Spaces:
Sleeping
Sleeping
Commit
·
90ff42e
1
Parent(s):
740153b
Fix: model dependency + default sample
Browse files
app.py
CHANGED
@@ -26,18 +26,13 @@ sample_images = {
|
|
26 |
"Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
|
27 |
"Sample 2": os.path.join(os.getcwd(), "data/xai/sample2.jpg"),
|
28 |
}
|
29 |
-
|
30 |
def load_sample_image(sample_name):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
except Exception as e:
|
35 |
-
print(f"Error loading image: {e}")
|
36 |
-
return None
|
37 |
return None
|
38 |
-
|
39 |
-
default_sample_image = load_sample_image("Sample 1")
|
40 |
|
|
|
41 |
with gr.Blocks() as interface:
|
42 |
gr.Markdown("# XAI: Upload an image to visualize object detection of your models..")
|
43 |
gr.Markdown("Upload an image or select a sample image to visualize object detection.")
|
@@ -49,7 +44,7 @@ with gr.Blocks() as interface:
|
|
49 |
label="Select a Sample Image",
|
50 |
type="value",
|
51 |
)
|
52 |
-
sample_display = gr.Image(label="Sample Image Preview",
|
53 |
sample_selection.change(fn=load_sample_image, inputs=sample_selection, outputs=sample_display)
|
54 |
|
55 |
selected_models = gr.CheckboxGroup(
|
@@ -62,7 +57,7 @@ with gr.Blocks() as interface:
|
|
62 |
|
63 |
gr.Button("Run").click(
|
64 |
fn=process_image,
|
65 |
-
inputs=[uploaded_image, selected_models],
|
66 |
outputs=result_gallery,
|
67 |
)
|
68 |
|
|
|
26 |
"Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
|
27 |
"Sample 2": os.path.join(os.getcwd(), "data/xai/sample2.jpg"),
|
28 |
}
|
|
|
29 |
def load_sample_image(sample_name):
|
30 |
+
image_path = sample_images.get(sample_name)
|
31 |
+
if image_path and os.path.exists(image_path):
|
32 |
+
return Image.open(image_path)
|
|
|
|
|
|
|
33 |
return None
|
|
|
|
|
34 |
|
35 |
+
default_sample_image = load_sample_image("Sample 1")
|
36 |
with gr.Blocks() as interface:
|
37 |
gr.Markdown("# XAI: Upload an image to visualize object detection of your models..")
|
38 |
gr.Markdown("Upload an image or select a sample image to visualize object detection.")
|
|
|
44 |
label="Select a Sample Image",
|
45 |
type="value",
|
46 |
)
|
47 |
+
sample_display = gr.Image(label="Sample Image Preview", value=default_sample_image)
|
48 |
sample_selection.change(fn=load_sample_image, inputs=sample_selection, outputs=sample_display)
|
49 |
|
50 |
selected_models = gr.CheckboxGroup(
|
|
|
57 |
|
58 |
gr.Button("Run").click(
|
59 |
fn=process_image,
|
60 |
+
inputs=[uploaded_image, selected_models, sample_display],
|
61 |
outputs=result_gallery,
|
62 |
)
|
63 |
|