space / main.py
nagaananth's picture
Level 2: Integrated real Sentiment Analysis model
eead084
raw
history blame contribute delete
631 Bytes
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]}