Spaces:
Running
on
A10G
Running
on
A10G
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
4 |
+
from diffusers.utils import export_to_video
|
5 |
+
|
6 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
7 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
8 |
+
pipe.enable_model_cpu_offload()
|
9 |
+
|
10 |
+
def infer(prompt, num_inference_steps):
|
11 |
+
#prompt = "Darth Vader is surfing on waves"
|
12 |
+
video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames
|
13 |
+
video_path = export_to_video(video_frames)
|
14 |
+
print(video_path)
|
15 |
+
return video_path
|
16 |
+
|
17 |
+
css = """
|
18 |
+
#col-container {max-width: 510px; margin-left: auto; margin-right: auto;}
|
19 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
20 |
+
"""
|
21 |
+
|
22 |
+
with gr.Blocks(css=css) as demo:
|
23 |
+
with gr.Column(elem_id="col-container"):
|
24 |
+
gr.HTML("""<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
25 |
+
<div
|
26 |
+
style="
|
27 |
+
display: inline-flex;
|
28 |
+
align-items: center;
|
29 |
+
gap: 0.8rem;
|
30 |
+
font-size: 1.75rem;
|
31 |
+
"
|
32 |
+
>
|
33 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
|
34 |
+
Zeroscope Text-to-Video
|
35 |
+
</h1>
|
36 |
+
</div>
|
37 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
38 |
+
A watermark-free Modelscope-based video model optimized for producing high-quality 16:9 compositions and a smooth video output. <br />
|
39 |
+
This model was trained using 9,923 clips and 29,769 tagged frames at 24 frames, 576x320 resolution.
|
40 |
+
|
41 |
+
</p>
|
42 |
+
</div>""")
|
43 |
+
|
44 |
+
prompt_in = gr.Textbox(label="Prompt", placeholder="Darth Vader is surfing on waves")
|
45 |
+
inference_steps = gr.Slider(minimum=10, maximum=100, step=1, value=40, interactive=False)
|
46 |
+
submit_btn = gr.Button("Submit")
|
47 |
+
video_result = gr.Video(label="Video Output")
|
48 |
+
|
49 |
+
submit_btn.click(fn=infer,
|
50 |
+
inputs=[prompt_in, inference_steps],
|
51 |
+
outputs=[video_result])
|
52 |
+
|
53 |
+
demo.queue(max_size=12).launch()
|
54 |
+
|