Spaces:
Sleeping
Sleeping
| # Use an official Python runtime as a parent image | |
| FROM python:3.11-slim | |
| # Set the working directory | |
| WORKDIR /app | |
| # Install necessary system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| gcc \ | |
| poppler-utils \ | |
| cmake \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgl1-mesa-glx \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set the CC environment variable to ensure TorchInductor uses the correct compiler | |
| ENV CC=gcc | |
| # Copy the requirements file and install dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Create cache and config directories with appropriate permissions | |
| RUN mkdir -p /app/cache && chmod 777 /app/cache | |
| RUN mkdir -p /app/config && chmod 777 /app/config | |
| RUN mkdir -p /app/triton_cache && chmod 777 /app/triton_cache | |
| RUN mkdir -p /app/torchinductor_cache && chmod 777 /app/torchinductor_cache | |
| RUN mkdir -p /mnt/data && chmod 777 /mnt/data | |
| RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache | |
| # for /.cache/doctr/models | |
| RUN mkdir -p /app/.cache/doctr && chmod -R 777 /app/.cache/doctr | |
| # Create directories for Matplotlib and Fontconfig with appropriate permissions | |
| RUN mkdir -p /app/matplotlib && chmod 777 /app/matplotlib | |
| RUN mkdir -p /app/fontconfig && chmod 777 /app/fontconfig | |
| # Set environment variables for Hugging Face cache, config, Triton, and TorchInductor directories | |
| ENV HF_HOME=/app/cache | |
| ENV XDG_CACHE_HOME=/app/.cache | |
| ENV XDG_CONFIG_HOME=/app/config | |
| ENV TRITON_CACHE_DIR=/app/triton_cache | |
| ENV TORCHINDUCTOR_CACHE_DIR=/app/torchinductor_cache | |
| ENV MPLCONFIGDIR=/app/matplotlib | |
| ENV FONTCONFIG_PATH=/app/fontconfig | |
| ENV TORCH_HOME=/app/torchinductor_cache | |
| ENV TRITON_CACHE=/app/triton_cache | |
| ENV TOKENIZERS_PARALLELISM=false | |
| ENV DOCTR_CACHE_DIR=/app/.cache/doctr | |
| # Copy the application code | |
| COPY main.py . | |
| COPY utils.py ./ | |
| COPY data_models.py ./ | |
| COPY models /app/models | |
| # Expose the port FastAPI will run on | |
| EXPOSE 7860 | |
| # Command to run the FastAPI app | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |