CadenShokat's picture
Create app.py
73a696f verified
raw
history blame contribute delete
326 Bytes
from fastapi import FastAPI
from transformers import pipeline
app = FastAPI()
classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
@app.get("/sentiment")
def analyze(text: str):
result = classifier(text)[0]
return {"label": result["label"], "score": result["score"]}