kouki321 commited on
Commit
74df37d
·
verified ·
1 Parent(s): f0f3a14

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ # Load model remotely from Hugging Face Hub (replace with your model id)
8
+ model_id = "distilbert-base-uncased-finetuned-sst-2-english"
9
+ classifier = pipeline("sentiment-analysis", model=model_id)
10
+
11
+ class TextIn(BaseModel):
12
+ text: str
13
+
14
+ @app.post("/predict")
15
+ def predict(data: TextIn):
16
+ result = classifier(data.text)
17
+ return {"label": result[0]['label'], "score": result[0]['score']}