Spaces:
Sleeping
Sleeping
Download app.py from hmb/wf-async-broken: direct link, hf CLI and curl.
- Browser
- Download file 854 Bytes
-
https://huggingface.co/spaces/hmb/wf-async-broken/resolve/main/app.py
- Command line
-
hf download hf://spaces/hmb/wf-async-broken/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hmb/wf-async-broken/resolve/main/app.py
854 Bytes
| """ | |
| Parallel execution test for gr.Workflow. | |
| Open in two browser tabs, type different prompts, click Run in both within | |
| a second of each other. Check the printed timestamps: | |
| BEFORE fix: tab 2's slow_fn starts exactly when tab 1's slow_fn ends (~16s total) | |
| AFTER fix: both run concurrently (~8s total), timestamps overlap | |
| """ | |
| import time | |
| from datetime import UTC, datetime | |
| import gradio as gr | |
| def _now() -> str: | |
| return datetime.now(UTC).strftime("%H:%M:%S.%f")[:-3] | |
| def slow_fn(text: str) -> str: | |
| start = _now() | |
| time.sleep(5) | |
| return f"slow | start={start} end={_now()} | input={text!r}" | |
| def fast_fn(text: str) -> str: | |
| start = _now() | |
| time.sleep(2) | |
| return f"fast | start={start} end={_now()}\n{text}" | |
| demo = gr.Workflow(bind={"slow_fn": slow_fn, "fast_fn": fast_fn}) | |
| if __name__ == "__main__": | |
| demo.launch() | |