ezAhmed commited on
Commit
ad8b011
·
verified ·
1 Parent(s): 16f5a6f

Upload 5 files

Browse files
Files changed (3) hide show
  1. app.py +36 -11
  2. gerd_light_vit.ipynb +0 -0
  3. requirements.txt +5 -0
app.py CHANGED
@@ -1,22 +1,41 @@
1
  import io
2
- from skimage.segmentation import mark_boundaries
3
- from lime import lime_image
4
- import shap
5
  import cv2
6
- from PIL import Image
7
- from tensorflow.keras import layers as L, models
8
- import tensorflow as tf
9
- import numpy as np
10
- import gradio as gr
11
- import os
12
  import matplotlib.pyplot as plt
13
  import matplotlib
14
- matplotlib.use('Agg') # Use non-interactive backend
15
-
 
 
 
 
16
  # Disable Gradio queue for direct REST API access - MUST be before gradio import
17
  os.environ["GRADIO_QUEUE"] = "false"
18
  os.environ["HF_HUB_DISABLE_GRADIO_QUEUE"] = "1"
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # -----------------------------
22
  # Model Architecture Components
@@ -297,6 +316,9 @@ def generate_shap(image):
297
  """
298
  Generate SHAP explanation visualization.
299
  """
 
 
 
300
  if model is None or image is None:
301
  return None, "Model not loaded or no image provided"
302
 
@@ -363,6 +385,9 @@ def generate_lime(image):
363
  """
364
  Generate LIME explanation visualization.
365
  """
 
 
 
366
  if model is None or image is None:
367
  return None, None, "Model not loaded or no image provided"
368
 
 
1
  import io
 
 
 
2
  import cv2
 
 
 
 
 
 
3
  import matplotlib.pyplot as plt
4
  import matplotlib
5
+ import gradio as gr
6
+ import numpy as np
7
+ import tensorflow as tf
8
+ from tensorflow.keras import layers as L, models
9
+ from PIL import Image
10
+ import os
11
  # Disable Gradio queue for direct REST API access - MUST be before gradio import
12
  os.environ["GRADIO_QUEUE"] = "false"
13
  os.environ["HF_HUB_DISABLE_GRADIO_QUEUE"] = "1"
14
 
15
+ matplotlib.use('Agg') # Use non-interactive backend
16
+
17
+ # Import XAI libraries with error handling
18
+ try:
19
+ import shap
20
+ SHAP_AVAILABLE = True
21
+ except ImportError:
22
+ SHAP_AVAILABLE = False
23
+ print("Warning: SHAP not available")
24
+
25
+ try:
26
+ from lime import lime_image
27
+ LIME_AVAILABLE = True
28
+ except ImportError:
29
+ LIME_AVAILABLE = False
30
+ print("Warning: LIME not available")
31
+
32
+ try:
33
+ from skimage.segmentation import mark_boundaries
34
+ SKIMAGE_AVAILABLE = True
35
+ except ImportError:
36
+ SKIMAGE_AVAILABLE = False
37
+ print("Warning: scikit-image not available")
38
+
39
 
40
  # -----------------------------
41
  # Model Architecture Components
 
316
  """
317
  Generate SHAP explanation visualization.
318
  """
319
+ if not SHAP_AVAILABLE:
320
+ return None, "SHAP library not available. Please install shap package."
321
+
322
  if model is None or image is None:
323
  return None, "Model not loaded or no image provided"
324
 
 
385
  """
386
  Generate LIME explanation visualization.
387
  """
388
+ if not LIME_AVAILABLE or not SKIMAGE_AVAILABLE:
389
+ return None, None, "LIME or scikit-image library not available. Please install lime and scikit-image packages."
390
+
391
  if model is None or image is None:
392
  return None, None, "Model not loaded or no image provided"
393
 
gerd_light_vit.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -3,3 +3,8 @@ tensorflow>=2.13.0
3
  numpy>=1.24.0
4
  pillow>=10.0.0
5
  huggingface_hub==0.17.3
 
 
 
 
 
 
3
  numpy>=1.24.0
4
  pillow>=10.0.0
5
  huggingface_hub==0.17.3
6
+ matplotlib>=3.7.0
7
+ opencv-python-headless>=4.8.0
8
+ scikit-image>=0.21.0
9
+ shap>=0.43.0
10
+ lime>=0.2.0.1