Spaces:
Running on Zero
Running on Zero
Download app.py from abidlabs/event-table-executor-zerogpu: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/abidlabs/event-table-executor-zerogpu/resolve/main/app.py
- Command line
-
hf download hf://spaces/abidlabs/event-table-executor-zerogpu/app.py
-
curl -L -o app.py https://huggingface.co/spaces/abidlabs/event-table-executor-zerogpu/resolve/main/app.py
1.72 kB
| """Process-executor check on Spaces: SSR, and ZeroGPU when ZERO=1.""" | |
| import os | |
| import subprocess | |
| import sys | |
| # The Space installs Gradio 6.29.1; this app needs the PR's build, which a | |
| # Space's build step cannot see, so install it here once and start again | |
| if not os.environ.get("PR_GRADIO_INSTALLED"): | |
| here = os.path.dirname(os.path.abspath(__file__)) | |
| subprocess.check_call( | |
| [ | |
| sys.executable, | |
| "-m", | |
| "pip", | |
| "install", | |
| "--no-cache-dir", | |
| f"{here}/wheels/gradio_client-2.7.2-py3-none-any.whl", | |
| f"{here}/wheels/gradio-6.30.0-py3-none-any.whl", | |
| ] | |
| ) | |
| os.environ["PR_GRADIO_INSTALLED"] = "1" | |
| os.execv(sys.executable, [sys.executable, *sys.argv]) | |
| import gradio as gr | |
| ZERO = os.environ.get("ZERO") == "1" | |
| if ZERO: | |
| import spaces | |
| import torch | |
| def gpu(x: str) -> str: | |
| return f"{x} on {torch.cuda.get_device_name(0)} (app pid {os.getpid()})" | |
| def echo(x: str) -> str: | |
| return f"{x[::-1]} (pid {os.getpid()})" | |
| def info() -> str: | |
| return ( | |
| f"gradio {gr.__version__} (PR commit {open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'PR_COMMIT')).read().strip()}); executor " | |
| f"{'process' if getattr(demo, '_process_worker', None) else 'thread'}; " | |
| f"ssr {getattr(demo, 'ssr_mode', None)}; pid {os.getpid()}" | |
| ) | |
| with gr.Blocks() as demo: | |
| text = gr.Textbox(label="input") | |
| out = gr.Textbox(label="output") | |
| gr.Button("echo").click(echo, text, out, api_name="echo") | |
| gr.Button("info").click(info, None, out, api_name="info") | |
| if ZERO: | |
| gr.Button("gpu").click(gpu, text, out, api_name="gpu") | |
| demo.launch() | |