Spaces:
Running
Running
| FROM python:3.10-slim | |
| WORKDIR /app | |
| # ββ System Dependencies ββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN apt-get update && apt-get install -y \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgomp1 \ | |
| g++ \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ββ Python Dependencies ββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # ββ App Code βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY app.py . | |
| COPY download_model.py . | |
| # ββ Bake Model Into Image at Build Time βββββββββββββββββββββββββββ | |
| # Runs download_model.py once during build β not on every cold start | |
| # Model files become permanently part of the image | |
| RUN python download_model.py | |
| EXPOSE 7860 | |
| # ββ Start the API ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # 2 workers β each runs its own copy of app.py with its own pool of 4 | |
| # Total simultaneous capacity: 2 workers Γ 4 pool = 8 images at once | |
| # RAM estimate: 2 Γ (4 Γ 1.2GB model + 0.3GB app) = ~10.6GB (safe on HF free tier) | |
| # uvicorn[standard] adds uvloop + httptools for faster HTTP handling | |
| # If Worker 1 crashes β Uvicorn auto-restarts it while Worker 2 keeps serving | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"] | |