-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (34 loc) · 1.04 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
from flask import Flask, render_template, request
import fasttext
app = Flask(__name__)
model = "samurai"
def load_da_model():
global model
model = fasttext.load_model("trained.ftz")
@app.route('/')
def home():
return render_template("index.html")
@app.route("/home.html")
def meth():
return render_template("home.html")
@app.route('/pred.html', methods=['GET', 'POST'])
def predict_da_text():
if request.method == 'POST':
stuff = request.form
text = ' '.join(stuff['inp'].split())
print(text, end=' ')
predicted = model.predict(text.lower())
res = "inappropriate" if predicted[0][0][-1]=='1' else "okay"
print(f"This is {res}.")
if res == "inappropriate":
verdict = "Can't be saying that."
col = "orange"
img = "static/images/no.png"
else:
verdict = "At least you aren't a drag to hang with."
col = "#0f0"
img = "static/images/ok.jpeg"
return render_template('pred.html', say=text, pred=res, verdict=verdict, box=col, img=img)
if __name__ == '__main__':
load_da_model()
app.run(host='0.0.0.0', debug=True, port=5000)