amine_dubs commited on
Commit
6241879
·
1 Parent(s): d645d4c

Fix: Add python-multipart and set HF cache directory

Browse files
Files changed (2) hide show
  1. Dockerfile +26 -27
  2. backend/requirements.txt +2 -1
Dockerfile CHANGED
@@ -1,40 +1,39 @@
1
- # Use an official Python slim-buster runtime as a parent image
2
  FROM python:3.12-slim
3
 
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Install system dependencies including Rust, build tools, pkg-config, cmake, and sentencepiece dev libs using apt-get
8
- RUN apt-get update && apt-get install -y --no-install-recommends \
9
- rustc \
10
- cargo \
11
- build-essential \
12
- pkg-config \
13
- cmake \
14
- libsentencepiece-dev \
15
- # Clean up apt lists to reduce image size
16
- && rm -rf /var/lib/apt/lists/*
17
-
18
- # Copy only the requirements file first to leverage Docker cache
19
- COPY backend/requirements.txt /app/requirements.txt
20
-
21
- # Install Python dependencies
22
- RUN pip install --no-cache-dir --upgrade pip
23
  RUN pip install --no-cache-dir -r requirements.txt
24
 
25
  # Copy the rest of the application code into the container
26
- COPY backend/ /app/backend
27
- COPY templates/ /app/templates
28
- COPY static/ /app/static
 
29
 
30
- # Create the necessary directories within the container that the app expects
31
- RUN mkdir -p /app/templates /app/static /app/uploads
32
 
33
- # Grant write permissions to the uploads directory
34
- RUN chmod -R 777 /app/uploads
35
-
36
- # Make port 8000 available
37
  EXPOSE 8000
38
 
39
- # Run main.py using uvicorn
 
 
 
 
40
  CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
+ # Use an official Python runtime as a parent image
2
  FROM python:3.12-slim
3
 
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
+ # --- Set Hugging Face cache directory ---
8
+ # Create a cache directory within the working directory and set HF_HOME
9
+ # This ensures the container has write permissions for downloading models/tokenizers
10
+ RUN mkdir -p /app/.cache
11
+ ENV HF_HOME=/app/.cache
12
+ ENV TRANSFORMERS_CACHE=/app/.cache # Also set TRANSFORMERS_CACHE for good measure
13
+
14
+ # Copy the requirements file into the container at /app
15
+ # Copy only requirements first to leverage Docker layer caching
16
+ COPY backend/requirements.txt .
17
+
18
+ # Install any needed packages specified in requirements.txt
19
+ # Add --no-cache-dir to reduce image size
 
 
 
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # Copy the rest of the application code into the container
23
+ # Copy backend, static, and templates directories
24
+ COPY backend/ ./backend
25
+ COPY static/ ./static
26
+ COPY templates/ ./templates
27
 
28
+ # Create the uploads directory (ensure it exists)
29
+ RUN mkdir -p /app/uploads
30
 
31
+ # Make port 8000 available to the world outside this container
 
 
 
32
  EXPOSE 8000
33
 
34
+ # Define environment variable (optional, can be set in HF Spaces settings too)
35
+ # ENV MODEL_NAME="Helsinki-NLP/opus-mt-en-ar"
36
+
37
+ # Run main.py when the container launches
38
+ # Use the backend subdirectory path for the module
39
  CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
backend/requirements.txt CHANGED
@@ -3,4 +3,5 @@ uvicorn
3
  python-docx
4
  PyMuPDF
5
  transformers[torch]
6
- sentencepiece # Added for MarianTokenizer
 
 
3
  python-docx
4
  PyMuPDF
5
  transformers[torch]
6
+ sentencepiece
7
+ python-multipart # Added for FastAPI form data handling