priyadip commited on
Commit
896d66f
Β·
verified Β·
1 Parent(s): 332f1d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -5,6 +5,12 @@ import matplotlib.pyplot as plt
5
  import warnings
6
  warnings.filterwarnings("ignore")
7
 
 
 
 
 
 
 
8
  # ── Standard imports ───────────────────────────────────────────────────
9
  import gradio as gr
10
  import numpy as np
@@ -12,7 +18,7 @@ import cv2
12
  import io
13
  from PIL import Image
14
 
15
- # ── Pipeline imports (TkAgg call inside module is silently ignored) ────
16
  from graph_cut_segmentation import (
17
  iterative_graph_cut,
18
  refine_segmentation,
@@ -23,6 +29,9 @@ from graph_cut_segmentation import (
23
  generate_auto_annotations,
24
  )
25
 
 
 
 
26
 
27
  # ══════════════════════════════════════════════════════════════════════
28
  # Helpers
 
5
  import warnings
6
  warnings.filterwarnings("ignore")
7
 
8
+ # Monkey-patch matplotlib.use so that graph_cut_segmentation.py's
9
+ # module-level `matplotlib.use("TkAgg")` call becomes a no-op on import.
10
+ # We cannot modify that file, so we intercept here instead.
11
+ _real_use = matplotlib.use
12
+ matplotlib.use = lambda *a, **kw: None
13
+
14
  # ── Standard imports ───────────────────────────────────────────────────
15
  import gradio as gr
16
  import numpy as np
 
18
  import io
19
  from PIL import Image
20
 
21
+ # ── Pipeline imports (TkAgg call inside module is now intercepted) ─────
22
  from graph_cut_segmentation import (
23
  iterative_graph_cut,
24
  refine_segmentation,
 
29
  generate_auto_annotations,
30
  )
31
 
32
+ # Restore real matplotlib.use now that the problematic import is done
33
+ matplotlib.use = _real_use
34
+
35
 
36
  # ══════════════════════════════════════════════════════════════════════
37
  # Helpers