-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (44 loc) · 1.58 KB
/
app.py
File metadata and controls
50 lines (44 loc) · 1.58 KB
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,render_template,request,Response,url_for
import joblib
from tensorflow.keras.preprocessing.sequence import pad_sequences
app = Flask(__name__)
@app.route("/")
@app.route("/home")
def home():
return render_template("home.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/submit",methods=["POST"])
def submit():
r = 2
result = ""
model = joblib.load("Models/Model.pkl")
tokens = joblib.load("Models/Tokens.pkl")
if request.method=="POST":
review = request.form.get("review")
if len(review) > 1:
f = review.split(" ")
new_st = [" ".join(f)]
new_ts = tokens.texts_to_sequences(new_st)
new_ts = pad_sequences(new_ts,maxlen=500,padding="post")
predict = model.predict(new_ts)
if predict >= 0.4:
r = 1
result = "A POSITIVE REVIEW."
print(predict)
print("positive")
elif predict >= 0.2 and predict <= 0.4:
r = 2
result = "A NEUTRAL REVIEW."
print(predict)
print("neutral")
else:
r = -1
result = "A NEGATIVE REVIEW."
print(predict)
print("negative")
return render_template("home.html",r=r,result=result)
else:
return render_template("home.html",result="Insufficient Data/try adding more sequences of your review.")
return render_template("home.html")