-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (31 loc) · 1.56 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
from flask import Flask, render_template, request, redirect, url_for
from joblib import load
from api_connection import get_related_tweets
import pandas as pd
pd.set_option('display.max_colwidth', 1000)
pipeline = load("text_classification.joblib")
def requestResults(name):
tweets = get_related_tweets(name)
tweets['prediction'] = pipeline.predict(tweets['Tweet_Text'])
data = str(tweets.prediction.value_counts()) + '\n\n\n'
text = '\n\nClassificaton\nClass 0 - Positive Tweet\nClass 1 - Negative Tweet\n\n'
d = {'Tweets': tweets.Tweet_Text, 'Prediction': tweets.prediction}
end_text = '\n\n===================================================================@ Twitter Speech Detection - Sentiment Analysis @===================================================================\n'
# return text+data+ 'Tweets\n'+str(tweets.Tweet_Text) +'\n\n'+ 'Prediction\n'+str(tweets.prediction)
return text, data , pd.DataFrame(data=d), end_text
# return text+data+'\n\n\n'+ pd.DataFrame(tweets.Tweet_Text, tweets.prediction)
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index2.html')
@app.route('/', methods=['POST', 'GET'])
def get_data():
if request.method == 'POST':
user = request.form['search']
return redirect(url_for('success', name=user))
@app.route('/success/<name>')
def success(name):
a,b,d, e = requestResults(name)
return "<xmp>" + str(e) + str(a) + str(b) + str(d) +"\n" +str(e) + " </xmp> "
if __name__ == '__main__' :
app.run(debug=True)