WORKWITHSHAFISK's picture
Create Dockerfile
0936b8e verified
# Use Python 3.10-slim (Slightly better support for newer ML libs than 3.9)
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# 1. Install system dependencies
# Added 'tesseract-ocr' and 'libtesseract-dev' because your backend uses OCR
# Kept 'build-essential' and 'libgl1' from your previous successful file
RUN apt-get update && apt-get install -y \
build-essential \
libgl1 \
tesseract-ocr \
libtesseract-dev \
&& rm -rf /var/lib/apt/lists/*
# 2. Upgrade pip first (Critical for finding wheels, as per your previous experience)
RUN pip install --upgrade pip
# 3. Copy requirements and install
COPY requirements.txt .
# Using --prefer-binary to avoid compiling heavy libs like Numpy/Pandas from source
RUN pip install --no-cache-dir --prefer-binary -r requirements.txt
# 4. Download AI Models (Baked into the image to speed up startup)
# Spacy Large model
RUN python -m spacy download en_core_web_lg
# NLTK Data (Added 'punkt_tab' which is often needed in newer NLTK versions)
RUN python -m nltk.downloader punkt punkt_tab averaged_perceptron_tagger maxent_ne_chunker words
# 5. Setup Cache Permissions for Hugging Face Transformers (DeBERTa/GLiNER)
# This prevents "Permission Denied" errors when the app tries to download models at runtime
ENV TRANSFORMERS_CACHE=/app/cache
ENV HF_HOME=/app/cache
RUN mkdir -p /app/cache && chmod 777 /app/cache
# 6. Copy the rest of the application
COPY . .
# 7. Expose the port (Hugging Face Spaces expects 7860)
EXPOSE 7860
# 8. Start FastAPI
# IMPORTANT: Changing "main:app" -> "api:app" because your file is named api.py
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]