fffiloni commited on
Commit
aeb7d74
1 Parent(s): fb5d273

adjust UI behavior on dimensions changes by user

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -159,7 +159,7 @@ def clear_result():
159
  return gr.update(value=None)
160
 
161
 
162
- def preload_presets(target_ratio):
163
  """Updates the width and height sliders based on the selected aspect ratio."""
164
  if target_ratio == "9:16":
165
  changed_width = 720
@@ -170,7 +170,7 @@ def preload_presets(target_ratio):
170
  changed_height = 720
171
  return changed_width, changed_height, gr.update(open=False)
172
  elif target_ratio == "Custom":
173
- return 720, 1280, gr.update(open=True)
174
 
175
  def select_the_right_preset(user_width, user_height):
176
  if user_width == 720 and user_height == 1280:
@@ -285,7 +285,7 @@ with gr.Blocks(css=css) as demo:
285
 
286
  target_ratio.change(
287
  fn=preload_presets,
288
- inputs=[target_ratio],
289
  outputs=[width_slider, height_slider, settings_panel],
290
  queue=False
291
  )
@@ -297,6 +297,13 @@ with gr.Blocks(css=css) as demo:
297
  queue = False
298
  )
299
 
 
 
 
 
 
 
 
300
  run_button.click(
301
  fn=clear_result,
302
  inputs=None,
 
159
  return gr.update(value=None)
160
 
161
 
162
+ def preload_presets(target_ratio, ui_width, ui_height):
163
  """Updates the width and height sliders based on the selected aspect ratio."""
164
  if target_ratio == "9:16":
165
  changed_width = 720
 
170
  changed_height = 720
171
  return changed_width, changed_height, gr.update(open=False)
172
  elif target_ratio == "Custom":
173
+ return ui_width, ui_height, gr.update(open=True)
174
 
175
  def select_the_right_preset(user_width, user_height):
176
  if user_width == 720 and user_height == 1280:
 
285
 
286
  target_ratio.change(
287
  fn=preload_presets,
288
+ inputs=[target_ratio, width_slider, height_slider],
289
  outputs=[width_slider, height_slider, settings_panel],
290
  queue=False
291
  )
 
297
  queue = False
298
  )
299
 
300
+ height_slider.change(
301
+ fn = select_the_right_preset,
302
+ inputs = [width_slider, height_slider],
303
+ outputs = [target_ratio],
304
+ queue = False
305
+ )
306
+
307
  run_button.click(
308
  fn=clear_result,
309
  inputs=None,