Spaces:
Runtime error
Runtime error
Johnniewhite
commited on
Commit
•
2116489
1
Parent(s):
62a1dd1
Upload 2 files
Browse files- index.py +24 -0
- requirements.txt +2 -0
index.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import transformers
|
2 |
+
from flask import Flask, request, jsonify
|
3 |
+
from transformers import RobertaTokenizerFast, TFRobertaForSequenceClassification, pipeline
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Load model and tokenizer once at app startup
|
8 |
+
tokenizer = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa")
|
9 |
+
model = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoROBERTa")
|
10 |
+
emotion = pipeline("sentiment-analysis", model="arpanghoshal/EmoROBERTa")
|
11 |
+
|
12 |
+
@app.route("/analyze_sentiment", methods=["POST"])
|
13 |
+
def analyze_sentiment():
|
14 |
+
data = request.get_json()
|
15 |
+
phrase = data.get("phrase")
|
16 |
+
|
17 |
+
if phrase:
|
18 |
+
emotion_labels = emotion(phrase)
|
19 |
+
return jsonify({"emotion_labels": emotion_labels})
|
20 |
+
else:
|
21 |
+
return jsonify({"error": "Missing phrase"}), 400
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
app.run(debug=True) # Set debug=False in production
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
transformers
|