Spaces:
Restarting on L40S
Restarting on L40S
Download app.py from Frame17/attention-closes-executor-private: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/Frame17/attention-closes-executor-private/resolve/main/app.py
- Command line
-
hf download hf://spaces/Frame17/attention-closes-executor-private/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Frame17/attention-closes-executor-private/resolve/main/app.py
1.81 kB
| #!/usr/bin/env python3 | |
| """Gradio wrapper for the "When Attention Closes" 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 results to the bundle dataset repos, and | |
| shows the latest payload in the UI. | |
| Requires GPU hardware (Settings -> Hardware, e.g. L40S) for the smoke/run | |
| stages, and the HF_TOKEN secret (Settings -> Variables and secrets). | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import threading | |
| import traceback | |
| 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: # 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="attention-closes executor (private)") as demo: | |
| gr.Markdown( | |
| "Private executor for the When-Attention-Closes reproduction " | |
| "(arXiv:2605.12922v2, Mistral-7B Table 1 cells). The stage in " | |
| "`stage.txt` runs on every restart; results are pushed to " | |
| "[Frame17/attention-closes-repro](https://huggingface.co/datasets/Frame17/attention-closes-repro) " | |
| "(logs/) and shown below. **Pause the Space when a stage has finished " | |
| "to stop GPU billing.**" | |
| ) | |
| 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() | |