Spaces:
Running on Zero
Running on Zero
feat: ZeroGPU demo (spaces.GPU + CUDA torch)
Browse files
app.py
CHANGED
|
@@ -86,9 +86,19 @@ def _forward(premise, hypothesis, keys):
|
|
| 86 |
|
| 87 |
|
| 88 |
def grade(premise, hypothesis, selection):
|
|
|
|
|
|
|
|
|
|
| 89 |
if not premise.strip() or not hypothesis.strip():
|
| 90 |
-
|
|
|
|
| 91 |
keys = SELECTION.get(selection, ["en", "multi"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
for spec in MODELS: # download/load on CPU first, so the GPU window is inference-only
|
| 93 |
if spec["key"] in keys:
|
| 94 |
_ensure(spec)
|
|
@@ -105,7 +115,7 @@ def grade(premise, hypothesis, selection):
|
|
| 105 |
verdict = "✅ grounded" if p >= 0.5 else "❌ not grounded"
|
| 106 |
bar = "█" * round(p * 10) + "░" * (10 - round(p * 10))
|
| 107 |
lines.append(f"| **{spec['name']}** | {spec['tag']} | `{bar}` **{p:.3f}** | {verdict} |")
|
| 108 |
-
|
| 109 |
|
| 110 |
|
| 111 |
from examples import EXAMPLES # noqa: E402 (real, labeled rows; single source of truth, verified)
|
|
@@ -129,8 +139,9 @@ with gr.Blocks(title="Grounding demo", theme=gr.themes.Soft()) as demo:
|
|
| 129 |
expected = gr.Textbox(label="Expected answer (ground truth for the selected example)",
|
| 130 |
interactive=False)
|
| 131 |
btn = gr.Button("Check grounding", variant="primary")
|
|
|
|
| 132 |
out = gr.Markdown()
|
| 133 |
-
btn.click(grade, [premise, hypothesis, model_sel], out)
|
| 134 |
gr.Examples(EXAMPLES, [premise, hypothesis, expected]) # fills the boxes incl. expected answer
|
| 135 |
gr.Markdown(
|
| 136 |
'## About the author\n'
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
def grade(premise, hypothesis, selection):
|
| 89 |
+
# Generator: emit an immediate status line so the click has visible feedback while the (potentially
|
| 90 |
+
# slow) cold start runs — first request downloads the weights to CPU AND cold-starts a shared ZeroGPU
|
| 91 |
+
# allocation, which together can take ~30-60s. Warm requests only wait on the GPU handoff.
|
| 92 |
if not premise.strip() or not hypothesis.strip():
|
| 93 |
+
yield "Enter a document premise and a claim to check."
|
| 94 |
+
return
|
| 95 |
keys = SELECTION.get(selection, ["en", "multi"])
|
| 96 |
+
cold = [s for s in MODELS if s["key"] in keys and s["key"] not in _loaded]
|
| 97 |
+
if cold:
|
| 98 |
+
yield ("⏳ **Waking up…** the first check downloads the model and cold-starts a shared GPU — "
|
| 99 |
+
"this can take **~30–60s**. Later checks are near-instant.")
|
| 100 |
+
else:
|
| 101 |
+
yield "⏳ Scoring on the GPU…"
|
| 102 |
for spec in MODELS: # download/load on CPU first, so the GPU window is inference-only
|
| 103 |
if spec["key"] in keys:
|
| 104 |
_ensure(spec)
|
|
|
|
| 115 |
verdict = "✅ grounded" if p >= 0.5 else "❌ not grounded"
|
| 116 |
bar = "█" * round(p * 10) + "░" * (10 - round(p * 10))
|
| 117 |
lines.append(f"| **{spec['name']}** | {spec['tag']} | `{bar}` **{p:.3f}** | {verdict} |")
|
| 118 |
+
yield "\n".join(lines)
|
| 119 |
|
| 120 |
|
| 121 |
from examples import EXAMPLES # noqa: E402 (real, labeled rows; single source of truth, verified)
|
|
|
|
| 139 |
expected = gr.Textbox(label="Expected answer (ground truth for the selected example)",
|
| 140 |
interactive=False)
|
| 141 |
btn = gr.Button("Check grounding", variant="primary")
|
| 142 |
+
gr.Markdown("<sub>⏱️ The first check cold-starts a shared GPU (~30–60s); later checks are fast.</sub>")
|
| 143 |
out = gr.Markdown()
|
| 144 |
+
btn.click(grade, [premise, hypothesis, model_sel], out, show_progress="full")
|
| 145 |
gr.Examples(EXAMPLES, [premise, hypothesis, expected]) # fills the boxes incl. expected answer
|
| 146 |
gr.Markdown(
|
| 147 |
'## About the author\n'
|