| 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 | |
| def home(): | |
| return {"message": "Nepali Sentiment API Running"} | |
| def predict(data: TextInput): | |
| result = classifier(data.text) | |
| return { | |
| "label": result[0]["label"], | |
| "score": float(result[0]["score"]) | |
| } |