Pujan-Dev commited on
Commit
c03128c
·
1 Parent(s): ccc8e1a

refact: added the module for proper python setup

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -14
Dockerfile CHANGED
@@ -1,25 +1,40 @@
1
- # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.10
5
-
6
- # Create user first
 
 
 
 
 
 
7
  RUN useradd -m -u 1000 user
8
 
9
- # Install system dependencies (requires root)
10
- RUN apt-get update && apt-get install -y libgl1
 
 
11
 
12
- # Switch to non-root user
13
  USER user
14
- ENV PATH="/home/user/.local/bin:$PATH"
15
-
16
  WORKDIR /app
17
 
18
- COPY --chown=user ./requirements.txt requirements.txt
19
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
- RUN python -m spacy download en_core_web_sm || echo "Failed to download model"
 
 
 
 
 
 
 
21
 
22
- COPY --chown=user . /app
 
23
 
 
24
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
25
 
 
1
+ # Use official Python 3.10 image
2
+ FROM python:3.10-slim
3
 
4
+ # Install system dependencies (requires root)
5
+ RUN apt-get update && \
6
+ apt-get install -y --no-install-recommends \
7
+ libgl1 \
8
+ build-essential \
9
+ curl \
10
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Create non-root user
13
  RUN useradd -m -u 1000 user
14
 
15
+ # Set environment for pip and path
16
+ ENV PATH="/home/user/.local/bin:$PATH" \
17
+ PYTHONDONTWRITEBYTECODE=1 \
18
+ PYTHONUNBUFFERED=1
19
 
20
+ # Switch to the user
21
  USER user
 
 
22
  WORKDIR /app
23
 
24
+ # Copy and install requirements
25
+ COPY --chown=user requirements.txt .
26
+ RUN pip install --no-cache-dir --upgrade pip && \
27
+ pip install --no-cache-dir -r requirements.txt
28
+
29
+ # Ensure spaCy model is installed (safe fallback if download fails)
30
+ RUN python -m spacy download en_core_web_sm || echo "spaCy model download failed, continuing..."
31
+
32
+ # Copy rest of the app
33
+ COPY --chown=user . .
34
 
35
+ # Expose port (optional but good practice)
36
+ EXPOSE 7860
37
 
38
+ # Start the app
39
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
40