#!/usr/bin/env python3 """Gradio wrapper for the TrajWiki reproduction executor (private Space). Runs the stage named in ./stage.txt in a background thread on Space startup (same stage functions as the org Docker executor, imported from executor_entrypoint.py), pushes the result to the bundle dataset repo, and shows the latest payload in the UI. ZeroGPU note: the embedding stage later uses a spaces.GPU-decorated function; importing `spaces` is safe on any Gradio Space. """ from __future__ import annotations import json import threading import traceback try: # ZeroGPU helper; harmless where unavailable import spaces # noqa: F401 except Exception: # noqa: BLE001 spaces = None # type: ignore[assignment] import gradio as gr import executor_entrypoint as ex LATEST: dict = {"payload": {"state": "starting"}} def _worker() -> None: stage = ex.read_stage() try: payload = ex.run_stage(stage) except Exception: # noqa: BLE001 - run_stage already captures; belt and braces payload = {"stage": stage, "error": traceback.format_exc()[-2000:]} LATEST["payload"] = payload def fetch_status() -> dict: return LATEST["payload"] threading.Thread(target=_worker, daemon=True).start() with gr.Blocks(title="TrajWiki executor (private)") as demo: gr.Markdown( "Private executor for the TrajWiki Table 10 reproduction. " "The stage in `stage.txt` runs on every restart; results are pushed to " "the bundle repo (`logs/`) and shown below." ) status = gr.JSON(value=fetch_status, label="Last run payload") refresh = gr.Button("Refresh") refresh.click(fn=fetch_status, outputs=status) if __name__ == "__main__": demo.launch()