-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
26 lines (20 loc) · 784 Bytes
/
Copy pathapp.py
File metadata and controls
26 lines (20 loc) · 784 Bytes
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
from flask import Flask, render_template, request, jsonify
from utils import model_predict
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
@app.route('/predict', methods=['POST'])
def predict():
email = request.form.get('content')
prediction = model_predict(email)
return render_template("index.html", prediction=prediction, email=email)
# Create an API endpoint
@app.route('/api/predict', methods=['POST'])
def predict_api():
data = request.get_json(force=True) # Get data posted as a json
email = data['content']
prediction = model_predict(email)
return jsonify({'prediction': prediction, 'email': email}) # Return prediction
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080, debug=True)