BhumikaMak commited on
Commit
589c79e
·
1 Parent(s): 872c6af

Fix: sample option selection

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -28,37 +28,36 @@ sample_images = [
28
  os.path.join(os.getcwd(), "data/xai/sample2.jpg")
29
  ]
30
 
31
- interface = gr.Interface(
32
- fn=process_image,
33
- inputs=[
34
- gr.Radio(
35
- label="Select Sample Image or Upload Image",
36
- choices=["None"] + sample_images, # Add 'None' option for uploading image
37
- value="None", # Default option is 'None'
38
- type="value", # We pass the file path or 'None' here
39
- ),
40
- gr.Image(
41
- label="Upload Image",
42
- type="pil", # Type 'pil' to work with PIL images
43
- visible=False # Initially hidden, will only be visible if 'None' is selected
44
- ),
45
- gr.CheckboxGroup(
46
- choices=["yolov5", "yolov8s"],
47
- value=["yolov5"], # Default model selected
48
- label="Select Model(s)",
49
- type="value", # Ensure the value is passed as a list of selected models
50
- ),
51
- ],
52
- outputs=gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500),
53
- title="Explainable AI for YOLO Models",
54
- description="Select a sample image or upload your own image and choose a model to visualize YOLO object detection with Grad-CAM.",
55
- examples=sample_images, # Example images to display
56
- live=True,
57
- )
 
58
 
59
- # Override the input image function to provide fallback
60
- interface.inputs[0].update(value=None)
61
 
62
 
63
  if __name__ == "__main__":
64
- interface.launch()
 
28
  os.path.join(os.getcwd(), "data/xai/sample2.jpg")
29
  ]
30
 
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("### Image Upload and Selection Interface")
33
+
34
+ # Checkbox for selecting mode
35
+ mode_checkbox = gr.Checkbox(label="Select Mode", value=False)
36
+
37
+ # Image input for uploading or selecting sample images
38
+ image_input = gr.Image(type="filepath", label="Upload or Select an Image", tool="editor")
39
+
40
+ # Dropdown for selecting sample images
41
+ sample_selector = gr.Dropdown(choices=sample_images, label="Or select a sample image", multiselect=False)
42
+
43
+ # Combine the image input and sample selector
44
+ def combine_inputs(uploaded_image, selected_sample):
45
+ return uploaded_image if uploaded_image else selected_sample
46
+
47
+ combined_image = gr.Button("Combine Inputs")
48
+
49
+ # Output display
50
+ output_text = gr.Textbox(label="Output")
51
+
52
+ # Define actions on button click
53
+ combined_image.click(
54
+ lambda img_path: process_image(img_path, mode_checkbox.value),
55
+ inputs=[image_input, sample_selector],
56
+ outputs=output_text
57
+ )
58
+
59
 
 
 
60
 
61
 
62
  if __name__ == "__main__":
63
+ demo.launch()