Spaces:
Sleeping
Sleeping
Commit
·
589c79e
1
Parent(s):
872c6af
Fix: sample option selection
Browse files
app.py
CHANGED
@@ -28,37 +28,36 @@ sample_images = [
|
|
28 |
os.path.join(os.getcwd(), "data/xai/sample2.jpg")
|
29 |
]
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
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 |
-
|
|
|
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()
|