File size: 1,414 Bytes
0e92f07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f20e646
 
 
d30125c
 
6df633f
0e92f07
 
 
6df633f
 
0e92f07
 
 
 
6df633f
 
 
 
 
 
 
 
c70a5b7
0e92f07
 
c70a5b7
 
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
37
38
39
40
41
42
43
44
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    && rm -rf /var/lib/apt/lists/*

# Copy and install requirements
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

# βœ… Install accelerate (fixes distilgpt2 loading with device_map)
RUN pip install --no-cache-dir accelerate

# βœ… Set environment variables to a writable path
ENV HF_HOME=/app/cache
ENV TRANSFORMERS_CACHE=/app/cache
ENV TOKENIZERS_PARALLELISM=false
ENV OMP_NUM_THREADS=1

# βœ… Create cache directory with proper permissions
RUN mkdir -p /app/cache && chmod -R 777 /app/cache

# Copy application
COPY . .

# βœ… Pre-download the model during build (optional but recommended)
RUN python -c "from transformers import AutoTokenizer, AutoModelForCausalLM; \
    AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache'); \
    AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache')" || echo "Model download failed, will retry at runtime"

# βœ… Ensure cache directory is writable after model download
RUN chmod -R 777 /app/cache

# βœ… Expose Gradio port
EXPOSE 7860

# βœ… Run Gradio app directly (no need for gunicorn)
CMD ["python", "app.py"]