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"]}