from fastapi import FastAPI from transformers import pipeline app = FastAPI() # Load the model once when the server starts # This is "Sentiment Analysis" by default classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") @app.get("/") def home(): return {"status": "Level 2 Live", "model": "DistilBERT Sentiment"} @app.post("/predict") def predict(data: dict): text = data.get("text", "") if not text: return {"error": "No text provided"} # Run the model result = classifier(text) return {"input": text, "result": result[0]}