Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request
|
| 2 |
+
from services.aggregator import collect_data
|
| 3 |
+
from services.sentiment import predict
|
| 4 |
+
from collections import Counter
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
@app.route('/', methods=['GET', 'POST'])
|
| 9 |
+
def index():
|
| 10 |
+
if request.method == 'POST':
|
| 11 |
+
keyword = request.form['keyword']
|
| 12 |
+
|
| 13 |
+
comments = collect_data(keyword)
|
| 14 |
+
sentiments = predict(comments[:100])
|
| 15 |
+
|
| 16 |
+
counts = Counter(sentiments)
|
| 17 |
+
|
| 18 |
+
data = list(zip(comments[:100], sentiments))
|
| 19 |
+
|
| 20 |
+
return render_template("result.html", data=data, counts=counts)
|
| 21 |
+
|
| 22 |
+
return render_template("index.html")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
app.run(host="0.0.0.0", port=7860)
|