mike23415 commited on
Commit
ec804b3
·
verified ·
1 Parent(s): 4414854

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -3
Dockerfile CHANGED
@@ -5,7 +5,8 @@ FROM python:3.10-slim
5
  ENV HF_HOME=/tmp \
6
  XDG_CACHE_HOME=/tmp \
7
  TRANSFORMERS_CACHE=/tmp \
8
- PYTHONUNBUFFERED=1
 
9
 
10
  # Install system dependencies
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -17,6 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
17
  libblas-dev \
18
  liblapack-dev \
19
  gfortran \
 
20
  && apt-get clean \
21
  && rm -rf /var/lib/apt/lists/*
22
 
@@ -25,13 +27,28 @@ WORKDIR /app
25
 
26
  # Copy requirements first for better caching
27
  COPY requirements.txt .
 
 
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
 
 
 
30
  # Copy the application code
31
  COPY . .
32
 
 
 
 
 
 
 
33
  # Expose port (for local or HF Spaces)
34
  EXPOSE 7860
35
 
36
- # Start the Flask app
37
- CMD ["python", "app.py"]
 
 
 
 
 
5
  ENV HF_HOME=/tmp \
6
  XDG_CACHE_HOME=/tmp \
7
  TRANSFORMERS_CACHE=/tmp \
8
+ PYTHONUNBUFFERED=1 \
9
+ PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:32
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
18
  libblas-dev \
19
  liblapack-dev \
20
  gfortran \
21
+ wget \
22
  && apt-get clean \
23
  && rm -rf /var/lib/apt/lists/*
24
 
 
27
 
28
  # Copy requirements first for better caching
29
  COPY requirements.txt .
30
+
31
+ # Install dependencies with specific versions
32
  RUN pip install --no-cache-dir -r requirements.txt
33
 
34
+ # Pre-download model to avoid timeout during startup
35
+ RUN python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('Qwen/Qwen2.5-1.5B-Instruct', use_fast=True)"
36
+
37
  # Copy the application code
38
  COPY . .
39
 
40
+ # Increase timeout for model loading
41
+ ENV FLASK_RUN_PORT=7860 \
42
+ TRANSFORMERS_OFFLINE=0 \
43
+ HF_HUB_DISABLE_TELEMETRY=1 \
44
+ OMP_NUM_THREADS=4
45
+
46
  # Expose port (for local or HF Spaces)
47
  EXPOSE 7860
48
 
49
+ # Use a shell script to start with proper memory management
50
+ RUN echo '#!/bin/bash\necho "Starting application with memory monitoring"\nexec python app.py' > /app/start.sh && \
51
+ chmod +x /app/start.sh
52
+
53
+ # Start the Flask app with the script
54
+ CMD ["/app/start.sh"]