Download main.py from api-relay/api_relay: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/api-relay/api_relay/resolve/main/main.py
- Command line
-
hf download hf://spaces/api-relay/api_relay/main.py
-
curl -L -o main.py https://huggingface.co/spaces/api-relay/api_relay/resolve/main/main.py
1.39 kB
| import importlib | |
| import os | |
| import pkgutil | |
| from pathlib import Path | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import JSONResponse | |
| # NO request-size cap. Payload bytes are streamed straight to disk by the | |
| # artifact endpoint; JSON bodies are the only in-memory part (uvicorn default). | |
| # Disk is the only size limit — failure surfaces as an error, never a silent truncation. | |
| app = FastAPI(title="Archx Relay v4", version="4.0.0") | |
| _routers = [] | |
| projects_dir = Path(__file__).parent / "projects" | |
| if projects_dir.exists(): | |
| for module_info in pkgutil.iter_modules([str(projects_dir)]): | |
| if not module_info.ispkg: | |
| continue | |
| name = module_info.name | |
| try: | |
| mod = importlib.import_module(f"projects.{name}.router") | |
| app.include_router(mod.router, prefix=f"/{name}") | |
| _routers.append(name) | |
| except Exception as e: | |
| print(f"Failed to load project '{name}': {e}", flush=True) | |
| def health(): | |
| return {"online": "yes", "projects": _routers} | |
| def _shutdown(): | |
| for name in _routers: | |
| try: | |
| mod = importlib.import_module(f"projects.{name}.router") | |
| if hasattr(mod, "store"): | |
| mod.store.stop() | |
| except Exception as e: | |
| print(f"shutdown flush failed for {name}: {e}", flush=True) | |