"""Unified DriftCall Space — every artefact at a slash-path, served locally. URL surface: / static project site (Vite-built React + Pretext) /assets/* site bundle /healthz OpenEnv health probe /reset POST OpenEnv canonical reset /step POST OpenEnv step /state GET OpenEnv read-only state /close POST OpenEnv close /openenv.yaml OpenEnv v1.0 manifest /docs FastAPI / Swagger UI for the env routes /demo voice demo Gradio app, MOUNTED LOCALLY (no iframe) /env landing page documenting env routes (curl recipes) /lora landing page with LoRA metadata + download link /source landing page with the project file tree + repo link Nothing under this Space depends on a 302 redirect to another origin — the demo Gradio Blocks are mounted via gr.mount_gradio_app, the LoRA and source pages are rendered server-side from local data. """ from __future__ import annotations import os from pathlib import Path from typing import Any from fastapi import FastAPI from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse from fastapi.staticfiles import StaticFiles # `app.py` refuses to start without DRIFTCALL_ENV_TOKEN. For the hackathon # demo Space we publish a known public token so anyone can hit the OpenEnv # API end-to-end. To restrict access, override via Space Settings → Secrets. os.environ.setdefault("DRIFTCALL_ENV_TOKEN", "driftcall-demo") # `app.py` eager-loads Kokoro TTS + faster-whisper ASR at lifespan startup. # On this unified Space those engines aren't needed for the OpenEnv API # surface — they only matter inside the /demo Gradio app, which constructs # its own engines lazily on first audio I/O. We monkey-patch the eager-load # step BEFORE importing app.py so the lifespan handler skips it. This also # dodges the misaki/kokoro version-drift error (`module 'misaki.en' has no # attribute 'MutableToken'`) that was crashing startup. import importlib _audio = importlib.import_module("cells.step_09_audio") def _noop_engine() -> None: return None _audio.get_tts_engine = _noop_engine # type: ignore[assignment] _audio.get_asr_engine = _noop_engine # type: ignore[assignment] from app import app as openenv_app # noqa: E402 # type: ignore[import-not-found] LORA_HUB_URL = "https://huggingface.co/DGXAI/gemma-3n-e2b-driftcall-lora" SOURCE_URL = "https://github.com/saumilyagupta/openenv-DGXAI" SITE_DIR = Path(__file__).parent / "site" MANIFEST_PATH = Path(__file__).parent / "openenv.yaml" # --------------------------------------------------------------------------- # Shared chrome — same dark editorial brutalism as the React site. # --------------------------------------------------------------------------- _HEAD = """
Every endpoint sits at the bare path the OpenEnv v1.0 spec expects —
no /api prefix, no rewriting. Auth is bearer
(DRIFTCALL_ENV_TOKEN) plus X-Session-Id on
every mutating call.
| method | path | description |
|---|---|---|
| GET | /healthz | health probe (unauthenticated, returns "ok") |
| POST | /reset | create or recycle a session (seed / curriculum_stage / language_weights / audio_boundary_enabled) |
| POST | /step | advance one turn — body {"action": <DriftCallAction>} |
| GET | /state | read-only DriftCallState snapshot |
| POST | /close | evict the server-side session |
| GET | /openenv.yaml | OpenEnv v1.0 manifest |
| GET | /docs | auto-generated FastAPI / Swagger UI |
This Space publishes a known public bearer token so anyone can exercise
the API end-to-end:
driftcall-demo.
# 1) probe (no auth)
curl https://saumilyajj-driftcall.hf.space/healthz
# 2) reset
curl -X POST https://saumilyajj-driftcall.hf.space/reset \\
-H "Authorization: Bearer driftcall-demo" \\
-H "X-Session-Id: smoke-001" \\
-H "Content-Type: application/json" \\
-d '{"seed": 42, "curriculum_stage": 2}'
# 3) step
curl -X POST https://saumilyajj-driftcall.hf.space/step \\
-H "Authorization: Bearer driftcall-demo" \\
-H "X-Session-Id: smoke-001" \\
-H "Content-Type: application/json" \\
-d '{"action": {"type": "end_episode"}}'
"""
# ---------------------------------------------------------------------------
# /lora — local landing page (no 302) with model card details.
# ---------------------------------------------------------------------------
_LORA_BODY = f"""
GRPO-tuned LoRA over Gemma-3n-E2B-it. Five reward components, three-stage curriculum (no drift → single drift → compound drift), 240 steps total on H100 80GB. Adapter-only — never the merged 16-bit weights, per DESIGN.md §10.5.
| repo | DGXAI/gemma-3n-e2b-driftcall-lora |
| base model | unsloth/gemma-3n-E2B-it |
| adapter type | peft / lora |
| r | 16 |
| alpha | 32 |
| dropout | 0.0 (Unsloth fast path) |
| trainer | scripts/train_driftcall_grpo.py · native PyTorch GRPO |
| curriculum | stage 1 (70 steps, no drift) → stage 2 (100 steps, single drift) → stage 3 (70 steps, compound) |
| num_generations | 2 |
| size on disk | adapter_model.safetensors · 84.6 MB · plus tokenizer (33.4 MB) |
| precision | 16-bit LoRA on bf16 base (H100 native) |
| license | apache-2.0 |
from unsloth import FastModel
from peft import PeftModel
model, tokenizer = FastModel.from_pretrained(
"unsloth/gemma-3n-E2B-it",
max_seq_length=4096,
load_in_4bit=False,
full_finetuning=False,
)
model = PeftModel.from_pretrained(model, "DGXAI/gemma-3n-e2b-driftcall-lora")
model.eval()
| id | name | weight | description |
|---|---|---|---|
| R1 | task_completion | 0.40 | did the agent actually book the cab / settle the payment / hold the reservation |
| R2 | drift_detection | 0.20 | noticed the schema mutated mid-episode and retried with the new shape |
| R3 | constraint_adherence | 0.20 | budget, time window, dietary, language — all checked deterministically |
| R4 | format_compliance | 0.10 | tool args parse against the (possibly drifted) JSON schema |
| R5 | anti_hack_penalty | 0.10 | 200-episode reward-hacking probe set; pure deterministic checks, no LLM judge |
open on hf hub ↗ project source
""" # --------------------------------------------------------------------------- # /source — local landing page (no 302) with the project file tree. # --------------------------------------------------------------------------- _SOURCE_BODY = f"""This Space bundles the entire DriftCall project — runtime modules, training scripts, the Colab-runnable notebook, design docs, the test suite, and the spec corpus. Browse the full file tree under the Files tab of this Space, or open the canonical mirror on GitHub.