ayush2917 commited on
Commit
33a77e9
·
verified ·
1 Parent(s): 1790f92

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -18
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- # Use the official Hugging Face Docker image as base
2
  FROM python:3.9-slim
3
 
4
  # Set environment variables
@@ -9,7 +9,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
9
  PIP_NO_CACHE_DIR=1 \
10
  PORT=8000
11
 
12
- # Create and set working directory
 
 
13
  WORKDIR /app
14
 
15
  # Install system dependencies
@@ -17,31 +19,42 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
17
  build-essential \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
- # Copy requirements first for better caching
21
  COPY requirements.txt .
22
 
23
  # Install Python dependencies
24
  RUN pip install --upgrade pip && \
25
  pip install --no-cache-dir -r requirements.txt
26
 
27
- # Copy the rest of the application
28
- COPY . .
 
 
 
 
 
29
 
30
- # Create necessary directories
31
- RUN mkdir -p /app/data /cache
32
 
33
- # Download models during build (optional)
34
  RUN python -c "\
35
- try: \
36
- from sentence_transformers import SentenceTransformer; \
37
- SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/cache'); \
38
- from transformers import AutoModelForCausalLM, AutoTokenizer; \
39
- AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/cache'); \
40
- AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/cache'); \
41
- except Exception as e: \
42
- print(f'Model preloading failed: {str(e)}'); \
43
- raise \
44
  "
45
 
46
- # Run the application
 
 
 
 
 
 
 
 
 
 
 
 
47
  CMD gunicorn --bind 0.0.0.0:$PORT --workers 2 --timeout 120 --preload app:app
 
1
+ # Hugging Face Spaces optimized image
2
  FROM python:3.9-slim
3
 
4
  # Set environment variables
 
9
  PIP_NO_CACHE_DIR=1 \
10
  PORT=8000
11
 
12
+ # Create directory structure
13
+ RUN mkdir -p /app/{data,src,config,templates,static/css,tests}
14
+
15
  WORKDIR /app
16
 
17
  # Install system dependencies
 
19
  build-essential \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
+ # Copy requirements first for caching
23
  COPY requirements.txt .
24
 
25
  # Install Python dependencies
26
  RUN pip install --upgrade pip && \
27
  pip install --no-cache-dir -r requirements.txt
28
 
29
+ # Copy application files
30
+ COPY app.py .
31
+ COPY src/ /app/src/
32
+ COPY config/ /app/config/
33
+ COPY templates/ /app/templates/
34
+ COPY static/ /app/static/
35
+ COPY tests/ /app/tests/
36
 
37
+ # Copy data files with correct permissions
38
+ COPY --chown=1000:1000 data/ /app/data/
39
 
40
+ # Verify data files
41
  RUN python -c "\
42
+ import os, json; \
43
+ assert os.path.exists('/app/data/rupeia_document.json'), 'Data file missing'; \
44
+ assert os.path.exists('/app/data/chat_history.json'), 'History file missing' \
 
 
 
 
 
 
45
  "
46
 
47
+ # Download models during build
48
+ RUN python -c "\
49
+ from sentence_transformers import SentenceTransformer; \
50
+ SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/cache'); \
51
+ from transformers import AutoModelForCausalLM, AutoTokenizer; \
52
+ AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/cache'); \
53
+ AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/cache') \
54
+ "
55
+
56
+ # Set proper permissions
57
+ RUN chmod a+r /app/data/*.json && \
58
+ find /app -type d -exec chmod a+rx {} \;
59
+
60
  CMD gunicorn --bind 0.0.0.0:$PORT --workers 2 --timeout 120 --preload app:app