from fastapi import FastAPI | |
from transformers import pipeline | |
app = FastAPI() | |
# Load the model | |
model_name = "distilbert-base-uncased-finetuned-sst-2-english" | |
nlp = pipeline("sentiment-analysis", model=model_name) | |
def predict(text: str): | |
result = nlp(text) | |
return {"sentiment": result[0]['label'], "score": result[0]['score']} | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=8000) |