BhumikaMak commited on
Commit
4a826f9
·
1 Parent(s): 1104379

Fix: interface layout

Browse files
Files changed (1) hide show
  1. app.py +20 -7
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
- # File upload for custom images (placed below the sample selection)
104
- uploaded_image = gr.Image(type="numpy", label="Upload an Image")
 
 
105
 
106
- # Update display when sample selection changes
107
  sample_selection.change(
108
  fn=load_sample_image,
109
  inputs=sample_selection,
110
  outputs=image_display,
111
  )
112
 
113
- # Update display when an image is uploaded
114
- uploaded_image.change(
115
- fn=lambda img: img,
116
- inputs=uploaded_image,
 
 
 
 
 
 
 
 
 
 
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