Spaces:
Runtime error

Adarsh-Saurabh commited on
Commit
cb8add0
·
1 Parent(s): 2b6a709

Register optional admin ZeroGPU hardware check

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. hf_app.py +18 -0
README.md CHANGED
@@ -33,7 +33,7 @@ The Gradio admin login uses username `admin` and the `ADMIN_PASSWORD` environmen
33
 
34
  ## Hugging Face deployment
35
 
36
- Create a **Gradio → Blank → ZeroGPU (Free)** Space. No GPU operations or storage bucket are needed by this demo. Upload `README.md`, `hf_app.py`, `requirements.txt`, `second_brain/*.py` and `data/fixtures/*.json`, preserving the folders. The README metadata selects the Gradio entry point. Do not upload `.env`, Git history, runtime files, or presentation assets.
37
 
38
  In **Settings → Variables and secrets**, add `ADMIN_PASSWORD` as a secret. Optional admin-only live extraction uses the `GEMINI_API_KEY` secret; the public workspace uses deterministic extraction with no model calls. Run `uv run --locked python -m pytest -q` before deploying. Regenerate `requirements.txt` after dependency changes with `uv export --locked --no-dev --no-hashes --no-emit-project -o requirements.txt`.
39
 
 
33
 
34
  ## Hugging Face deployment
35
 
36
+ Create a **Gradio → Blank → ZeroGPU (Free)** Space. The normal workflow uses the CPU. ZeroGPU requires a registered GPU function, so the admin console includes an optional hardware check; only clicking that check requests GPU time and uses quota. Hugging Face supplies `spaces` and PyTorch. No storage bucket is needed. Upload `README.md`, `hf_app.py`, `requirements.txt`, `second_brain/*.py` and `data/fixtures/*.json`, preserving the folders. The README metadata selects the Gradio entry point. Do not upload `.env`, Git history, runtime files, or presentation assets.
37
 
38
  In **Settings → Variables and secrets**, add `ADMIN_PASSWORD` as a secret. Optional admin-only live extraction uses the `GEMINI_API_KEY` secret; the public workspace uses deterministic extraction with no model calls. Run `uv run --locked python -m pytest -q` before deploying. Regenerate `requirements.txt` after dependency changes with `uv export --locked --no-dev --no-hashes --no-emit-project -o requirements.txt`.
39
 
hf_app.py CHANGED
@@ -49,6 +49,19 @@ CSS = """
49
  """
50
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  def close_workflow(wf):
53
  if wf is not None:
54
  wf.close()
@@ -232,6 +245,11 @@ def build_page(*, admin=False):
232
  button.click(partial(act, command=command), inputs=[state, scopes], **event_options)
233
  if admin:
234
  gr.Markdown("Scenario and Gemini settings take effect when you select **Start a fresh demo**. This console has its own session; public visitors cannot access its diagnostics or settings.")
 
 
 
 
 
235
  return page.queue(max_size=32)
236
 
237
 
 
49
  """
50
 
51
 
52
+ def check_host_gpu():
53
+ if not os.environ.get("SPACE_ID"):
54
+ return "Local preview · no ZeroGPU allocation requested."
55
+ import torch
56
+ return "ZeroGPU available: " + torch.cuda.get_device_name(0)
57
+
58
+
59
+ # ZeroGPU requires a registered GPU function even when the main workflow uses the CPU.
60
+ if os.environ.get("SPACE_ID"):
61
+ import spaces
62
+ check_host_gpu = spaces.GPU(duration=10)(check_host_gpu)
63
+
64
+
65
  def close_workflow(wf):
66
  if wf is not None:
67
  wf.close()
 
245
  button.click(partial(act, command=command), inputs=[state, scopes], **event_options)
246
  if admin:
247
  gr.Markdown("Scenario and Gemini settings take effect when you select **Start a fresh demo**. This console has its own session; public visitors cannot access its diagnostics or settings.")
248
+ with gr.Accordion("Hosting health check", open=False):
249
+ gr.Markdown("Optional: allocates ZeroGPU briefly to verify the hosting hardware. This uses your GPU quota; the normal workflow does not.")
250
+ host_check = gr.Button("Check ZeroGPU hardware")
251
+ host_result = gr.Textbox(label="Hosting result", interactive=False)
252
+ host_check.click(check_host_gpu, outputs=host_result, api_name=False)
253
  return page.queue(max_size=32)
254
 
255