Spaces:
Runtime error
Runtime error
File size: 631 Bytes
fad8517 eead084 fad8517 eead084 fad8517 eead084 fad8517 eead084 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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]} |