Ash2505 commited on
Commit
e7b1b3f
·
verified ·
1 Parent(s): 6ca0343

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -57
app.py CHANGED
@@ -154,75 +154,24 @@ def update_preset(preset: str):
154
  image = Image.open(BytesIO(response.content)).convert("RGB")
155
  return image, preset_info["fg_threshold"], preset_info["mg_threshold"]
156
 
157
- # -----------------------------
158
- # Gradio Interface Setup
159
- # -----------------------------
160
- title = "Blur Effects: Gaussian & Depth-Based Lens Blur with Adjustable Depth Thresholds"
161
- description = (
162
- "Choose a preset image or upload your own image to apply two distinct effects:\n\n"
163
- "1. A segmentation-based Gaussian blur that blurs the background (using RMBG-2.0).\n"
164
- "2. A depth-based lens blur effect that simulates realistic lens blur based on depth (using DepthPro).\n\n"
165
- "The preset selection will automatically set the image and its default foreground/middleground depth thresholds."
166
- )
167
-
168
- # A radio to select between two preset images
169
- preset_radio = gr.Radio(
170
- choices=["Preset 1", "Preset 2"],
171
- label="Select Preset Image",
172
- value="Preset 1"
173
- )
174
-
175
- # An image component that will be updated based on the preset selection
176
- preset_img = gr.Image(type="pil", label="Input Image")
177
 
178
- # Slider components for depth thresholds (will be updated when a preset is selected)
179
- fg_slider = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.33, label="Foreground Depth Threshold")
180
- mg_slider = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.66, label="Middleground Depth Threshold")
181
 
182
- # When the preset is changed, update the image and sliders with corresponding defaults.
183
- preset_radio.change(fn=update_preset, inputs=preset_radio, outputs=[preset_img, fg_slider, mg_slider])
184
-
185
- # Build the Gradio interface using the updated components.
186
  demo = gr.Interface(
187
  fn=process_image,
188
- inputs=[preset_img, fg_slider, mg_slider],
 
 
 
 
189
  outputs=[
190
  gr.Image(type="pil", label="Segmentation-Based Blur"),
191
  gr.Image(type="pil", label="Depth Map"),
192
  gr.Image(type="pil", label="Depth-Based Lens Blur")
193
  ],
194
  title=title,
195
- description=description,
196
  allow_flagging="never"
197
  )
198
 
199
  if __name__ == "__main__":
200
  demo.launch()
201
-
202
- # title = "Blur Effects: Gaussian & Depth-Based Lens Blur with Adjustable Depth Thresholds"
203
- # description = (
204
- # "Upload an image to apply two distinct effects:\n\n"
205
- # "1. A segmentation-based Gaussian blur that blurs the background (using RMBG-2.0).\n"
206
- # "2. A depth-based lens blur effect that simulates realistic lens blur based on depth (using DepthPro).\n\n"
207
- # "Use the sliders to adjust the foreground and middleground depth thresholds."
208
- # )
209
-
210
- # demo = gr.Interface(
211
- # fn=process_image,
212
- # inputs=[
213
- # gr.Image(type="pil", label="Input Image", value="https://i.ibb.co/fznz2b2b/hw3-q2.jpg"),
214
- # gr.Slider(minimum=0, maximum=1, step=0.01, value=0.33, label="Foreground Depth Threshold"),
215
- # gr.Slider(minimum=0, maximum=1, step=0.01, value=0.66, label="Middleground Depth Threshold")
216
- # ],
217
- # outputs=[
218
- # gr.Image(type="pil", label="Segmentation-Based Blur"),
219
- # gr.Image(type="pil", label="Depth Map"),
220
- # gr.Image(type="pil", label="Depth-Based Lens Blur")
221
- # ],
222
- # title=title,
223
- # description=description,
224
- # allow_flagging="never"
225
- # )
226
-
227
- # if __name__ == "__main__":
228
- # demo.launch()
 
154
  image = Image.open(BytesIO(response.content)).convert("RGB")
155
  return image, preset_info["fg_threshold"], preset_info["mg_threshold"]
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ title = "Blur Effects on Segmentation-Based Gaussian Blur & Depth-Based Lens Blur with Adjustable Depth Thresholds"
 
 
159
 
 
 
 
 
160
  demo = gr.Interface(
161
  fn=process_image,
162
+ inputs=[
163
+ gr.Image(type="pil", label="Input Image", value="https://i.ibb.co/fznz2b2b/hw3-q2.jpg"),
164
+ gr.Slider(minimum=0, maximum=1, step=0.01, value=0.33, label="Foreground Depth Threshold"),
165
+ gr.Slider(minimum=0, maximum=1, step=0.01, value=0.66, label="Middleground Depth Threshold")
166
+ ],
167
  outputs=[
168
  gr.Image(type="pil", label="Segmentation-Based Blur"),
169
  gr.Image(type="pil", label="Depth Map"),
170
  gr.Image(type="pil", label="Depth-Based Lens Blur")
171
  ],
172
  title=title,
 
173
  allow_flagging="never"
174
  )
175
 
176
  if __name__ == "__main__":
177
  demo.launch()