-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappp.py
More file actions
54 lines (38 loc) · 1.27 KB
/
appp.py
File metadata and controls
54 lines (38 loc) · 1.27 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
51
52
53
54
from flask import Flask, render_template, request, redirect
from helper 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 mypost():
text = request.form['comments']
logging.info(f'Text : {text}')
preprocessed_txt = preprocessing(text)
logging.info(f'Preprocessed Text : {preprocessed_txt}')
vectorized_txt = vectorizer(preprocessed_txt)
logging.info(f'Vectorized Text : {vectorized_txt}')
prediction = get_prediction(vectorized_txt)
logging.info(f'Prediction : {prediction}')
if prediction == 'Not Spam':
message = 'This is not a spam'
global negative
negative += 1
else:
message = 'This is a spam'
global positive
positive += 1
data['last_text'] = text # Save the last entered text
return render_template('index.html', data=data, message=message)
if __name__ == "__main__":
app.run()