Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -64,9 +64,9 @@ 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 * multiplier) + 1
|
71 |
torch_dtype = torch.bfloat16 if MODEL_DTYPE == "bf16" else torch.float32
|
72 |
if(image):
|
@@ -97,23 +97,26 @@ def generate_video(prompt, image=None, duration=5, guidance_scale=9, video_guida
|
|
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=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=2 if is_canonical else 5, step=1, label="Duration (seconds)"
|
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,7 +145,11 @@ with gr.Blocks() as demo:
|
|
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 |
|
148 |
demo.launch()
|
|
|
64 |
model = load_model()
|
65 |
|
66 |
# Text-to-video generation function
|
67 |
+
@spaces.GPU(duration=160)
|
68 |
def generate_video(prompt, image=None, duration=5, guidance_scale=9, video_guidance_scale=5, progress=gr.Progress(track_tqdm=True)):
|
69 |
+
multiplier = 3
|
70 |
temp = int(duration * multiplier) + 1
|
71 |
torch_dtype = torch.bfloat16 if MODEL_DTYPE == "bf16" else torch.float32
|
72 |
if(image):
|
|
|
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 |
+
frames = gr.State()
|
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=2 if is_canonical else 10, value=2 if is_canonical else 5, step=1, label="Duration (seconds)")
|
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 |
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 |
+
input=[frames],
|
152 |
+
outouts=t2v_output
|
153 |
)
|
154 |
|
155 |
demo.launch()
|