evalstate HF Staff commited on
Commit
d952837
·
verified ·
1 Parent(s): 089046e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -123
app.py CHANGED
@@ -332,73 +332,73 @@ css = '''#col-container { max-width: 800px; margin: 0 auto; }
332
  #examples{max-width: 800px; margin: 0 auto; }'''
333
 
334
 
335
- def reset_all(api_name=False) -> list:
336
- """
337
- Reset all camera control knobs and flags to their default values.
338
-
339
- This is used by the "Reset" button to set:
340
- - rotate_deg = 0
341
- - move_forward = 0
342
- - vertical_tilt = 0
343
- - wideangle = False
344
- - is_reset = True
345
-
346
- Returns:
347
- list:
348
- A list of values matching the order of the reset outputs:
349
- [rotate_deg, move_forward, vertical_tilt, wideangle, is_reset, True]
350
- """
351
- return [0, 0, 0, 0, False, True]
352
-
353
-
354
- def end_reset(api,api_name=False) -> bool:
355
- """
356
- Mark the end of a reset cycle.
357
-
358
- This helper is chained after `reset_all` to set the internal
359
- `is_reset` flag back to False, so that live inference can resume.
360
-
361
- Returns:
362
- bool:
363
- Always returns False.
364
- """
365
- return False
366
-
367
-
368
- def update_dimensions_on_upload(
369
- image: Optional[Image.Image],api_name=False
370
- ) -> Tuple[int, int]:
371
- """
372
- Compute recommended (width, height) for the output resolution when an
373
- image is uploaded while preserveing the aspect ratio.
374
-
375
- Args:
376
- image (PIL.Image.Image | None):
377
- The uploaded image. If `None`, defaults to (1024, 1024).
378
-
379
- Returns:
380
- Tuple[int, int]:
381
- The new (width, height).
382
- """
383
- if image is None:
384
- return 1024, 1024
385
-
386
- original_width, original_height = image.size
387
-
388
- if original_width > original_height:
389
- new_width = 1024
390
- aspect_ratio = original_height / original_width
391
- new_height = int(new_width * aspect_ratio)
392
- else:
393
- new_height = 1024
394
- aspect_ratio = original_width / original_height
395
- new_width = int(new_height * aspect_ratio)
396
-
397
- # Ensure dimensions are multiples of 8
398
- new_width = (new_width // 8) * 8
399
- new_height = (new_height // 8) * 8
400
-
401
- return new_width, new_height
402
 
403
 
404
  with gr.Blocks() as demo:
@@ -506,13 +506,13 @@ with gr.Blocks() as demo:
506
  ]
507
  outputs = [result, seed, prompt_preview]
508
 
509
- # Reset behavior
510
- reset_btn.click(
511
- fn=reset_all,
512
- inputs=None,
513
- outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
514
- queue=False
515
- ).then(fn=end_reset, inputs=None, outputs=[is_reset], queue=False)
516
 
517
  # Manual generation with video button visibility control
518
  # def infer_and_show_video_button(*args: Any):
@@ -575,56 +575,56 @@ with gr.Blocks() as demo:
575
  )
576
 
577
  # Image upload triggers dimension update and control reset
578
- image.upload(
579
- fn=update_dimensions_on_upload,
580
- inputs=[image],
581
- outputs=[width, height]
582
- ).then(
583
- fn=reset_all,
584
- inputs=None,
585
- outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
586
- queue=False
587
- ).then(
588
- fn=end_reset,
589
- inputs=None,
590
- outputs=[is_reset],
591
- queue=False
592
- )
593
-
594
- # Live updates
595
- def maybe_infer(
596
- is_reset: bool,
597
- progress: gr.Progress = gr.Progress(track_tqdm=True),
598
- api_name=False,
599
- *args: Any
600
- ):
601
- if is_reset:
602
- return gr.update(), gr.update(), gr.update(), gr.update()
603
- else:
604
- result_img, result_seed, result_prompt = infer_camera_edit(*args)
605
- # Show video button if we have both input and output
606
- show_button = args[0] is not None and result_img is not None
607
- return result_img, result_seed, result_prompt, gr.update(visible=show_button)
608
-
609
- control_inputs = [
610
- image, rotate_deg, move_forward,
611
- vertical_tilt, wideangle,
612
- seed, randomize_seed, true_guidance_scale, num_inference_steps, height, width, prev_output
613
- ]
614
- control_inputs_with_flag = [is_reset] + control_inputs
615
-
616
- for control in [rotate_deg, move_forward, vertical_tilt]:
617
- control.release(
618
- fn=maybe_infer,
619
- inputs=control_inputs_with_flag,
620
- outputs=outputs + [create_video_button]
621
- )
622
 
623
- wideangle.input(
624
- fn=maybe_infer,
625
- inputs=control_inputs_with_flag,
626
- outputs=outputs + [create_video_button]
627
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
628
 
629
  # run_event.then(lambda img, *_: img, inputs=[result], outputs=[prev_output])
630
 
 
332
  #examples{max-width: 800px; margin: 0 auto; }'''
333
 
334
 
335
+ # def reset_all(api_name=False) -> list:
336
+ # """
337
+ # Reset all camera control knobs and flags to their default values.
338
+
339
+ # This is used by the "Reset" button to set:
340
+ # - rotate_deg = 0
341
+ # - move_forward = 0
342
+ # - vertical_tilt = 0
343
+ # - wideangle = False
344
+ # - is_reset = True
345
+
346
+ # Returns:
347
+ # list:
348
+ # A list of values matching the order of the reset outputs:
349
+ # [rotate_deg, move_forward, vertical_tilt, wideangle, is_reset, True]
350
+ # """
351
+ # return [0, 0, 0, 0, False, True]
352
+
353
+
354
+ # def end_reset(api,api_name=False) -> bool:
355
+ # """
356
+ # Mark the end of a reset cycle.
357
+
358
+ # This helper is chained after `reset_all` to set the internal
359
+ # `is_reset` flag back to False, so that live inference can resume.
360
+
361
+ # Returns:
362
+ # bool:
363
+ # Always returns False.
364
+ # """
365
+ # return False
366
+
367
+
368
+ # def update_dimensions_on_upload(
369
+ # image: Optional[Image.Image],api_name=False
370
+ # ) -> Tuple[int, int]:
371
+ # """
372
+ # Compute recommended (width, height) for the output resolution when an
373
+ # image is uploaded while preserveing the aspect ratio.
374
+
375
+ # Args:
376
+ # image (PIL.Image.Image | None):
377
+ # The uploaded image. If `None`, defaults to (1024, 1024).
378
+
379
+ # Returns:
380
+ # Tuple[int, int]:
381
+ # The new (width, height).
382
+ # """
383
+ # if image is None:
384
+ # return 1024, 1024
385
+
386
+ # original_width, original_height = image.size
387
+
388
+ # if original_width > original_height:
389
+ # new_width = 1024
390
+ # aspect_ratio = original_height / original_width
391
+ # new_height = int(new_width * aspect_ratio)
392
+ # else:
393
+ # new_height = 1024
394
+ # aspect_ratio = original_width / original_height
395
+ # new_width = int(new_height * aspect_ratio)
396
+
397
+ # # Ensure dimensions are multiples of 8
398
+ # new_width = (new_width // 8) * 8
399
+ # new_height = (new_height // 8) * 8
400
+
401
+ # return new_width, new_height
402
 
403
 
404
  with gr.Blocks() as demo:
 
506
  ]
507
  outputs = [result, seed, prompt_preview]
508
 
509
+ # # Reset behavior
510
+ # reset_btn.click(
511
+ # fn=reset_all,
512
+ # inputs=None,
513
+ # outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
514
+ # queue=False
515
+ # ).then(fn=end_reset, inputs=None, outputs=[is_reset], queue=False)
516
 
517
  # Manual generation with video button visibility control
518
  # def infer_and_show_video_button(*args: Any):
 
575
  )
576
 
577
  # Image upload triggers dimension update and control reset
578
+ # image.upload(
579
+ # fn=update_dimensions_on_upload,
580
+ # inputs=[image],
581
+ # outputs=[width, height]
582
+ # ).then(
583
+ # fn=reset_all,
584
+ # inputs=None,
585
+ # outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
586
+ # queue=False
587
+ # ).then(
588
+ # fn=end_reset,
589
+ # inputs=None,
590
+ # outputs=[is_reset],
591
+ # queue=False
592
+ # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
 
594
+ # # Live updates
595
+ # def maybe_infer(
596
+ # is_reset: bool,
597
+ # progress: gr.Progress = gr.Progress(track_tqdm=True),
598
+ # api_name=False,
599
+ # *args: Any
600
+ # ):
601
+ # if is_reset:
602
+ # return gr.update(), gr.update(), gr.update(), gr.update()
603
+ # else:
604
+ # result_img, result_seed, result_prompt = infer_camera_edit(*args)
605
+ # # Show video button if we have both input and output
606
+ # show_button = args[0] is not None and result_img is not None
607
+ # return result_img, result_seed, result_prompt, gr.update(visible=show_button)
608
+
609
+ # control_inputs = [
610
+ # image, rotate_deg, move_forward,
611
+ # vertical_tilt, wideangle,
612
+ # seed, randomize_seed, true_guidance_scale, num_inference_steps, height, width, prev_output
613
+ # ]
614
+ # control_inputs_with_flag = [is_reset] + control_inputs
615
+
616
+ # for control in [rotate_deg, move_forward, vertical_tilt]:
617
+ # control.release(
618
+ # fn=maybe_infer,
619
+ # inputs=control_inputs_with_flag,
620
+ # outputs=outputs + [create_video_button]
621
+ # )
622
+
623
+ # wideangle.input(
624
+ # fn=maybe_infer,
625
+ # inputs=control_inputs_with_flag,
626
+ # outputs=outputs + [create_video_button]
627
+ # )
628
 
629
  # run_event.then(lambda img, *_: img, inputs=[result], outputs=[prev_output])
630