Spaces:
Running
Running
| # Use an official Python runtime as a parent image | |
| FROM python:3.12-slim | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy the requirements file | |
| COPY requirements.txt requirements.txt | |
| # Install Python packages with timeout increase | |
| RUN pip install --no-cache-dir --timeout=1000 -r requirements.txt | |
| # Copy application code | |
| COPY . /app | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 user | |
| # Change ownership | |
| RUN chown -R user:user /app | |
| # Switch to the non-root user | |
| USER user | |
| # Expose the port | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV FLASK_HOST=0.0.0.0 | |
| ENV FLASK_PORT=7860 | |
| ENV FLASK_DEBUG=False | |
| # CRITICAL: Set HF-specific env vars | |
| ENV TRANSFORMERS_CACHE=/tmp/transformers_cache | |
| ENV HF_HOME=/tmp/hf_home | |
| ENV TORCH_HOME=/tmp/torch_home | |
| # Command to run the app | |
| CMD ["python", "app.py"] |