Download engine/app/server.py from lorcapoul/smol-neuron-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/lorcapoul/smol-neuron-studio/resolve/main/engine/app/server.py
- Command line
-
hf download hf://spaces/lorcapoul/smol-neuron-studio/engine/app/server.py
-
curl -L -o server.py https://huggingface.co/spaces/lorcapoul/smol-neuron-studio/resolve/main/engine/app/server.py
1.28 kB
| """Servidor de producción (Space): la API bajo /api y la interfaz estática en /. | |
| En desarrollo se sigue usando `app.main:app` (rutas en la raíz) con Nuxt reenviando | |
| /api al motor; aquí se reproduce esa misma forma en un solo proceso: | |
| cd engine && uv run uvicorn app.server:app --port 7860 | |
| La interfaz sale de `nuxt generate` (`web/.output/public`, o `WEB_DIST`). | |
| """ | |
| import os | |
| from contextlib import asynccontextmanager | |
| from pathlib import Path | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from app.main import app as api | |
| DEFAULT_WEB_DIST = Path(__file__).resolve().parents[2] / "web" / ".output" / "public" | |
| def create_app(web_dist: Path | None) -> FastAPI: | |
| async def lifespan(_: FastAPI): | |
| # Las apps montadas no corren su propio lifespan: delegar en el de la API. | |
| async with api.router.lifespan_context(api): | |
| yield | |
| root = FastAPI(title="Smol Neuron Studio", lifespan=lifespan, docs_url=None, redoc_url=None, openapi_url=None) | |
| root.mount("/api", api) | |
| if web_dist and (web_dist / "index.html").exists(): | |
| root.mount("/", StaticFiles(directory=web_dist, html=True), name="web") | |
| return root | |
| app = create_app(Path(os.environ.get("WEB_DIST", DEFAULT_WEB_DIST))) | |