-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
43 lines (30 loc) · 918 Bytes
/
application.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
# A very simple Flask Hello World app for you to get started with...
from flask import Flask, jsonify, request
import bz2
import pickle
import pandas as pd
with bz2.BZ2File('sentiment_cv.pbz2', 'r') as f:
cv = pickle.load(f)
with bz2.BZ2File('sentiment_model.pbz2', 'r') as f:
model = pickle.load(f)
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1>Hello Deepesh Sentiment Analysis</h1>"
@app.route("/analysis/", methods=['POST'])
def analysis():
x = request.get_json()
com = {
'comments': x['comment']
}
tt = []
for i in range(len(com['comments'])):
tt.append(str(com['comments'][i]))
tt = pd.Series(tt)
xcv = cv.transform(pd.Series(tt))
pred = model.predict(xcv)
k = []
for i in range(len(tt)):
k.append({'comment': str(tt[i]), 'sentiment': str(pred[i])})
jj = {'text_analysis': k}
return jsonify(jj)