noman2110014's picture
Update Dockerfile
f4fb363 verified
Raw
History Blame Contribute Delete
840 Bytes
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy app files
COPY main.py .
COPY models/ models/
# Pre-download and cache ViT weights at BUILD time
# This avoids downloading at runtime and prevents random-weights fallback
RUN python -c "\
import os; \
os.environ['TRANSFORMERS_CACHE'] = '/app/hf_cache'; \
os.environ['HF_HOME'] = '/app/hf_cache'; \
from transformers import TFViTModel; \
TFViTModel.from_pretrained('google/vit-base-patch16-224-in21k'); \
print('ViT weights cached successfully') \
"
# Set cache env vars so main.py finds the same cache at runtime
ENV TRANSFORMERS_CACHE=/app/hf_cache
ENV HF_HOME=/app/hf_cache
# HuggingFace Spaces runs on port 7860
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]