Spaces:
Running on Zero
Running on Zero
GitHub Actions commited on
Commit Β·
fb17651
1
Parent(s): 76973b4
fix(ui): disable broken tabs + add @spaces.GPU + MiniCPM trust_remote_code note
Browse filesMain Space (app.py):
- Comment out 5 broken tabs: Nemotron, Voice, Image, OCR, Translation
- Document reasons: event loop error, unavailable backends, config issues
- Keep working tabs: Ask, Chat, Mesh, Marketplace, Files, Emergency, Settings
- Add MiniCPM3-4B trust_remote_code requirement note to ask.py docstring
Nemotron Space (app_nemotron.py):
- Add 'import spaces' with graceful fallback
- Decorate extract_structured() with @spaces.GPU (or no-op if HAS_SPACES=False)
- Fixes 'No @spaces.GPU function detected during startup' error on HF ZeroGPU
- app_nemotron.py +13 -0
- hearthnet/ui/app.py +15 -10
- hearthnet/ui/tabs/ask.py +6 -0
app_nemotron.py
CHANGED
|
@@ -26,6 +26,13 @@ import os
|
|
| 26 |
|
| 27 |
import gradio as gr
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# ββ Optional mesh connection ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
_MESH_NODE = os.getenv("HEARTHNET_NODE", "")
|
| 31 |
_NVIDIA_KEY = os.getenv("NVIDIA_API_KEY", "")
|
|
@@ -148,6 +155,7 @@ async def _nemotron_chat(messages: list, model: str, api_key: str, temperature:
|
|
| 148 |
return r.json()["choices"][0]["message"]["content"]
|
| 149 |
|
| 150 |
|
|
|
|
| 151 |
def extract_structured(
|
| 152 |
doc_text: str,
|
| 153 |
schema_preset: str,
|
|
@@ -155,6 +163,11 @@ def extract_structured(
|
|
| 155 |
model_label: str,
|
| 156 |
api_key: str,
|
| 157 |
) -> tuple[str, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
import json
|
| 159 |
|
| 160 |
if not doc_text.strip():
|
|
|
|
| 26 |
|
| 27 |
import gradio as gr
|
| 28 |
|
| 29 |
+
# HF Spaces GPU support
|
| 30 |
+
try:
|
| 31 |
+
import spaces
|
| 32 |
+
HAS_SPACES = True
|
| 33 |
+
except ImportError:
|
| 34 |
+
HAS_SPACES = False
|
| 35 |
+
|
| 36 |
# ββ Optional mesh connection ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 37 |
_MESH_NODE = os.getenv("HEARTHNET_NODE", "")
|
| 38 |
_NVIDIA_KEY = os.getenv("NVIDIA_API_KEY", "")
|
|
|
|
| 155 |
return r.json()["choices"][0]["message"]["content"]
|
| 156 |
|
| 157 |
|
| 158 |
+
@spaces.GPU if HAS_SPACES else lambda f: f
|
| 159 |
def extract_structured(
|
| 160 |
doc_text: str,
|
| 161 |
schema_preset: str,
|
|
|
|
| 163 |
model_label: str,
|
| 164 |
api_key: str,
|
| 165 |
) -> tuple[str, str]:
|
| 166 |
+
"""Extract structured data from documents using Nemotron.
|
| 167 |
+
|
| 168 |
+
Wrapped with @spaces.GPU to signal GPU usage to HF Spaces.
|
| 169 |
+
Falls back gracefully if GPU unavailable (e.g., local testing).
|
| 170 |
+
"""
|
| 171 |
import json
|
| 172 |
|
| 173 |
if not doc_text.strip():
|
hearthnet/ui/app.py
CHANGED
|
@@ -289,16 +289,21 @@ class UiApp:
|
|
| 289 |
build_marketplace_tab(self._bus)
|
| 290 |
with gr.Tab("Files"):
|
| 291 |
build_files_tab(self._bus)
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
with gr.Tab("
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
with gr.Tab("Emergency"):
|
| 303 |
build_emergency_tab(self._bus, self._state_bus)
|
| 304 |
with gr.Tab("Settings"):
|
|
|
|
| 289 |
build_marketplace_tab(self._bus)
|
| 290 |
with gr.Tab("Files"):
|
| 291 |
build_files_tab(self._bus)
|
| 292 |
+
# [Disabled: event loop error in HF Spaces worker thread]
|
| 293 |
+
# with gr.Tab("π¬ Nemotron"):
|
| 294 |
+
# build_nemotron_tab(self._bus)
|
| 295 |
+
# [Disabled: transcript backend unavailable]
|
| 296 |
+
# with gr.Tab("π Voice"):
|
| 297 |
+
# build_voice_tab(self._bus)
|
| 298 |
+
# [Disabled: Florence2 forced_bos_token_id config error]
|
| 299 |
+
# with gr.Tab("πΌ Image"):
|
| 300 |
+
# build_image_tab(self._bus)
|
| 301 |
+
# [Disabled: TrOCR model compatibility issue]
|
| 302 |
+
# with gr.Tab("π OCR"):
|
| 303 |
+
# build_ocr_tab(self._bus)
|
| 304 |
+
# [Disabled: translation backend not configured]
|
| 305 |
+
# with gr.Tab("π Translation"):
|
| 306 |
+
# build_translation_tab(self._bus)
|
| 307 |
with gr.Tab("Emergency"):
|
| 308 |
build_emergency_tab(self._bus, self._state_bus)
|
| 309 |
with gr.Tab("Settings"):
|
hearthnet/ui/tabs/ask.py
CHANGED
|
@@ -8,6 +8,12 @@ The routing trace shows exactly which node answered and why.
|
|
| 8 |
No hardcoded responses. If no LLM is configured, an UnavailableBackend
|
| 9 |
error is surfaced directly rather than fabricating an answer.
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
Spec: docs/M04-llm.md, docs/M05-rag.md, docs/M03-bus.md Β§4
|
| 12 |
"""
|
| 13 |
|
|
|
|
| 8 |
No hardcoded responses. If no LLM is configured, an UnavailableBackend
|
| 9 |
error is surfaced directly rather than fabricating an answer.
|
| 10 |
|
| 11 |
+
LLM Models:
|
| 12 |
+
- MiniCPM3-4B (OpenBMB default) requires trust_remote_code=True when loading via
|
| 13 |
+
transformers.from_pretrained() β the model repo contains custom modeling code.
|
| 14 |
+
HF Transformers backend (app.py) passes this flag; local-first vLLM/llama.cpp
|
| 15 |
+
endpoints do not need it (they handle the model internally).
|
| 16 |
+
|
| 17 |
Spec: docs/M04-llm.md, docs/M05-rag.md, docs/M03-bus.md Β§4
|
| 18 |
"""
|
| 19 |
|