Download backend/app/main.py from modventures/character-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/main.py
- Command line
-
hf download hf://spaces/modventures/character-studio/backend/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/main.py
2.12 kB
| from contextlib import asynccontextmanager | |
| from pathlib import Path | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import FileResponse | |
| from app.config import settings | |
| from app.bootstrap import initialize | |
| from app.characters.character_controller import router as character_router | |
| from app.conversations.conversation_controller import router as conversation_router | |
| from app.scenes.scene_controller import router as scene_router | |
| from app.generations.generation_controller import router as generation_router | |
| from app.assets.asset_controller import router as asset_router | |
| from app.system.system_controller import router as system_router | |
| async def lifespan(app): | |
| initialize() | |
| yield | |
| app = FastAPI(title=settings.app_name, lifespan=lifespan) | |
| for router in ( | |
| character_router, | |
| conversation_router, | |
| scene_router, | |
| generation_router, | |
| asset_router, | |
| system_router, | |
| ): | |
| app.include_router(router, prefix="/api/v1") | |
| def health(): | |
| return {"status": "ok", "service": settings.app_name} | |
| # The built Vite app and API use the same origin in the Docker deployment. | |
| frontend = Path(__file__).resolve().parents[2] / "frontend" / "dist" | |
| def frontend_app(path: str): | |
| if path.startswith(("api/", "health/")): | |
| raise HTTPException(404, "Route not found") | |
| candidate = (frontend / path).resolve() | |
| if candidate.is_relative_to(frontend.resolve()) and candidate.is_file(): | |
| return FileResponse( | |
| candidate, | |
| headers={"Cache-Control": "public, max-age=31536000, immutable"} | |
| if path.startswith("assets/") else {"Cache-Control": "no-cache"}, | |
| ) | |
| if path.startswith("assets/") or Path(path).suffix: | |
| raise HTTPException(404, "Frontend asset not found") | |
| index = frontend / "index.html" | |
| if not index.is_file(): | |
| raise HTTPException( | |
| 404, "Build the frontend or start the Vite development server" | |
| ) | |
| return FileResponse(index, headers={"Cache-Control": "no-cache"}) | |