therandomuser03 commited on
Commit
15f9d61
·
1 Parent(s): bae0f63

update backend for HF

Browse files
Files changed (2) hide show
  1. Dockerfile +15 -9
  2. requirements.txt +3 -5
Dockerfile CHANGED
@@ -1,32 +1,38 @@
1
- # 1. Use Python 3.10
2
  FROM python:3.10-slim
3
 
4
  # 2. Set working directory
5
  WORKDIR /app
6
 
7
- # 3. Install system dependencies (including build tools for llama-cpp-python if needed)
8
- RUN apt-get update && apt-get install -y \
 
 
9
  libgl1 \
10
  libglib2.0-0 \
11
  build-essential \
12
  python3-dev \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # 4. Install Python dependencies
 
 
 
 
 
16
  COPY requirements.txt .
17
  RUN pip install --no-cache-dir -r requirements.txt
18
 
19
- # 5. Copy your code
20
  COPY . .
21
 
22
- # 6. Download all ML models (Face, Text, LLaMA 3 GGUF) during build
23
- # This ensures a "batteries included" image for HF Spaces
24
  RUN python download_models.py
25
 
26
- # 7. Environment & Port settings (7860 is HF Spaces standard)
27
  ENV PYTHONPATH=/app
28
  ENV USE_EMBEDDED_LLM=True
29
  EXPOSE 7860
30
 
31
- # 8. Run the app with Uvicorn
32
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # 1. Use Python 3.10 slim
2
  FROM python:3.10-slim
3
 
4
  # 2. Set working directory
5
  WORKDIR /app
6
 
7
+ # 3. Install minimal system dependencies
8
+ # - libgl1/libglib2.0-0: OpenCV needs these
9
+ # - build-essential/python3-dev: llama-cpp-python builds from source
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
  libgl1 \
12
  libglib2.0-0 \
13
  build-essential \
14
  python3-dev \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # 4. Install PyTorch CPU-only FIRST (saves ~1.5GB vs full CUDA torch)
18
+ # This is a separate layer so it caches well
19
+ RUN pip install --no-cache-dir \
20
+ torch --index-url https://download.pytorch.org/whl/cpu
21
+
22
+ # 5. Install remaining Python dependencies
23
  COPY requirements.txt .
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
+ # 6. Copy your code
27
  COPY . .
28
 
29
+ # 7. Download all ML models (Face, Text, LLaMA 3 GGUF) during build
 
30
  RUN python download_models.py
31
 
32
+ # 8. Environment & Port settings (7860 is HF Spaces standard)
33
  ENV PYTHONPATH=/app
34
  ENV USE_EMBEDDED_LLM=True
35
  EXPOSE 7860
36
 
37
+ # 9. Run the app with Uvicorn
38
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
requirements.txt CHANGED
@@ -12,18 +12,16 @@ anyio>=4.0.0
12
  # --- Rate Limiting ---
13
  slowapi>=0.1.9
14
 
15
- # --- AI & Vision (Preserved - Version Locked for Stability) ---
16
  numpy<2.0
17
- opencv-python
18
- tensorflow
19
  tensorflow-cpu
20
  pandas
21
  pillow
22
  gdown
23
 
24
- # --- NLP (New) ---
25
  transformers>=4.40.0
26
- torch>=2.0.0
27
  sentencepiece==0.1.99
28
  llama-cpp-python>=0.2.77
29
  huggingface-hub>=0.23.0
 
12
  # --- Rate Limiting ---
13
  slowapi>=0.1.9
14
 
15
+ # --- AI & Vision (CPU-only TensorFlow saves ~500MB vs full tensorflow) ---
16
  numpy<2.0
17
+ opencv-python-headless
 
18
  tensorflow-cpu
19
  pandas
20
  pillow
21
  gdown
22
 
23
+ # --- NLP (PyTorch CPU-only via --index-url, see Dockerfile) ---
24
  transformers>=4.40.0
 
25
  sentencepiece==0.1.99
26
  llama-cpp-python>=0.2.77
27
  huggingface-hub>=0.23.0