riteshraut commited on
Commit
07274f3
·
1 Parent(s): f6d6be5
Files changed (1) hide show
  1. Dockerfile +21 -30
Dockerfile CHANGED
@@ -1,40 +1,31 @@
1
- FROM python:3.9-slim
 
2
 
3
- # Set working directory
4
- WORKDIR /app
5
 
6
- # Install system dependencies
7
- # Update package lists first
8
- RUN apt-get update
9
-
10
- # Install each main package and its dependencies in a separate layer
11
- RUN apt-get install -y --no-install-recommends libfaiss-dev && rm -rf /var/lib/apt/lists/*
12
- RUN apt-get update && apt-get install -y --no-install-recommends tesseract-ocr && rm -rf /var/lib/apt/lists/*
13
- RUN apt-get update && apt-get install -y --no-install-recommends libgl1 && rm -rf /var/lib/apt/lists/*
14
-
15
- # Set environment variables for writable directories
16
- ENV HOME=/tmp
17
  ENV NLTK_DATA=/tmp/nltk_data
18
- ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
19
- ENV HF_HOME=/tmp/huggingface
20
- ENV PYTHONUNBUFFERED=1
21
-
22
- # Create necessary directories with proper permissions
23
- RUN mkdir -p /tmp/nltk_data /tmp/transformers_cache /tmp/huggingface /tmp/uploads && \
24
- chmod -R 777 /tmp
25
-
26
- # Copy requirements and install Python dependencies
27
  COPY requirements.txt .
28
- RUN pip install --no-cache-dir -r requirements.txt
29
 
30
- # Download NLTK data during build
31
- RUN python -c "import nltk; nltk.download('punkt', download_dir='/tmp/nltk_data'); nltk.download('stopwords', download_dir='/tmp/nltk_data')"
32
 
33
- # Copy application files
34
  COPY . .
35
 
36
- # Expose port
37
  EXPOSE 7860
38
 
39
- # Run the application
40
- CMD ["gunicorn", "-b", "0.0.0.0:7860", "--timeout", "300", "--workers", "1", "app:app"]
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.11-slim
3
 
4
+ # Set the working directory in the container
5
+ WORKDIR /code
6
 
7
+ # Set writable cache directories for Hugging Face models and NLTK data
8
+ ENV HF_HOME=/tmp/huggingface_cache
 
 
 
 
 
 
 
 
 
9
  ENV NLTK_DATA=/tmp/nltk_data
10
+ ENV MPLCONFIGDIR=/tmp/matplotlib_cache
11
+ ENV FONTCONFIG_PATH=/tmp/fontconfig
12
+ ENV XDG_CACHE_HOME=/tmp/xdg_cache
13
+ # Copy the system dependencies file and install them
14
+ COPY packages.txt .
15
+ RUN apt-get update && apt-get install -y --no-install-recommends $(cat packages.txt) && \
16
+ rm -rf /var/lib/apt/lists/*
17
+
18
+ # Copy the Python requirements file
19
  COPY requirements.txt .
 
20
 
21
+ # Install the Python dependencies
22
+ RUN pip install --no-cache-dir -r requirements.txt
23
 
24
+ # Copy the rest of your application code into the container
25
  COPY . .
26
 
27
+ # Expose the port that Hugging Face Spaces uses
28
  EXPOSE 7860
29
 
30
+ # Command to run your application using gunicorn
31
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]