-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
38 lines (28 loc) · 1.39 KB
/
script.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
# Link between model.py and index.html to take user inputs and display results
import flask
from flask import request
from model import predict_sentiment
# Initialize the app
app = flask.Flask(__name__)
@app.route('/')
def index():
# Displays the shown string above the user entered text
header_review = "Review:"
# Displays the show string above the model determined sentiment
header_sentiment = "Sentiment:"
print(request.args)
# Contains a dictionary containing the parsed contents of the query string
if(request.args):
# Passes contents of query string to the prediction function contained in model.py
x_input, prediction = predict_sentiment(request.args['text_in'])
print(prediction[0]['prob'])
# Indexes the returned dictionary for the sentiment probability
if((prediction[0]['prob']) > 0.5):
prediction = "Positive"
return flask.render_template('index.html', text_in=x_input, prediction=prediction, header_review=header_review, header_sentiment=header_sentiment)
else:
prediction = "Negative"
return flask.render_template('index.html', text_in=x_input, prediction=prediction, header_review=header_review, header_sentiment=header_sentiment)
# If the parsed query string does not contain anything then return index page
else:
return flask.render_template('index.html')