Fabrice-TIERCELIN commited on
Commit
d724bbb
·
verified ·
1 Parent(s): d7a1a43

Compute size

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -446,11 +446,6 @@ with gr.Blocks(css=css) as demo:
446
  width_input_debug_value = value
447
  return []
448
 
449
- def image_i2v_debug_upload(image_filepath):
450
- global image_i2v_debug_value
451
- image_i2v_debug_value = image_filepath
452
- return []
453
-
454
  def i2v_prompt_debug_change(prompt):
455
  global i2v_prompt_debug_value
456
  i2v_prompt_debug_value = prompt
@@ -471,6 +466,21 @@ with gr.Blocks(css=css) as demo:
471
  # Keep current slider values on error
472
  return gr.update(value=current_h), gr.update(value=current_w)
473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  def handle_video_upload_for_dims(video_filepath, current_h, current_w):
475
  if not video_filepath: # Video cleared or no video initially
476
  return gr.update(value=current_h), gr.update(value=current_w)
@@ -508,6 +518,12 @@ with gr.Blocks(css=css) as demo:
508
  return gr.update(value=current_h), gr.update(value=current_w)
509
 
510
 
 
 
 
 
 
 
511
  image_i2v.upload(
512
  fn=handle_image_upload_for_dims,
513
  inputs=[image_i2v, height_input, width_input],
@@ -518,11 +534,6 @@ with gr.Blocks(css=css) as demo:
518
  inputs=[video_v2v, height_input, width_input],
519
  outputs=[height_input, width_input]
520
  )
521
- image_i2v_debug.upload(
522
- fn=image_i2v_debug_upload,
523
- inputs=[image_i2v_debug],
524
- outputs=[]
525
- )
526
  i2v_prompt_debug.change(
527
  fn=i2v_prompt_debug_change,
528
  inputs=[image_i2v_debug],
 
446
  width_input_debug_value = value
447
  return []
448
 
 
 
 
 
 
449
  def i2v_prompt_debug_change(prompt):
450
  global i2v_prompt_debug_value
451
  i2v_prompt_debug_value = prompt
 
466
  # Keep current slider values on error
467
  return gr.update(value=current_h), gr.update(value=current_w)
468
 
469
+ def handle_image_debug_upload_for_dims(image_filepath, current_h, current_w):
470
+ global image_i2v_debug_value
471
+ image_i2v_debug_value = image_filepath
472
+ if not image_filepath: # Image cleared or no image initially
473
+ # Keep current slider values if image is cleared or no input
474
+ return gr.update(value=current_h), gr.update(value=current_w)
475
+ try:
476
+ img = Image.open(image_filepath)
477
+ orig_w, orig_h = img.size
478
+ new_h, new_w = calculate_new_dimensions(orig_w, orig_h)
479
+ return gr.update(value=new_h), gr.update(value=new_w)
480
+ except Exception as e:
481
+ # Keep current slider values on error
482
+ return gr.update(value=current_h), gr.update(value=current_w)
483
+
484
  def handle_video_upload_for_dims(video_filepath, current_h, current_w):
485
  if not video_filepath: # Video cleared or no video initially
486
  return gr.update(value=current_h), gr.update(value=current_w)
 
518
  return gr.update(value=current_h), gr.update(value=current_w)
519
 
520
 
521
+ image_i2v_debug.upload(
522
+ fn=handle_image_debug_upload_for_dims,
523
+ inputs=[image_i2v_debug, height_input_debug, width_input_debug],
524
+ outputs=[height_input_debug, width_input_debug]
525
+ )
526
+
527
  image_i2v.upload(
528
  fn=handle_image_upload_for_dims,
529
  inputs=[image_i2v, height_input, width_input],
 
534
  inputs=[video_v2v, height_input, width_input],
535
  outputs=[height_input, width_input]
536
  )
 
 
 
 
 
537
  i2v_prompt_debug.change(
538
  fn=i2v_prompt_debug_change,
539
  inputs=[image_i2v_debug],