vivek12coder commited on
Commit
056b79f
·
1 Parent(s): 331e250

Fix headless deployment: set matplotlib Agg backend and simplify Docker deps

Browse files
Files changed (2) hide show
  1. Dockerfile +6 -6
  2. app.py +5 -0
Dockerfile CHANGED
@@ -10,17 +10,17 @@ WORKDIR /app
10
  ENV PYTHONPATH="/app"
11
  ENV PYTHONDONTWRITEBYTECODE=1
12
  ENV PYTHONUNBUFFERED=1
 
 
13
 
14
- # Install system dependencies
15
  RUN apt-get update && apt-get install -y \
16
  libglib2.0-0 \
17
  libsm6 \
18
  libxext6 \
19
- libxrender-dev \
20
  libgomp1 \
21
- libgtk-3-0 \
22
- libgl1-mesa-dri \
23
- libglu1-mesa \
24
  curl \
25
  && rm -rf /var/lib/apt/lists/*
26
 
@@ -39,7 +39,7 @@ COPY knowledge_base/ ./knowledge_base/
39
  COPY test_leaf_sample.jpg .
40
 
41
  # Create necessary directories
42
- RUN mkdir -p outputs temp
43
 
44
  # Expose the port FastAPI runs on
45
  EXPOSE 7860
 
10
  ENV PYTHONPATH="/app"
11
  ENV PYTHONDONTWRITEBYTECODE=1
12
  ENV PYTHONUNBUFFERED=1
13
+ ENV MPLCONFIGDIR=/tmp/matplotlib
14
+ ENV QT_QPA_PLATFORM=offscreen
15
 
16
+ # Install minimal system dependencies for headless OpenCV
17
  RUN apt-get update && apt-get install -y \
18
  libglib2.0-0 \
19
  libsm6 \
20
  libxext6 \
21
+ libxrender1 \
22
  libgomp1 \
23
+ libglib2.0-0 \
 
 
24
  curl \
25
  && rm -rf /var/lib/apt/lists/*
26
 
 
39
  COPY test_leaf_sample.jpg .
40
 
41
  # Create necessary directories
42
+ RUN mkdir -p outputs temp /tmp/matplotlib
43
 
44
  # Expose the port FastAPI runs on
45
  EXPOSE 7860
app.py CHANGED
@@ -20,7 +20,12 @@ import uuid
20
  import tempfile
21
  import asyncio
22
  from pathlib import Path
 
 
 
 
23
  import matplotlib.pyplot as plt
 
24
  import cv2
25
  import base64
26
  from datetime import datetime
 
20
  import tempfile
21
  import asyncio
22
  from pathlib import Path
23
+
24
+ # Set matplotlib backend before importing pyplot (fixes headless environment)
25
+ import matplotlib
26
+ matplotlib.use('Agg')
27
  import matplotlib.pyplot as plt
28
+
29
  import cv2
30
  import base64
31
  from datetime import datetime