testCaseGenerator / Dockerfile
Syncbuz120's picture
Convert Flask to Gradio
c70a5b7
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"]