wf-async-broken / app.py
hmb's picture
hmb HF Staff
Rename run.py to app.py
9520dc8 verified
Raw History Blame Contribute Delete
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()