sameerdorjee07's picture
Create app.py
1c9374b verified
raw
history blame contribute delete
563 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
app = FastAPI()
# Load YOUR trained model
classifier = pipeline(
"sentiment-analysis",
model="sameerdorjee07/nepali-sentiment-xlmr",
device=-1
)
class TextInput(BaseModel):
text: str
@app.get("/")
def home():
return {"message": "Nepali Sentiment API Running"}
@app.post("/predict")
def predict(data: TextInput):
result = classifier(data.text)
return {
"label": result[0]["label"],
"score": float(result[0]["score"])
}