Spaces:
Sleeping
Sleeping
Syedkaif29
Deploy hf_space_requirements_fix with latest improvements - Memory optimization, Enhanced PDF processing, OCR support
9f42118
| FROM python:3.11-slim | |
| # Set environment variables for cache directories | |
| ENV TRANSFORMERS_CACHE=/tmp/transformers_cache | |
| ENV HF_HOME=/tmp/huggingface_cache | |
| ENV TORCH_HOME=/tmp/torch_cache | |
| ENV PYTHONPATH=/app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| tesseract-ocr \ | |
| tesseract-ocr-eng \ | |
| libtesseract-dev \ | |
| poppler-utils \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create cache directories with proper permissions | |
| RUN mkdir -p /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache && \ | |
| chmod -R 777 /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache | |
| WORKDIR /app | |
| # Copy requirements and install dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy application files | |
| COPY . . | |
| # Set proper permissions for the app directory | |
| RUN chmod -R 755 /app | |
| # Create a non-root user for security | |
| RUN useradd -m -u 1000 appuser && \ | |
| chown -R appuser:appuser /app /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache | |
| # Switch to non-root user | |
| USER appuser | |
| # Expose port | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Run the application | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |