sameerdorjee07 commited on
Commit
1c9374b
·
verified ·
1 Parent(s): aa7d9a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ # Load YOUR trained model
8
+ classifier = pipeline(
9
+ "sentiment-analysis",
10
+ model="sameerdorjee07/nepali-sentiment-xlmr",
11
+ device=-1
12
+ )
13
+
14
+ class TextInput(BaseModel):
15
+ text: str
16
+
17
+ @app.get("/")
18
+ def home():
19
+ return {"message": "Nepali Sentiment API Running"}
20
+
21
+ @app.post("/predict")
22
+ def predict(data: TextInput):
23
+ result = classifier(data.text)
24
+ return {
25
+ "label": result[0]["label"],
26
+ "score": float(result[0]["score"])
27
+ }