Spaces:
Runtime error
Runtime error
Upload Dockerfile with huggingface_hub
Browse files- Dockerfile +24 -8
Dockerfile
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
COPY requirements.txt .
|
| 10 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
COPY . .
|
| 14 |
|
| 15 |
-
# Expose
|
| 16 |
EXPOSE 7860
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
CMD ["
|
|
|
|
| 1 |
+
# Use Python 3.10 (Stable for Torch/Transformers)
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
| 6 |
+
ENV PYTHONUNBUFFERED 1
|
| 7 |
+
ENV PORT 7860
|
| 8 |
+
|
| 9 |
+
# Install system dependencies (OpenCV requires libgl1)
|
| 10 |
+
RUN apt-get update && apt-get install -y \
|
| 11 |
+
libgl1-mesa-glx \
|
| 12 |
+
libglib2.0-0 \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
+
# Set working directory
|
| 16 |
+
WORKDIR /app
|
| 17 |
|
| 18 |
+
# Copy requirements and install
|
| 19 |
COPY requirements.txt .
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
+
# Pre-download models to bake them into the Docker image
|
| 23 |
+
# This ensures fast startup on Hugging Face Spaces
|
| 24 |
+
RUN python -c "from transformers import TrOCRProcessor, VisionEncoderDecoderModel; \
|
| 25 |
+
TrOCRProcessor.from_pretrained('microsoft/trocr-large-handwritten'); \
|
| 26 |
+
VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-large-handwritten')"
|
| 27 |
+
|
| 28 |
+
# Copy the rest of the application
|
| 29 |
COPY . .
|
| 30 |
|
| 31 |
+
# Expose the HF default port
|
| 32 |
EXPOSE 7860
|
| 33 |
|
| 34 |
+
# Command to run the application
|
| 35 |
+
CMD ["python", "api.py"]
|