adithimshrouthy commited on
Commit
f3e93f5
·
verified ·
1 Parent(s): a845da1

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
+ MODEL_ID = "MoritzLaurer/deberta-v3-large-zeroshot-v2.0-c"
6
+ app = FastAPI()
7
+ zsc = pipeline("zero-shot-classification", model=MODEL_ID)
8
+
9
+ class Req(BaseModel):
10
+ text: str
11
+ labels: list[str]
12
+ multi_label: bool = True
13
+ template: str = "This text is about {}."
14
+
15
+ @app.get("/")
16
+ def health():
17
+ return {"status": "ok"}
18
+
19
+ @app.post("/predict")
20
+ def predict(r: Req):
21
+ out = zsc(
22
+ r.text,
23
+ candidate_labels=r.labels,
24
+ multi_label=r.multi_label,
25
+ hypothesis_template=r.template,
26
+ )
27
+ return {"labels": out["labels"], "scores": out["scores"]}