File size: 968 Bytes
f59cf24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fea25f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# βœ… Use official slim image
FROM python:3.10-slim

# βœ… Set working directory
WORKDIR /app

# βœ… Set environment variables early to ensure cache use in setup.py
ENV TRANSFORMERS_CACHE=/app/model_cache \
    HF_HOME=/app/model_cache \
    TORCH_HOME=/app/model_cache \
    TOKENIZERS_PARALLELISM=false \
    OMP_NUM_THREADS=4

# βœ… Install only necessary OS packages and clean cache
RUN apt-get update && apt-get install -y git \
 && rm -rf /var/lib/apt/lists/*

# βœ… Copy files (excluding model_cache, logs, etc. via .dockerignore)
COPY . .

# βœ… Upgrade pip + install deps without cache
RUN pip install --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

# βœ… Run setup.py to download the model
RUN python setup.py

# βœ… Expose Hugging Face Space-required port
EXPOSE 7860

# βœ… Launch FastAPI on port 7860 for HF Space
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "120", "--log-level", "info"]