-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (37 loc) · 1.53 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
47
48
49
50
from flask import Flask, request, jsonify, render_template
from models import XGBoostModel, RandomForestModel, PyCaretModel
app = Flask(__name__)
# Instantiate models
xgboost_model = XGBoostModel()
random_forest_model = RandomForestModel()
pycaret_model = PyCaretModel()
# Load pre-trained models
xgboost_model.load_model('xgboost_model.pkl')
random_forest_model.load_model('random_forest_model.pkl')
# List of algorithms for dropdown
algorithms = ['xgboost', 'random_forest', 'pycaret']
@app.route('/')
def index():
return render_template('index.html', algorithms=algorithms)
@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
# Get data from the HTML form
title = request.form['title']
author = request.form['author']
text = request.form['text']
algorithm = request.form['algorithm']
# Make predictions based on the chosen algorithm
if algorithm == 'xgboost':
prediction = xgboost_model.predict(title, author, text)
elif algorithm == 'random_forest':
prediction = random_forest_model.predict(title, author, text)
elif algorithm == 'pycaret':
prediction = pycaret_model.predict(title, author, text)
else:
return jsonify({'error': 'Invalid algorithm choice'})
return render_template('result.html', prediction=prediction)
# If GET method, render the form
return render_template('index.html', algorithms=algorithms)
if __name__ == '__main__':
app.run(debug=True)