Spaces:
Sleeping
Sleeping
Commit ·
ba8a971
1
Parent(s): 8d63316
Fix: Dockerfile Updated to support OpenCV headless for huggingface space
Browse files- Dockerfile +32 -8
- requirements.txt +1 -0
Dockerfile
CHANGED
|
@@ -2,16 +2,35 @@ FROM python:3.10-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
libmagic1 \
|
| 9 |
file \
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
COPY requirements.txt .
|
| 14 |
-
RUN pip install --no-cache-dir -
|
|
|
|
| 15 |
|
| 16 |
# Copy application code
|
| 17 |
COPY . .
|
|
@@ -24,13 +43,18 @@ ENV HOST=0.0.0.0
|
|
| 24 |
ENV PORT=7860
|
| 25 |
ENV OLLAMA_ENABLED=false
|
| 26 |
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Expose port for HF Spaces
|
| 29 |
EXPOSE 7860
|
| 30 |
|
| 31 |
# Health check
|
| 32 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 33 |
-
CMD python -c "import requests; requests.get('http://localhost:7860/api/health', timeout=5)"
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
# Start application
|
| 36 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "120"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies for OpenCV, OCR, and basic utilities
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
libmagic1 \
|
| 9 |
file \
|
| 10 |
+
# OpenCV dependencies
|
| 11 |
+
libgl1-mesa-glx \
|
| 12 |
+
libglib2.0-0 \
|
| 13 |
+
libsm6 \
|
| 14 |
+
libxext6 \
|
| 15 |
+
libxrender1 \
|
| 16 |
+
libgomp1 \
|
| 17 |
+
libstdc++6 \
|
| 18 |
+
# OCR dependencies
|
| 19 |
+
tesseract-ocr \
|
| 20 |
+
tesseract-ocr-eng \
|
| 21 |
+
poppler-utils \
|
| 22 |
+
# Additional utilities
|
| 23 |
+
wget \
|
| 24 |
+
curl \
|
| 25 |
+
git \
|
| 26 |
+
# Clean up
|
| 27 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 28 |
+
&& apt-get clean
|
| 29 |
+
|
| 30 |
+
# Copy requirements and install Python dependencies
|
| 31 |
COPY requirements.txt .
|
| 32 |
+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 33 |
+
pip install --no-cache-dir -r requirements.txt
|
| 34 |
|
| 35 |
# Copy application code
|
| 36 |
COPY . .
|
|
|
|
| 43 |
ENV PORT=7860
|
| 44 |
ENV OLLAMA_ENABLED=false
|
| 45 |
ENV PYTHONUNBUFFERED=1
|
| 46 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 47 |
+
ENV PYTHONPATH=/app:$PYTHONPATH
|
| 48 |
|
| 49 |
# Expose port for HF Spaces
|
| 50 |
EXPOSE 7860
|
| 51 |
|
| 52 |
# Health check
|
| 53 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 54 |
+
CMD python -c "import requests; requests.get('http://localhost:7860/api/health', timeout=5)" || exit 1
|
| 55 |
+
|
| 56 |
+
# Download PaddleOCR models during build (optional, but speeds up first run)
|
| 57 |
+
RUN python -c "from paddleocr import PaddleOCR; PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False, show_log=False)" || true
|
| 58 |
|
| 59 |
+
# Start application with optimized settings for Hugging Face Spaces
|
| 60 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]
|
requirements.txt
CHANGED
|
@@ -29,6 +29,7 @@ easyocr==1.7.2
|
|
| 29 |
paddlepaddle==3.2.2
|
| 30 |
Pillow==10.0.1
|
| 31 |
opencv-python==4.6.0.66
|
|
|
|
| 32 |
|
| 33 |
# Archive Handling
|
| 34 |
py7zr==0.20.6
|
|
|
|
| 29 |
paddlepaddle==3.2.2
|
| 30 |
Pillow==10.0.1
|
| 31 |
opencv-python==4.6.0.66
|
| 32 |
+
opencv-python-headless==4.8.1.78
|
| 33 |
|
| 34 |
# Archive Handling
|
| 35 |
py7zr==0.20.6
|