Spaces:
Runtime error
Runtime error
Commit
·
83ca6b0
1
Parent(s):
cdf5c6e
flask app
Browse files
app.py
CHANGED
@@ -1,8 +1,31 @@
|
|
1 |
-
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
3 |
pipe = pipeline('sentiment-analysis')
|
4 |
-
text = st.text_area('enter some text!')
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# from transformers import pipeline
|
3 |
+
# pipe = pipeline('sentiment-analysis')
|
4 |
+
# text = st.text_area('enter some text!')
|
5 |
+
|
6 |
+
# if text:
|
7 |
+
# out = pipe(text)
|
8 |
+
# st.write(out)
|
9 |
+
|
10 |
+
# My Flask App
|
11 |
+
import json
|
12 |
+
from flask import Flask, request, jsonify
|
13 |
from transformers import pipeline
|
14 |
+
|
15 |
+
app = Flask(__name__)
|
16 |
+
|
17 |
pipe = pipeline('sentiment-analysis')
|
|
|
18 |
|
19 |
+
@app.route('/sentiment', methods=['POST'])
|
20 |
+
def sentiment_analysis():
|
21 |
+
data = request.get_json()
|
22 |
+
text = data['text']
|
23 |
+
|
24 |
+
if text:
|
25 |
+
out = pipe(text)
|
26 |
+
return jsonify(out)
|
27 |
+
else:
|
28 |
+
return jsonify({"error": "No text provided."}), 400
|
29 |
+
|
30 |
+
if __name__ == '__main__':
|
31 |
+
app.run()
|