Download code/backend/app/main.py from Arko007/Yoga-1M: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/Arko007/Yoga-1M/resolve/main/code/backend/app/main.py
- Command line
-
hf download hf://datasets/Arko007/Yoga-1M/code/backend/app/main.py
-
curl -L -o main.py https://huggingface.co/datasets/Arko007/Yoga-1M/resolve/main/code/backend/app/main.py
1.37 kB
| import torch | |
| from fastapi import FastAPI | |
| from app.config import settings | |
| from app.services.hf_loader import initialize_models | |
| from app.routers import pose, correction | |
| # Enforce thread limits on startup | |
| torch.set_num_threads(settings.CPU_THREADS) | |
| torch.set_num_interop_threads(settings.CPU_THREADS) | |
| app = FastAPI( | |
| title=settings.TITLE, | |
| version=settings.VERSION, | |
| description="Modular, production-grade API for Smart Yoga Posture Correction (P05)" | |
| ) | |
| from fastapi.middleware.cors import CORSMiddleware | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=[ | |
| "https://yoga-posture-correction-system.vercel.app", | |
| "http://localhost:3000", # for local dev | |
| "http://localhost:3001", | |
| ], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Startup event: Pre-cache models to prevent runtime latency spikes | |
| def startup_event(): | |
| print("Startup: Fetching and caching weights from Hugging Face Hub...", flush=True) | |
| initialize_models() | |
| # Include routers | |
| app.include_router(pose.router, prefix="/api", tags=["Pose Analysis"]) | |
| app.include_router(correction.router, prefix="/api", tags=["Postural Corrections"]) | |
| def health_check(): | |
| return { | |
| "status": "healthy", | |
| "device": str(settings.DEVICE), | |
| "app_title": settings.TITLE | |
| } | |