Spaces:
Runtime error
Runtime error
Commit
•
f9979b6
1
Parent(s):
77956e4
revert back to 3s
Browse files
app.py
CHANGED
@@ -64,14 +64,14 @@ def load_model():
|
|
64 |
model = load_model()
|
65 |
|
66 |
# Text-to-video generation function
|
67 |
-
@spaces.GPU(duration=
|
68 |
def generate_video(prompt, image=None, duration=5, guidance_scale=9, video_guidance_scale=5, progress=gr.Progress(track_tqdm=True)):
|
69 |
-
multiplier =
|
70 |
-
temp = int(duration *
|
71 |
torch_dtype = torch.bfloat16 if MODEL_DTYPE == "bf16" else torch.float32
|
72 |
if(image):
|
73 |
-
cropped_image = center_crop(image, 1280,
|
74 |
-
resized_image = cropped_image.resize((1280,
|
75 |
with torch.no_grad(), torch.cuda.amp.autocast(enabled=True, dtype=torch_dtype):
|
76 |
frames = model.generate_i2v(
|
77 |
prompt=prompt,
|
@@ -97,26 +97,23 @@ def generate_video(prompt, image=None, duration=5, guidance_scale=9, video_guida
|
|
97 |
output_type="pil",
|
98 |
save_memory=True,
|
99 |
)
|
100 |
-
return frames, gr.update()
|
101 |
-
|
102 |
-
def compose_video(frames):
|
103 |
output_path = f"{str(uuid.uuid4())}_output_video.mp4"
|
104 |
-
export_to_video(frames, output_path, fps=24)
|
105 |
-
return output_path
|
106 |
|
107 |
# Gradio interface
|
108 |
with gr.Blocks() as demo:
|
109 |
gr.Markdown("# Pyramid Flow")
|
110 |
gr.Markdown("Pyramid Flow is a training-efficient Autoregressive Video Generation model based on Flow Matching. It is trained only on open-source datasets within 20.7k A100 GPU hours")
|
111 |
gr.Markdown("[[Paper](https://arxiv.org/pdf/2410.05954)], [[Model](https://huggingface.co/rain1011/pyramid-flow-sd3)], [[Code](https://github.com/jy0205/Pyramid-Flow)]")
|
112 |
-
|
113 |
with gr.Row():
|
114 |
with gr.Column():
|
115 |
with gr.Accordion("Image to Video (optional)", open=False):
|
116 |
i2v_image = gr.Image(type="pil", label="Input Image")
|
117 |
t2v_prompt = gr.Textbox(label="Prompt")
|
118 |
with gr.Accordion("Advanced settings", open=False):
|
119 |
-
t2v_duration = gr.Slider(minimum=1, maximum=
|
120 |
t2v_guidance_scale = gr.Slider(minimum=1, maximum=15, value=9, step=0.1, label="Guidance Scale")
|
121 |
t2v_video_guidance_scale = gr.Slider(minimum=1, maximum=15, value=5, step=0.1, label="Video Guidance Scale")
|
122 |
t2v_generate_btn = gr.Button("Generate Video")
|
@@ -145,10 +142,6 @@ with gr.Blocks() as demo:
|
|
145 |
t2v_generate_btn.click(
|
146 |
generate_video,
|
147 |
inputs=[t2v_prompt, i2v_image, t2v_duration, t2v_guidance_scale, t2v_video_guidance_scale],
|
148 |
-
outputs=[frames, t2v_output]
|
149 |
-
).then(
|
150 |
-
compose_video,
|
151 |
-
inputs=[frames],
|
152 |
outputs=t2v_output
|
153 |
)
|
154 |
|
|
|
64 |
model = load_model()
|
65 |
|
66 |
# Text-to-video generation function
|
67 |
+
@spaces.GPU(duration=120)
|
68 |
def generate_video(prompt, image=None, duration=5, guidance_scale=9, video_guidance_scale=5, progress=gr.Progress(track_tqdm=True)):
|
69 |
+
multiplier = 0.8 if is_canonical else 2.4
|
70 |
+
temp = int(duration * 0.8) # Convert seconds to temp value (assuming 24 FPS)
|
71 |
torch_dtype = torch.bfloat16 if MODEL_DTYPE == "bf16" else torch.float32
|
72 |
if(image):
|
73 |
+
cropped_image = center_crop(image, 1280, 720)
|
74 |
+
resized_image = cropped_image.resize((1280, 720))
|
75 |
with torch.no_grad(), torch.cuda.amp.autocast(enabled=True, dtype=torch_dtype):
|
76 |
frames = model.generate_i2v(
|
77 |
prompt=prompt,
|
|
|
97 |
output_type="pil",
|
98 |
save_memory=True,
|
99 |
)
|
|
|
|
|
|
|
100 |
output_path = f"{str(uuid.uuid4())}_output_video.mp4"
|
101 |
+
export_to_video(frames, output_path, fps=8 if is_canonical else 24)
|
102 |
+
return output_path
|
103 |
|
104 |
# Gradio interface
|
105 |
with gr.Blocks() as demo:
|
106 |
gr.Markdown("# Pyramid Flow")
|
107 |
gr.Markdown("Pyramid Flow is a training-efficient Autoregressive Video Generation model based on Flow Matching. It is trained only on open-source datasets within 20.7k A100 GPU hours")
|
108 |
gr.Markdown("[[Paper](https://arxiv.org/pdf/2410.05954)], [[Model](https://huggingface.co/rain1011/pyramid-flow-sd3)], [[Code](https://github.com/jy0205/Pyramid-Flow)]")
|
109 |
+
|
110 |
with gr.Row():
|
111 |
with gr.Column():
|
112 |
with gr.Accordion("Image to Video (optional)", open=False):
|
113 |
i2v_image = gr.Image(type="pil", label="Input Image")
|
114 |
t2v_prompt = gr.Textbox(label="Prompt")
|
115 |
with gr.Accordion("Advanced settings", open=False):
|
116 |
+
t2v_duration = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Duration (seconds)", visible=not is_canonical)
|
117 |
t2v_guidance_scale = gr.Slider(minimum=1, maximum=15, value=9, step=0.1, label="Guidance Scale")
|
118 |
t2v_video_guidance_scale = gr.Slider(minimum=1, maximum=15, value=5, step=0.1, label="Video Guidance Scale")
|
119 |
t2v_generate_btn = gr.Button("Generate Video")
|
|
|
142 |
t2v_generate_btn.click(
|
143 |
generate_video,
|
144 |
inputs=[t2v_prompt, i2v_image, t2v_duration, t2v_guidance_scale, t2v_video_guidance_scale],
|
|
|
|
|
|
|
|
|
145 |
outputs=t2v_output
|
146 |
)
|
147 |
|