Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -438,6 +438,10 @@ _PLACEMENT_ALLOWANCE, _MARGIN = 8, 1.15
|
|
| 438 |
# The ZeroGPU per-call ceiling. A booking above it is refused with `ZeroGPU illegal duration` once the request is
|
| 439 |
# already in flight, so `generate` checks it up front and says which knob to turn instead.
|
| 440 |
_MAX_BOOKING = int(os.environ.get("H3_MAX_BOOKING", "1500"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
|
| 443 |
def get_duration(
|
|
@@ -453,9 +457,14 @@ def get_duration(
|
|
| 453 |
sharpen,
|
| 454 |
multiplier,
|
| 455 |
seed,
|
|
|
|
|
|
|
| 456 |
*a,
|
| 457 |
**k,
|
| 458 |
):
|
|
|
|
|
|
|
|
|
|
| 459 |
height, width, num_frames, steps = int(height), int(width), int(num_frames), int(steps)
|
| 460 |
multiplier = max(1, int(multiplier))
|
| 461 |
latent_frames = (num_frames - LATENTS_PER_CHUNK) // FRAMES_PER_CHUNK * LATENTS_PER_CHUNK + 2
|
|
@@ -475,7 +484,7 @@ def get_duration(
|
|
| 475 |
return max(60, int((denoise + decode + post) * _MARGIN) + _PLACEMENT_ALLOWANCE)
|
| 476 |
|
| 477 |
|
| 478 |
-
@spaces.GPU(duration=
|
| 479 |
def _generate(
|
| 480 |
prompt_embeds,
|
| 481 |
text_token_tags,
|
|
@@ -490,6 +499,7 @@ def _generate(
|
|
| 490 |
multiplier,
|
| 491 |
seed,
|
| 492 |
lora_strengths,
|
|
|
|
| 493 |
):
|
| 494 |
"""The only thing on GPU time: the denoise loop, the two decoders and the workflow's post chain.
|
| 495 |
The mp4 is muxed here rather than in the caller: a `@spaces.GPU` return crosses a process boundary by pickling,
|
|
@@ -591,6 +601,7 @@ def generate(
|
|
| 591 |
lora_e_strength=DEFAULT_LORA_E_STRENGTH,
|
| 592 |
lora_f_strength=DEFAULT_LORA_F_STRENGTH,
|
| 593 |
lora_g_strength=DEFAULT_LORA_G_STRENGTH,
|
|
|
|
| 594 |
progress=gr.Progress(track_tqdm=True),
|
| 595 |
):
|
| 596 |
"""One request through the PlagueKind graph. Every parameter but the prompt carries the default its UI
|
|
@@ -649,6 +660,7 @@ def generate(
|
|
| 649 |
multiplier,
|
| 650 |
int(seed),
|
| 651 |
lora_strengths,
|
|
|
|
| 652 |
)
|
| 653 |
# The same call `spaces` will book the worker with, so the report can show the fit against the measurement.
|
| 654 |
booked_seconds = get_duration(*call)
|
|
@@ -775,62 +787,6 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 775 |
value=DEFAULT_STEPS,
|
| 776 |
info="PlagueKind: 15-20 on the linear_quadratic grid.",
|
| 777 |
)
|
| 778 |
-
lora_1_strength = gr.Slider(
|
| 779 |
-
label="Distilled LoRA",
|
| 780 |
-
minimum=0.0,
|
| 781 |
-
maximum=2.0,
|
| 782 |
-
step=0.05,
|
| 783 |
-
value=DEFAULT_LORA_1_STRENGTH,
|
| 784 |
-
)
|
| 785 |
-
lora_a_strength = gr.Slider(
|
| 786 |
-
label="Anthro Enhancer LoRA",
|
| 787 |
-
minimum=0.0,
|
| 788 |
-
maximum=2.0,
|
| 789 |
-
step=0.05,
|
| 790 |
-
value=DEFAULT_LORA_A_STRENGTH,
|
| 791 |
-
)
|
| 792 |
-
lora_b_strength = gr.Slider(
|
| 793 |
-
label="Reasoning Enhancer LoRA",
|
| 794 |
-
minimum=0.0,
|
| 795 |
-
maximum=2.0,
|
| 796 |
-
step=0.05,
|
| 797 |
-
value=DEFAULT_LORA_B_STRENGTH,
|
| 798 |
-
)
|
| 799 |
-
lora_c_strength = gr.Slider(
|
| 800 |
-
label="HM-AIO LoRA",
|
| 801 |
-
minimum=0.0,
|
| 802 |
-
maximum=2.0,
|
| 803 |
-
step=0.05,
|
| 804 |
-
value=DEFAULT_LORA_C_STRENGTH,
|
| 805 |
-
)
|
| 806 |
-
lora_d_strength = gr.Slider(
|
| 807 |
-
label="Anthro Realism LoRA",
|
| 808 |
-
minimum=0.0,
|
| 809 |
-
maximum=2.0,
|
| 810 |
-
step=0.05,
|
| 811 |
-
value=DEFAULT_LORA_D_STRENGTH,
|
| 812 |
-
)
|
| 813 |
-
lora_e_strength = gr.Slider(
|
| 814 |
-
label="SB LoRA",
|
| 815 |
-
minimum=0.0,
|
| 816 |
-
maximum=2.0,
|
| 817 |
-
step=0.05,
|
| 818 |
-
value=DEFAULT_LORA_E_STRENGTH,
|
| 819 |
-
)
|
| 820 |
-
lora_f_strength = gr.Slider(
|
| 821 |
-
label="Moaxx LoRA",
|
| 822 |
-
minimum=0.0,
|
| 823 |
-
maximum=2.0,
|
| 824 |
-
step=0.05,
|
| 825 |
-
value=DEFAULT_LORA_F_STRENGTH,
|
| 826 |
-
)
|
| 827 |
-
lora_g_strength = gr.Slider(
|
| 828 |
-
label="Fluid Enhancer LoRA",
|
| 829 |
-
minimum=0.0,
|
| 830 |
-
maximum=2.0,
|
| 831 |
-
step=0.05,
|
| 832 |
-
value=DEFAULT_LORA_G_STRENGTH,
|
| 833 |
-
)
|
| 834 |
schedule = gr.Dropdown(
|
| 835 |
label="Sigma schedule",
|
| 836 |
choices=list(SCHEDULES),
|
|
@@ -857,10 +813,72 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 857 |
value=False,
|
| 858 |
info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
|
| 859 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 860 |
|
| 861 |
with gr.Column():
|
| 862 |
video = gr.Video(label="Video + soundtrack")
|
| 863 |
report = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 864 |
|
| 865 |
first_frame.upload(_fit_keyframe, [first_frame, canvas], [first_frame, canvas])
|
| 866 |
last_frame.upload(_fit_keyframe, [last_frame, canvas], [last_frame, canvas])
|
|
@@ -885,6 +903,7 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 885 |
lora_e_strength,
|
| 886 |
lora_f_strength,
|
| 887 |
lora_g_strength,
|
|
|
|
| 888 |
]
|
| 889 |
|
| 890 |
run.click(generate, controls, [video, report], api_name="generate")
|
|
|
|
| 438 |
# The ZeroGPU per-call ceiling. A booking above it is refused with `ZeroGPU illegal duration` once the request is
|
| 439 |
# already in flight, so `generate` checks it up front and says which knob to turn instead.
|
| 440 |
_MAX_BOOKING = int(os.environ.get("H3_MAX_BOOKING", "1500"))
|
| 441 |
+
# Free-tier testing mode: forces the main Space's booking to exactly this many seconds regardless of the actual
|
| 442 |
+
# request. Paired with the conditioner Space's own fixed 8s booking (both xlarge), for a combined 148s against
|
| 443 |
+
# the shared 150s free-tier ceiling.
|
| 444 |
+
MAXIMIZE_GPU_DURATION = int(os.environ.get("H3_MAXIMIZE_GPU_DURATION", "140"))
|
| 445 |
|
| 446 |
|
| 447 |
def get_duration(
|
|
|
|
| 457 |
sharpen,
|
| 458 |
multiplier,
|
| 459 |
seed,
|
| 460 |
+
lora_strengths,
|
| 461 |
+
maximize_gpu,
|
| 462 |
*a,
|
| 463 |
**k,
|
| 464 |
):
|
| 465 |
+
if maximize_gpu:
|
| 466 |
+
return MAXIMIZE_GPU_DURATION
|
| 467 |
+
|
| 468 |
height, width, num_frames, steps = int(height), int(width), int(num_frames), int(steps)
|
| 469 |
multiplier = max(1, int(multiplier))
|
| 470 |
latent_frames = (num_frames - LATENTS_PER_CHUNK) // FRAMES_PER_CHUNK * LATENTS_PER_CHUNK + 2
|
|
|
|
| 484 |
return max(60, int((denoise + decode + post) * _MARGIN) + _PLACEMENT_ALLOWANCE)
|
| 485 |
|
| 486 |
|
| 487 |
+
@spaces.GPU(duration=get_duration, size=GPU_SIZE)
|
| 488 |
def _generate(
|
| 489 |
prompt_embeds,
|
| 490 |
text_token_tags,
|
|
|
|
| 499 |
multiplier,
|
| 500 |
seed,
|
| 501 |
lora_strengths,
|
| 502 |
+
maximize_gpu,
|
| 503 |
):
|
| 504 |
"""The only thing on GPU time: the denoise loop, the two decoders and the workflow's post chain.
|
| 505 |
The mp4 is muxed here rather than in the caller: a `@spaces.GPU` return crosses a process boundary by pickling,
|
|
|
|
| 601 |
lora_e_strength=DEFAULT_LORA_E_STRENGTH,
|
| 602 |
lora_f_strength=DEFAULT_LORA_F_STRENGTH,
|
| 603 |
lora_g_strength=DEFAULT_LORA_G_STRENGTH,
|
| 604 |
+
maximize_gpu=False,
|
| 605 |
progress=gr.Progress(track_tqdm=True),
|
| 606 |
):
|
| 607 |
"""One request through the PlagueKind graph. Every parameter but the prompt carries the default its UI
|
|
|
|
| 660 |
multiplier,
|
| 661 |
int(seed),
|
| 662 |
lora_strengths,
|
| 663 |
+
bool(maximize_gpu),
|
| 664 |
)
|
| 665 |
# The same call `spaces` will book the worker with, so the report can show the fit against the measurement.
|
| 666 |
booked_seconds = get_duration(*call)
|
|
|
|
| 787 |
value=DEFAULT_STEPS,
|
| 788 |
info="PlagueKind: 15-20 on the linear_quadratic grid.",
|
| 789 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 790 |
schedule = gr.Dropdown(
|
| 791 |
label="Sigma schedule",
|
| 792 |
choices=list(SCHEDULES),
|
|
|
|
| 813 |
value=False,
|
| 814 |
info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
|
| 815 |
)
|
| 816 |
+
maximize_gpu = gr.Checkbox(
|
| 817 |
+
label="Maximize Free Tier ZeroGPU (150 seconds)",
|
| 818 |
+
value=False,
|
| 819 |
+
info="Forces this request to book exactly 140s (plus 8s on the conditioner) for debugging purposes; does not prevent timeouts.",
|
| 820 |
+
)
|
| 821 |
|
| 822 |
with gr.Column():
|
| 823 |
video = gr.Video(label="Video + soundtrack")
|
| 824 |
report = gr.Markdown()
|
| 825 |
+
lora_1_strength = gr.Slider(
|
| 826 |
+
label="Distilled LoRA",
|
| 827 |
+
minimum=0.0,
|
| 828 |
+
maximum=2.0,
|
| 829 |
+
step=0.05,
|
| 830 |
+
value=DEFAULT_LORA_1_STRENGTH,
|
| 831 |
+
)
|
| 832 |
+
with gr.Accordion("Custom LoRAs", open=False):
|
| 833 |
+
lora_a_strength = gr.Slider(
|
| 834 |
+
label="Anthro Enhancer LoRA",
|
| 835 |
+
minimum=0.0,
|
| 836 |
+
maximum=2.0,
|
| 837 |
+
step=0.05,
|
| 838 |
+
value=DEFAULT_LORA_A_STRENGTH,
|
| 839 |
+
)
|
| 840 |
+
lora_b_strength = gr.Slider(
|
| 841 |
+
label="Reasoning Enhancer LoRA",
|
| 842 |
+
minimum=0.0,
|
| 843 |
+
maximum=2.0,
|
| 844 |
+
step=0.05,
|
| 845 |
+
value=DEFAULT_LORA_B_STRENGTH,
|
| 846 |
+
)
|
| 847 |
+
lora_c_strength = gr.Slider(
|
| 848 |
+
label="HM-AIO LoRA",
|
| 849 |
+
minimum=0.0,
|
| 850 |
+
maximum=2.0,
|
| 851 |
+
step=0.05,
|
| 852 |
+
value=DEFAULT_LORA_C_STRENGTH,
|
| 853 |
+
)
|
| 854 |
+
lora_d_strength = gr.Slider(
|
| 855 |
+
label="Anthro Realism LoRA",
|
| 856 |
+
minimum=0.0,
|
| 857 |
+
maximum=2.0,
|
| 858 |
+
step=0.05,
|
| 859 |
+
value=DEFAULT_LORA_D_STRENGTH,
|
| 860 |
+
)
|
| 861 |
+
lora_e_strength = gr.Slider(
|
| 862 |
+
label="SB LoRA",
|
| 863 |
+
minimum=0.0,
|
| 864 |
+
maximum=2.0,
|
| 865 |
+
step=0.05,
|
| 866 |
+
value=DEFAULT_LORA_E_STRENGTH,
|
| 867 |
+
)
|
| 868 |
+
lora_f_strength = gr.Slider(
|
| 869 |
+
label="Moaxx LoRA",
|
| 870 |
+
minimum=0.0,
|
| 871 |
+
maximum=2.0,
|
| 872 |
+
step=0.05,
|
| 873 |
+
value=DEFAULT_LORA_F_STRENGTH,
|
| 874 |
+
)
|
| 875 |
+
lora_g_strength = gr.Slider(
|
| 876 |
+
label="Fluid Enhancer LoRA",
|
| 877 |
+
minimum=0.0,
|
| 878 |
+
maximum=2.0,
|
| 879 |
+
step=0.05,
|
| 880 |
+
value=DEFAULT_LORA_G_STRENGTH,
|
| 881 |
+
)
|
| 882 |
|
| 883 |
first_frame.upload(_fit_keyframe, [first_frame, canvas], [first_frame, canvas])
|
| 884 |
last_frame.upload(_fit_keyframe, [last_frame, canvas], [last_frame, canvas])
|
|
|
|
| 903 |
lora_e_strength,
|
| 904 |
lora_f_strength,
|
| 905 |
lora_g_strength,
|
| 906 |
+
maximize_gpu,
|
| 907 |
]
|
| 908 |
|
| 909 |
run.click(generate, controls, [video, report], api_name="generate")
|