-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (36 loc) · 1.14 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
from flask import Flask, render_template, request,redirect
from prediction_pipeline import preprocessing,vectorizer,get_prediction
from logger import logging
app = Flask(__name__)
logging.info("Flask server started")
data = dict()
reviews = []
positive = 0
negative = 0
@app.route("/")
def index():
data['reviews'] = reviews
data['positive'] = positive
data['negative'] = negative
logging.info("=========== Open Home Page ===========")
return render_template('index.html',data=data)
@app.route("/", methods=['POST'])
def my_post():
text = request.form['text']
logging.info(f'Text:{text}')
preprocessed_text = preprocessing(text)
logging.info(f'Preprocessed Text:{preprocessed_text}')
vectorized_text = vectorizer(preprocessed_text)
logging.info(f'Vectorized Text:{vectorized_text}')
prediction = get_prediction(vectorized_text)
logging.info(f'Prediction:{prediction}')
if prediction == 'negative':
global negative
negative += 1
else:
global positive
positive += 1
reviews.insert(0,text)
return redirect(request.url)
if __name__ == "__main__":
app.run()