Spaces:
Sleeping
Sleeping
shivam0897-i
fix(backend): Convert PyTorch thread execution to bounded async pool to prevent OOM on HF Spaces
4eae08d | FROM python:3.10-slim | |
| WORKDIR /app | |
| # Install system dependencies for librosa and audio processing | |
| RUN apt-get update && apt-get install -y \ | |
| libsndfile1 \ | |
| ffmpeg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements first for better caching | |
| COPY requirements.txt . | |
| # Install CPU-only PyTorch first (smaller size) | |
| RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu | |
| # Install other dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application code and model | |
| COPY . . | |
| # Create a non-root user for HF Spaces | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR /app | |
| # Hugging Face Spaces uses port 7860 | |
| EXPOSE 7860 | |
| # Run the application (2 workers for increased performance, Python handles thread locking to prevent OOM) | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"] | |