File size: 1,114 Bytes
ba43a18 d3e9582 ba43a18 3fc6ddb |
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 34 35 36 |
# Use lightweight Python base image
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies (for PyTorch and git)
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# Copy requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# ✅ Hugging Face cache directory (use /tmp, writable in Spaces)
ENV HF_HOME=/tmp
# Pre-download model into /tmp to avoid cold start
RUN python -c "from transformers import AutoTokenizer, AutoModelForCausalLM; \
from peft import PeftModel; \
base_model_id='microsoft/DialoGPT-small'; \
adapter_id='rabiyulfahim/Python_coding_model'; \
AutoTokenizer.from_pretrained(base_model_id, cache_dir='/tmp'); \
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, cache_dir='/tmp'); \
PeftModel.from_pretrained(base_model, adapter_id, cache_dir='/tmp')"
# Expose the correct port (Hugging Face default is 7860)
EXPOSE 7860
# Command to run the app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|