Spaces:
Running on Zero
Running on Zero
Download space.py from loose-bits/u-space: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/loose-bits/u-space/resolve/main/space.py
- Command line
-
hf download hf://spaces/loose-bits/u-space/space.py
-
curl -L -o space.py https://huggingface.co/spaces/loose-bits/u-space/resolve/main/space.py
1.99 kB
| """Entry point for the Hugging Face Space. The Hub runs this file; nothing else imports it. | |
| The package is imported from `src/` rather than installed. The Hub mounts `requirements.txt` | |
| alone, at /tmp, and runs pip from a directory that is not the repo, so a `.[app]` line in it | |
| has no pyproject.toml to find; the dependencies are listed out in requirements.txt instead and | |
| this file puts `src` on the path. | |
| Everything the page needs at startup other than the model ships in `space/cache/`: the cone at | |
| every lens block, the bases at 20 and 23, and the transported vocabulary's row norms. Without | |
| them the first visitor would wait on a 388 MB lens checkpoint and a basis build before the | |
| page could paint. The 8.8 GB model is still fetched on a cold start — a Space's disk is not | |
| persistent — and only the decode panel reaches for the lens, lazily, when clicked. | |
| Why the defaults differ from the local demo: on ZeroGPU a run is charged to the *visitor's* | |
| daily quota, which is 2 minutes unauthenticated and 5 on a free account, and a thinking run | |
| asks for `60 + max_new_tokens // 5` seconds of it. So the page starts with thinking off, where | |
| the model answers in seconds, and the budget's ceiling is 512 rather than 2048. Both are plain | |
| environment variables, so the Space's settings can raise them without a code change. | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE / "src")) | |
| os.environ.setdefault("ULENS_CACHE", str(HERE / "space" / "cache")) | |
| os.environ.setdefault("ULENS_APP_THINK", "off") | |
| os.environ.setdefault("ULENS_APP_MAX_TOKENS", "512") | |
| os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False") | |
| from ulens import simplex # noqa: E402 | |
| from ulens.app import CSS, JS, build, favicon_head, theme # noqa: E402 | |
| demo = build() | |
| demo.queue().launch(css=CSS, js=JS, theme=theme(), head=favicon_head(), | |
| favicon_path=str(simplex.MARK_PATH)) | |