Spaces:
Sleeping
Sleeping
| # Base Image | |
| FROM python:3.10-slim | |
| ENV DEBIAN_FRONTEND=noninteractive \ | |
| PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 | |
| WORKDIR /code | |
| # System Dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| git \ | |
| curl \ | |
| libopenblas-dev \ | |
| libomp-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Hugging Face + model tools | |
| RUN pip install --no-cache-dir huggingface-hub sentencepiece accelerate fasttext | |
| # Hugging Face cache environment | |
| ENV HF_HOME=/models/huggingface \ | |
| TRANSFORMERS_CACHE=/models/huggingface \ | |
| HUGGINGFACE_HUB_CACHE=/models/huggingface \ | |
| HF_HUB_CACHE=/models/huggingface | |
| # Created cache dir and set permissions | |
| RUN mkdir -p /models/huggingface && chmod -R 777 /models/huggingface | |
| # Note: Models are loaded lazily at runtime to reduce startup time and memory usage | |
| # HuggingFace Spaces will cache models automatically | |
| # Pre-downloading is skipped to keep build time and image size smaller | |
| # Copy project files | |
| COPY . . | |
| # Expose FastAPI port | |
| EXPOSE 7860 | |
| # Run FastAPI app with uvicorn (1 worker for CPU, single-threaded for memory efficiency) | |
| # Set environment variables for CPU optimization | |
| ENV OMP_NUM_THREADS=4 \ | |
| MKL_NUM_THREADS=4 \ | |
| NUMEXPR_NUM_THREADS=4 | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "30"] |