Fetch dataset at runtime instead of build time (F4 refactor)
Browse files- Dockerfile +4 -11
- app.py +22 -0
- requirements.txt +1 -0
Dockerfile
CHANGED
|
@@ -5,23 +5,16 @@ WORKDIR /app
|
|
| 5 |
# Copy space app files
|
| 6 |
COPY . /app
|
| 7 |
|
| 8 |
-
# Install dependencies
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
-
# Set environment for dataset download
|
| 12 |
-
ENV HF_HUB_DOWNLOAD_TIMEOUT=120
|
| 13 |
-
|
| 14 |
-
# Fetch benchmark tasks from Hugging Face dataset (public, no token needed)
|
| 15 |
-
RUN pip install --no-cache-dir huggingface-hub && \
|
| 16 |
-
python -c "from huggingface_hub import snapshot_download; snapshot_download('hummbl-hf/governance-bench', repo_type='dataset', local_dir='/bench')"
|
| 17 |
-
|
| 18 |
-
# Verify download
|
| 19 |
-
RUN ls /bench/tasks/ | head -5
|
| 20 |
-
|
| 21 |
# Set environment
|
|
|
|
| 22 |
ENV BENCH_ROOT=/bench
|
| 23 |
ENV PYTHONPATH=/bench/scripts:/app
|
| 24 |
|
|
|
|
|
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 5 |
# Copy space app files
|
| 6 |
COPY . /app
|
| 7 |
|
| 8 |
+
# Install dependencies (huggingface-hub is in requirements.txt for runtime dataset fetch)
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Set environment
|
| 12 |
+
ENV HF_HUB_DOWNLOAD_TIMEOUT=120
|
| 13 |
ENV BENCH_ROOT=/bench
|
| 14 |
ENV PYTHONPATH=/bench/scripts:/app
|
| 15 |
|
| 16 |
+
# Dataset is fetched at runtime (app startup), not build time,
|
| 17 |
+
# so dataset updates surface without a space rebuild (F4 refactor).
|
| 18 |
EXPOSE 7860
|
| 19 |
|
| 20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -34,6 +34,23 @@ SCRIPTS_DIR = BENCH_ROOT / "scripts"
|
|
| 34 |
TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
|
| 35 |
STATIC_DIR = Path(__file__).resolve().parent / "static"
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
app = FastAPI(
|
| 38 |
title="Governance-Bench Agent Reasoning Audit",
|
| 39 |
description="Interactive benchmark for AI agent governance primitives",
|
|
@@ -44,6 +61,11 @@ app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
|
| 44 |
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
| 45 |
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# ---------------------------------------------------------------------------
|
| 48 |
# Data models
|
| 49 |
# ---------------------------------------------------------------------------
|
|
|
|
| 34 |
TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
|
| 35 |
STATIC_DIR = Path(__file__).resolve().parent / "static"
|
| 36 |
|
| 37 |
+
|
| 38 |
+
def ensure_bench_downloaded() -> None:
|
| 39 |
+
"""Download the benchmark dataset at runtime if BENCH_ROOT is empty/missing.
|
| 40 |
+
|
| 41 |
+
Fetches from hummbl-hf/governance-bench so dataset updates surface without
|
| 42 |
+
a space rebuild (F4 refactor — was previously baked in at Docker build time).
|
| 43 |
+
"""
|
| 44 |
+
if TASKS_ROOT.exists() and any(TASKS_ROOT.iterdir()):
|
| 45 |
+
return # already populated
|
| 46 |
+
from huggingface_hub import snapshot_download
|
| 47 |
+
snapshot_download(
|
| 48 |
+
"hummbl-hf/governance-bench",
|
| 49 |
+
repo_type="dataset",
|
| 50 |
+
local_dir=str(BENCH_ROOT),
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
app = FastAPI(
|
| 55 |
title="Governance-Bench Agent Reasoning Audit",
|
| 56 |
description="Interactive benchmark for AI agent governance primitives",
|
|
|
|
| 61 |
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
| 62 |
|
| 63 |
|
| 64 |
+
@app.on_event("startup")
|
| 65 |
+
async def _startup_download_bench() -> None:
|
| 66 |
+
ensure_bench_downloaded()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
# ---------------------------------------------------------------------------
|
| 70 |
# Data models
|
| 71 |
# ---------------------------------------------------------------------------
|
requirements.txt
CHANGED
|
@@ -2,3 +2,4 @@ fastapi
|
|
| 2 |
uvicorn[standard]
|
| 3 |
jinja2
|
| 4 |
hummbl-governance>=1.1.0
|
|
|
|
|
|
| 2 |
uvicorn[standard]
|
| 3 |
jinja2
|
| 4 |
hummbl-governance>=1.1.0
|
| 5 |
+
huggingface-hub
|