Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
|
| 6 |
+
|
| 7 |
+
@app.get("/sentiment")
|
| 8 |
+
def analyze(text: str):
|
| 9 |
+
result = classifier(text)[0]
|
| 10 |
+
return {"label": result["label"], "score": result["score"]}
|