Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -654,33 +654,16 @@ def calculate_frames(duration: float, frame_rate: float = DEFAULT_FRAME_RATE) ->
|
|
| 654 |
return min(frames, MAX_FRAMES)
|
| 655 |
|
| 656 |
|
| 657 |
-
def
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
return
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
def detect_aspect_ratio(image) -> str:
|
| 666 |
-
if image is None:
|
| 667 |
-
return "16:9"
|
| 668 |
-
if hasattr(image, "size"):
|
| 669 |
-
w, h = image.size
|
| 670 |
-
elif hasattr(image, "shape"):
|
| 671 |
-
h, w = image.shape[:2]
|
| 672 |
-
else:
|
| 673 |
-
return "16:9"
|
| 674 |
-
ratio = w / h
|
| 675 |
-
candidates = {"16:9": 16/9, "9:16": 9/16, "1:1": 1.0}
|
| 676 |
-
return min(candidates, key=lambda k: abs(ratio - candidates[k]))
|
| 677 |
|
| 678 |
|
| 679 |
-
def
|
| 680 |
-
|
| 681 |
-
ref_image = first_image
|
| 682 |
-
if ref_image is None:
|
| 683 |
-
return gr.update(), gr.update()
|
| 684 |
aspect = detect_aspect_ratio(ref_image)
|
| 685 |
tier = "high" if high_res else "low"
|
| 686 |
w, h = RESOLUTIONS[tier][aspect]
|
|
|
|
| 654 |
return min(frames, MAX_FRAMES)
|
| 655 |
|
| 656 |
|
| 657 |
+
def on_image_upload(first_image, last_image, high_res):
|
| 658 |
+
ref_image = first_image if first_image is not None else last_image
|
| 659 |
+
aspect = detect_aspect_ratio(ref_image)
|
| 660 |
+
tier = "high" if high_res else "low"
|
| 661 |
+
w, h = RESOLUTIONS[tier][aspect]
|
| 662 |
+
return gr.update(value=w), gr.update(value=h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
|
| 664 |
|
| 665 |
+
def on_highres_toggle(first_image, last_image, high_res):
|
| 666 |
+
ref_image = first_image if first_image is not None else last_image
|
|
|
|
|
|
|
|
|
|
| 667 |
aspect = detect_aspect_ratio(ref_image)
|
| 668 |
tier = "high" if high_res else "low"
|
| 669 |
w, h = RESOLUTIONS[tier][aspect]
|