WormWorm / your_script.py
Dmtlant's picture
Rename app.py to your_script.py
53df126 verified
raw
history blame contribute delete
453 Bytes
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)
@app.get("/predict/")
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)