Spaces:
Sleeping
Sleeping
Commit
·
4a826f9
1
Parent(s):
1104379
Fix: interface layout
Browse files
app.py
CHANGED
@@ -94,26 +94,39 @@ with gr.Blocks() as interface:
|
|
94 |
type="value",
|
95 |
value="Sample 1", # Set default selection
|
96 |
)
|
|
|
97 |
# Display the selected or uploaded image
|
98 |
image_display = gr.Image(
|
99 |
value=load_sample_image("Sample 1"), # Load default sample image
|
100 |
label="Selected/Uploaded Image",
|
101 |
)
|
102 |
|
103 |
-
#
|
104 |
-
|
|
|
|
|
105 |
|
106 |
-
#
|
107 |
sample_selection.change(
|
108 |
fn=load_sample_image,
|
109 |
inputs=sample_selection,
|
110 |
outputs=image_display,
|
111 |
)
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
fn=lambda
|
116 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
outputs=image_display,
|
118 |
)
|
119 |
|
|
|
94 |
type="value",
|
95 |
value="Sample 1", # Set default selection
|
96 |
)
|
97 |
+
|
98 |
# Display the selected or uploaded image
|
99 |
image_display = gr.Image(
|
100 |
value=load_sample_image("Sample 1"), # Load default sample image
|
101 |
label="Selected/Uploaded Image",
|
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 |
|