Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def _clamp01(x: float) -> float:
|
|
| 38 |
|
| 39 |
# ===== 简易VAD(仅演示兜底,不等价真实模型)=====
|
| 40 |
_POS = ["good","great","excellent","love","like","happy","joy","awesome","amazing","wonderful","赞","好","喜欢","开心","愉快","优秀","棒","太好了","满意","值得"]
|
| 41 |
-
_NEG = ["bad","terrible","awful","hate","dislike","sad","angry","worse","worst","horrible","差","坏","讨厌","生气","愤怒","悲伤","糟糕","失望","
|
| 42 |
|
| 43 |
def simple_vad(text: str) -> Dict[str, float]:
|
| 44 |
t = text or ""
|
|
@@ -169,16 +169,18 @@ def diagnose():
|
|
| 169 |
if not HF_TOKEN:
|
| 170 |
return "未检测到 HF_TOKEN", ""
|
| 171 |
try:
|
| 172 |
-
res = _session.post(
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
| 176 |
return f"HTTP {res.status_code}", res.text[:500]
|
| 177 |
except Exception as e:
|
| 178 |
return f"异常:{type(e).__name__}: {e}", ""
|
| 179 |
|
| 180 |
# ===== Gradio 界面 =====
|
| 181 |
-
with gr.Blocks(title=APP_TITLE, css=".wrap {max-width: 1200px; margin: 0 auto;}")
|
| 182 |
gr.Markdown(f"# {APP_TITLE}\n{APP_DESC}")
|
| 183 |
with gr.Row(elem_classes=["wrap"]):
|
| 184 |
with gr.Column(scale=5):
|
|
@@ -198,8 +200,13 @@ with gr.Blocks(title=APP_TITLE, css=".wrap {max-width: 1200px; margin: 0 auto;}"
|
|
| 198 |
chart = gr.HTML(label="VAD 对比柱状图")
|
| 199 |
report = gr.Textbox(label="摘要结果", lines=4)
|
| 200 |
raw_json = gr.Code(label="JSON 输出", language="json")
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
# 兼容运行器:导出 demo 与 app
|
| 205 |
app = demo
|
|
|
|
| 38 |
|
| 39 |
# ===== 简易VAD(仅演示兜底,不等价真实模型)=====
|
| 40 |
_POS = ["good","great","excellent","love","like","happy","joy","awesome","amazing","wonderful","赞","好","喜欢","开心","愉快","优秀","棒","太好了","满意","值得"]
|
| 41 |
+
_NEG = ["bad","terrible","awful","hate","dislike","sad","angry","worse","worst","horrible","差","坏","讨厌","生气","愤怒","悲伤","糟糕","失望","不满"]
|
| 42 |
|
| 43 |
def simple_vad(text: str) -> Dict[str, float]:
|
| 44 |
t = text or ""
|
|
|
|
| 169 |
if not HF_TOKEN:
|
| 170 |
return "未检测到 HF_TOKEN", ""
|
| 171 |
try:
|
| 172 |
+
res = _session.post(
|
| 173 |
+
HF_API_URL,
|
| 174 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}", "Content-Type":"application/json"},
|
| 175 |
+
json={"model": MODEL_ID, "inputs": "ok"},
|
| 176 |
+
timeout=(8, 30)
|
| 177 |
+
)
|
| 178 |
return f"HTTP {res.status_code}", res.text[:500]
|
| 179 |
except Exception as e:
|
| 180 |
return f"异常:{type(e).__name__}: {e}", ""
|
| 181 |
|
| 182 |
# ===== Gradio 界面 =====
|
| 183 |
+
with gr.Blocks(title=APP_TITLE, css=".wrap {max-width: 1200px; margin: 0 auto;}") as demo:
|
| 184 |
gr.Markdown(f"# {APP_TITLE}\n{APP_DESC}")
|
| 185 |
with gr.Row(elem_classes=["wrap"]):
|
| 186 |
with gr.Column(scale=5):
|
|
|
|
| 200 |
chart = gr.HTML(label="VAD 对比柱状图")
|
| 201 |
report = gr.Textbox(label="摘要结果", lines=4)
|
| 202 |
raw_json = gr.Code(label="JSON 输出", language="json")
|
| 203 |
+
|
| 204 |
+
# 事件绑定,设置并发限制
|
| 205 |
+
run_btn.click(run, [student, reference, backend], [chart, report, raw_json], concurrency_limit=4)
|
| 206 |
+
chk_btn.click(diagnose, [], [api_status, api_body], concurrency_limit=2)
|
| 207 |
+
|
| 208 |
+
# 开启队列(不传已弃用参数)
|
| 209 |
+
demo.queue()
|
| 210 |
|
| 211 |
# 兼容运行器:导出 demo 与 app
|
| 212 |
app = demo
|