Spaces:
Sleeping
Sleeping
Commit
·
20ca536
1
Parent(s):
4a826f9
Fix: interface layout
Browse files
app.py
CHANGED
|
@@ -62,7 +62,7 @@ with gr.Blocks() as interface:
|
|
| 62 |
def load_sample_image(choice):
|
| 63 |
if choice in sample_images:
|
| 64 |
image_path = sample_images[choice]
|
| 65 |
-
return cv2.imread(image_path)[:, :, ::-1]
|
| 66 |
else:
|
| 67 |
raise ValueError("Invalid sample selection.")
|
| 68 |
|
|
@@ -81,71 +81,39 @@ def process_image(choice, yolo_versions=["yolov5"]):
|
|
| 81 |
result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
|
| 82 |
return result_images
|
| 83 |
|
|
|
|
|
|
|
| 84 |
with gr.Blocks() as interface:
|
| 85 |
gr.Markdown("# XAI: Visualize Object Detection of Your Models")
|
| 86 |
-
gr.Markdown("Select a sample image
|
| 87 |
-
|
| 88 |
-
with gr.Row():
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
# Buttons for each sample image to upload custom image
|
| 105 |
-
upload_button_1 = gr.File(label="Upload Image for Sample 1", file_count="single")
|
| 106 |
-
upload_button_2 = gr.File(label="Upload Image for Sample 2", file_count="single")
|
| 107 |
-
upload_button_3 = gr.File(label="Upload Image for Sample 3", file_count="single")
|
| 108 |
-
|
| 109 |
-
# When a sample is selected, update the image display accordingly
|
| 110 |
-
sample_selection.change(
|
| 111 |
-
fn=load_sample_image,
|
| 112 |
-
inputs=sample_selection,
|
| 113 |
-
outputs=image_display,
|
| 114 |
-
)
|
| 115 |
-
|
| 116 |
-
# Handle file uploads for each custom image upload button
|
| 117 |
-
upload_button_1.change(
|
| 118 |
-
fn=lambda file: cv2.imread(file.name)[:, :, ::-1] if file else None, # Read and display uploaded image
|
| 119 |
-
inputs=upload_button_1,
|
| 120 |
-
outputs=image_display,
|
| 121 |
-
)
|
| 122 |
-
upload_button_2.change(
|
| 123 |
-
fn=lambda file: cv2.imread(file.name)[:, :, ::-1] if file else None,
|
| 124 |
-
inputs=upload_button_2,
|
| 125 |
-
outputs=image_display,
|
| 126 |
-
)
|
| 127 |
-
upload_button_3.change(
|
| 128 |
-
fn=lambda file: cv2.imread(file.name)[:, :, ::-1] if file else None,
|
| 129 |
-
inputs=upload_button_3,
|
| 130 |
-
outputs=image_display,
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
# Model selection below the image options
|
| 134 |
-
selected_models = gr.CheckboxGroup(
|
| 135 |
-
choices=["yolov5", "yolov8s"],
|
| 136 |
-
value=["yolov5"],
|
| 137 |
-
label="Select Model(s)",
|
| 138 |
-
)
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
# Use the uploaded image if available, otherwise the selected sample
|
| 146 |
gr.Button("Run").click(
|
| 147 |
fn=process_image,
|
| 148 |
-
inputs=[
|
| 149 |
outputs=result_gallery,
|
| 150 |
)
|
| 151 |
|
|
|
|
| 62 |
def load_sample_image(choice):
|
| 63 |
if choice in sample_images:
|
| 64 |
image_path = sample_images[choice]
|
| 65 |
+
return cv2.imread(image_path)[:, :, ::-1]
|
| 66 |
else:
|
| 67 |
raise ValueError("Invalid sample selection.")
|
| 68 |
|
|
|
|
| 81 |
result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
|
| 82 |
return result_images
|
| 83 |
|
| 84 |
+
|
| 85 |
+
import gradio as gr
|
| 86 |
with gr.Blocks() as interface:
|
| 87 |
gr.Markdown("# XAI: Visualize Object Detection of Your Models")
|
| 88 |
+
gr.Markdown("Select a sample image to visualize object detection.")
|
| 89 |
+
default_sample = "Sample 1"
|
| 90 |
+
with gr.Row():
|
| 91 |
+
sample_selection = gr.Radio(
|
| 92 |
+
choices=list(sample_images.keys()),
|
| 93 |
+
label="Select a Sample Image",
|
| 94 |
+
type="value",
|
| 95 |
+
value=default_sample, # Set default selection
|
| 96 |
+
)
|
| 97 |
+
sample_display = gr.Image(
|
| 98 |
+
value=load_sample_image(default_sample),
|
| 99 |
+
label="Selected Sample Image",
|
| 100 |
+
)
|
| 101 |
+
sample_selection.change(
|
| 102 |
+
fn=load_sample_image,
|
| 103 |
+
inputs=sample_selection,
|
| 104 |
+
outputs=sample_display,
|
| 105 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
selected_models = gr.CheckboxGroup(
|
| 108 |
+
choices=["yolov5", "yolov8s"],
|
| 109 |
+
value=["yolov5"],
|
| 110 |
+
label="Select Model(s)",
|
| 111 |
+
)
|
| 112 |
+
result_gallery = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500)
|
| 113 |
|
|
|
|
| 114 |
gr.Button("Run").click(
|
| 115 |
fn=process_image,
|
| 116 |
+
inputs=[sample_selection, selected_models],
|
| 117 |
outputs=result_gallery,
|
| 118 |
)
|
| 119 |
|