Multimodal_urdu / Dockerfile
oldAhmed's picture
Update Dockerfile
1420c51 verified
Raw
History Blame Contribute Delete
1.42 kB
# Use a lightweight Python base
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system packages if needed
RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Install PyTorch CPU version
RUN pip install --no-cache-dir torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cpu
# Copy dependency list
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Create cache directory and set permissions
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
# Set environment variable for Hugging Face cache
# Set cache env vars
ENV HF_HOME=/app/cache
ENV TORCH_HOME=/app/cache
# ✅ Pre-download BERT
RUN python -c "\
import os; \
from transformers import BertTokenizerFast, BertModel; \
import torchvision.models as models; \
from torchvision.models import Inception_V3_Weights; \
cache_dir = '/app/cache'; \
BertTokenizerFast.from_pretrained('bert-base-multilingual-cased', cache_dir=cache_dir); \
BertModel.from_pretrained('bert-base-multilingual-cased', cache_dir=cache_dir); \
models.inception_v3(weights=Inception_V3_Weights.IMAGENET1K_V1); \
print('Files in cache:', os.listdir(cache_dir))"
# Copy the app and model files
COPY . .
# Expose port
EXPOSE 7860
# Run FastAPI app with Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]