-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (40 loc) · 2.22 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# main.py
from feature_extraction import build_feature_dataframe, detect_word_et, detect_word_others_researchers, \
detect_word_this, detect_word_because, detect_word_but, detect_word_however, detect_word_alhough, \
detect_capital_letters_vs_periods, detect_numbers_per_paragraph, detect_long_sentences_per_paragraph, \
detect_short_sentences_per_paragraph, mean_diff_in_sentence_length_per_paragraph, std_dev_sentence_length_per_paragraph, \
detect_apostrophe_per_paragraph, detect_question_mark_per_paragraph, detect_semicolon_colon_per_paragraph, \
detect_dash_per_paragraph, detect_parentheses_per_paragraph, count_words_per_paragraph, count_sentences_per_paragraph
from model_training import train_xgboost_model, train_adaboost_model, evaluate_model, predict_submission, plot_roc_auc
from flask import Flask, render_template, request
import pandas as pd
import xgboost as xgb
from sklearn.ensemble import AdaBoostClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score, roc_curve
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import pickle
app = Flask(__name__)
import pickle
with open('xgboost_model.pkl', 'rb') as file:
xgboost_model = pickle.load(file)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
noteforscore=" NOTE: AI->Score Closer to 1 & Human-> Score Closer to 0"
if request.method == 'POST':
user_input = request.form['user_input']
user_input_features = build_feature_dataframe([user_input], [0])
xgboost_prediction = predict_submission(xgboost_model, user_input_features.drop('label', axis=1))
# adaboost_prediction = predict_submission(adaboost_model, user_input_features.drop('label', axis=1))
if(xgboost_prediction>0.5):
pred="AI Generated with a score of :" + str(xgboost_prediction)
return render_template('result.html', prediction=pred,note=noteforscore)
else:
pred="Human Generated with a score of" + str(xgboost_prediction)
return render_template('result.html', prediction=pred,note=noteforscore)
if __name__ == "__main__":
app.run(debug=True)