Angstormy commited on
Commit
a652eba
·
verified ·
1 Parent(s): 581f3be

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -8
Dockerfile CHANGED
@@ -1,19 +1,35 @@
 
1
  FROM python:3.10-slim
2
 
3
- WORKDIR /app
 
 
 
 
 
 
 
 
 
4
 
5
- # Install minimal system dependencies
6
- RUN apt-get update && apt-get install -y libglib2.0-0 && rm -rf /var/lib/apt/lists/*
7
 
8
- # Install Python requirements
9
  COPY requirements.txt .
10
  RUN pip install --no-cache-dir -r requirements.txt
11
 
12
- # Copy all the model files and api.py
 
 
 
 
 
 
13
  COPY . .
14
 
15
- # Expose port 7860 (Hugging Face Spaces default port)
16
  EXPOSE 7860
17
 
18
- # Start the FastAPI server using uvicorn
19
- CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
 
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"]