File size: 563 Bytes
1c9374b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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"])
    }