Spaces:
Running on Zero
Running on Zero
Remove hf_oauth/LoginButton, pre-download models in build phase
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ Apple x Claude minimalist design with progressive feedback during the
|
|
| 5 |
multi-step pipeline.
|
| 6 |
"""
|
| 7 |
|
| 8 |
-
import io
|
| 9 |
import logging
|
| 10 |
import os
|
| 11 |
import sys
|
|
@@ -17,6 +16,31 @@ import pandas as pd
|
|
| 17 |
ROOT = Path(__file__).parent
|
| 18 |
sys.path.insert(0, str(ROOT))
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
import gradio as gr # noqa: E402
|
| 21 |
|
| 22 |
from src.orchestrator.pipeline import SQLAgentOrchestrator # noqa: E402
|
|
@@ -36,9 +60,6 @@ except ImportError:
|
|
| 36 |
|
| 37 |
spaces = _SpacesShim() # type: ignore
|
| 38 |
|
| 39 |
-
logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
|
| 40 |
-
logger = logging.getLogger(__name__)
|
| 41 |
-
|
| 42 |
|
| 43 |
# ============================================================ THEME / CSS
|
| 44 |
THEME_CSS = """
|
|
@@ -639,8 +660,6 @@ def build_app() -> gr.Blocks:
|
|
| 639 |
'</div>'
|
| 640 |
'</div>'
|
| 641 |
)
|
| 642 |
-
# Hugging Face login button — required for ZeroGPU quota
|
| 643 |
-
gr.LoginButton(value="Sign in with Hugging Face", size="sm")
|
| 644 |
|
| 645 |
# Upload
|
| 646 |
with gr.Row(elem_classes=["upload-row"]):
|
|
|
|
| 5 |
multi-step pipeline.
|
| 6 |
"""
|
| 7 |
|
|
|
|
| 8 |
import logging
|
| 9 |
import os
|
| 10 |
import sys
|
|
|
|
| 16 |
ROOT = Path(__file__).parent
|
| 17 |
sys.path.insert(0, str(ROOT))
|
| 18 |
|
| 19 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
|
| 22 |
+
# CRITICAL: pre-download model weights at module-load time (CPU phase, no GPU
|
| 23 |
+
# needed). When @spaces.GPU is later invoked, from_pretrained() finds the
|
| 24 |
+
# files already cached and just moves them to GPU — that loads in ~10s
|
| 25 |
+
# instead of 30-60s, which keeps us inside the ZeroGPU quota window.
|
| 26 |
+
MODEL_REPOS = [
|
| 27 |
+
"DanielRegaladoCardoso/sql-generator-qwen25-coder-7b-lora",
|
| 28 |
+
"DanielRegaladoCardoso/chart-reasoner-phi3-mini-lora",
|
| 29 |
+
"DanielRegaladoCardoso/svg-renderer-deepseek-coder-1.3b-lora",
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
from huggingface_hub import snapshot_download
|
| 34 |
+
for repo in MODEL_REPOS:
|
| 35 |
+
try:
|
| 36 |
+
logger.info(f"Pre-downloading {repo}...")
|
| 37 |
+
snapshot_download(repo)
|
| 38 |
+
logger.info(f" cached")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
logger.warning(f" pre-download failed (will retry on first use): {e}")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
logger.warning(f"snapshot_download unavailable: {e}")
|
| 43 |
+
|
| 44 |
import gradio as gr # noqa: E402
|
| 45 |
|
| 46 |
from src.orchestrator.pipeline import SQLAgentOrchestrator # noqa: E402
|
|
|
|
| 60 |
|
| 61 |
spaces = _SpacesShim() # type: ignore
|
| 62 |
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# ============================================================ THEME / CSS
|
| 65 |
THEME_CSS = """
|
|
|
|
| 660 |
'</div>'
|
| 661 |
'</div>'
|
| 662 |
)
|
|
|
|
|
|
|
| 663 |
|
| 664 |
# Upload
|
| 665 |
with gr.Row(elem_classes=["upload-row"]):
|