Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ summ = pipeline("summarization", model=SUM_MODEL)
|
|
| 20 |
class ZSCReq(BaseModel):
|
| 21 |
text: str
|
| 22 |
labels: list[str] = []
|
| 23 |
-
multi_label: bool =
|
| 24 |
template: str = "This feedback is primarily about {}."
|
| 25 |
|
| 26 |
class SAReq(BaseModel):
|
|
@@ -41,7 +41,7 @@ def warmup():
|
|
| 41 |
# === ROUTES ===
|
| 42 |
@app.get("/")
|
| 43 |
def health():
|
| 44 |
-
return {"status": "ok"}
|
| 45 |
|
| 46 |
# in your HF Space app.py
|
| 47 |
@app.post("/predict")
|
|
@@ -56,13 +56,15 @@ def predict(req: ZSCReq):
|
|
| 56 |
)
|
| 57 |
|
| 58 |
pairs = sorted(zip(out["labels"], out["scores"]), key=lambda p: p[1], reverse=True)
|
|
|
|
|
|
|
| 59 |
lbls, scs = zip(*pairs)
|
| 60 |
return {"labels": list(lbls), "scores": list(map(float, scs))}
|
| 61 |
|
| 62 |
@app.post("/sa")
|
| 63 |
def sentiment(req: SAReq):
|
| 64 |
result = sa(req.text)[0]
|
| 65 |
-
return {"label":
|
| 66 |
|
| 67 |
@app.post("/sum")
|
| 68 |
def summarize(req: SumReq):
|
|
|
|
| 20 |
class ZSCReq(BaseModel):
|
| 21 |
text: str
|
| 22 |
labels: list[str] = []
|
| 23 |
+
multi_label: bool = False
|
| 24 |
template: str = "This feedback is primarily about {}."
|
| 25 |
|
| 26 |
class SAReq(BaseModel):
|
|
|
|
| 41 |
# === ROUTES ===
|
| 42 |
@app.get("/")
|
| 43 |
def health():
|
| 44 |
+
return {"status": "ok", "model": ZSC_MODEL, "labels": DEFAULT_LABELS}
|
| 45 |
|
| 46 |
# in your HF Space app.py
|
| 47 |
@app.post("/predict")
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
pairs = sorted(zip(out["labels"], out["scores"]), key=lambda p: p[1], reverse=True)
|
| 59 |
+
if not pairs:
|
| 60 |
+
return {"labels": [], "scores": []}
|
| 61 |
lbls, scs = zip(*pairs)
|
| 62 |
return {"labels": list(lbls), "scores": list(map(float, scs))}
|
| 63 |
|
| 64 |
@app.post("/sa")
|
| 65 |
def sentiment(req: SAReq):
|
| 66 |
result = sa(req.text)[0]
|
| 67 |
+
return {"label": result["label"], "score": float(result["score"])}
|
| 68 |
|
| 69 |
@app.post("/sum")
|
| 70 |
def summarize(req: SumReq):
|