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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from share_btn import community_icon_html, loading_icon_html, share_js
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 5 |
+
from diffusers.utils import export_to_video
|
| 6 |
|
| 7 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
| 8 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 9 |
+
pipe.enable_model_cpu_offload()
|
| 10 |
|
| 11 |
+
def infer(prompt):
|
| 12 |
+
negative_prompt = "text, watermark, copyright, blurry, nsfw"
|
| 13 |
+
video_frames = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames
|
| 14 |
+
video_path = export_to_video(video_frames)
|
| 15 |
+
print(video_path)
|
| 16 |
+
return video_path, gr.Group.update(visible=True)
|
| 17 |
|
| 18 |
+
css = """
|
| 19 |
+
#col-container {max-width: 510px; margin-left: auto; margin-right: auto;}
|
| 20 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
| 21 |
+
.animate-spin {
|
| 22 |
+
animation: spin 1s linear infinite;
|
| 23 |
+
}
|
| 24 |
|
| 25 |
+
@keyframes spin {
|
| 26 |
+
from {
|
| 27 |
+
transform: rotate(0deg);
|
| 28 |
+
}
|
| 29 |
+
to {
|
| 30 |
+
transform: rotate(360deg);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
|
| 34 |
+
#share-btn-container {
|
| 35 |
+
display: flex;
|
| 36 |
+
padding-left: 0.5rem !important;
|
| 37 |
+
padding-right: 0.5rem !important;
|
| 38 |
+
background-color: #000000;
|
| 39 |
+
justify-content: center;
|
| 40 |
+
align-items: center;
|
| 41 |
+
border-radius: 9999px !important;
|
| 42 |
+
max-width: 15rem;
|
| 43 |
+
height: 36px;
|
| 44 |
+
}
|
| 45 |
|
| 46 |
+
div#share-btn-container > div {
|
| 47 |
+
flex-direction: row;
|
| 48 |
+
background: black;
|
| 49 |
+
align-items: center;
|
| 50 |
+
}
|
| 51 |
|
| 52 |
+
#share-btn-container:hover {
|
| 53 |
+
background-color: #060606;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
#share-btn {
|
| 57 |
+
all: initial;
|
| 58 |
+
color: #ffffff;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
cursor:pointer;
|
| 61 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 62 |
+
margin-left: 0.5rem !important;
|
| 63 |
+
padding-top: 0.5rem !important;
|
| 64 |
+
padding-bottom: 0.5rem !important;
|
| 65 |
+
right:0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
#share-btn * {
|
| 69 |
+
all: unset;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
#share-btn-container div:nth-child(-n+2){
|
| 73 |
+
width: auto !important;
|
| 74 |
+
min-height: 0px !important;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
#share-btn-container .wrap {
|
| 78 |
+
display: none !important;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
#share-btn-container.hidden {
|
| 82 |
+
display: none!important;
|
| 83 |
+
}
|
| 84 |
+
img[src*='#center'] {
|
| 85 |
+
display: inline-block;
|
| 86 |
+
margin: unset;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.footer {
|
| 90 |
+
margin-bottom: 45px;
|
| 91 |
+
margin-top: 10px;
|
| 92 |
+
text-align: center;
|
| 93 |
+
border-bottom: 1px solid #e5e5e5;
|
| 94 |
+
}
|
| 95 |
+
.footer>p {
|
| 96 |
+
font-size: .8rem;
|
| 97 |
+
display: inline-block;
|
| 98 |
+
padding: 0 10px;
|
| 99 |
+
transform: translateY(10px);
|
| 100 |
+
background: white;
|
| 101 |
+
}
|
| 102 |
+
.dark .footer {
|
| 103 |
+
border-color: #303030;
|
| 104 |
+
}
|
| 105 |
+
.dark .footer>p {
|
| 106 |
+
background: #0b0f19;
|
| 107 |
+
}
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
with gr.Blocks(css=css) as demo:
|
| 111 |
+
with gr.Column(elem_id="col-container"):
|
| 112 |
+
gr.Markdown(
|
| 113 |
+
"""
|
| 114 |
+
<h1 style="text-align: center;">Zeroscope Text-to-Video</h1>
|
| 115 |
+
<p style="text-align: center;">
|
| 116 |
+
A watermark-free Modelscope-based video model optimized for producing high-quality 16:9 compositions and a smooth video output. <br />
|
| 117 |
+
</p>
|
| 118 |
+
|
| 119 |
+
"""
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
prompt_in = gr.Textbox(label="Prompt", placeholder="Darth Vader is surfing on waves", elem_id="prompt-in")
|
| 123 |
+
#neg_prompt = gr.Textbox(label="Negative prompt", value="text, watermark, copyright, blurry, nsfw", elem_id="neg-prompt-in")
|
| 124 |
+
#inference_steps = gr.Slider(label="Inference Steps", minimum=10, maximum=100, step=1, value=40, interactive=False)
|
| 125 |
+
submit_btn = gr.Button("Submit")
|
| 126 |
+
video_result = gr.Video(label="Video Output", elem_id="video-output")
|
| 127 |
+
|
| 128 |
+
with gr.Row():
|
| 129 |
+
with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
|
| 130 |
+
community_icon = gr.HTML(community_icon_html)
|
| 131 |
+
loading_icon = gr.HTML(loading_icon_html)
|
| 132 |
+
share_button = gr.Button("Share with Community", elem_id="share-btn")
|
| 133 |
+
|
| 134 |
+
gr.Markdown("""
|
| 135 |
+
[](https://huggingface.co/spaces/fffiloni/zeroscope-cloning?duplicate=true)
|
| 136 |
+
""")
|
| 137 |
+
|
| 138 |
+
gr.HTML("""
|
| 139 |
+
<div class="footer">
|
| 140 |
+
<p>
|
| 141 |
+
<a href="https://huggingface.co/cerspense/zeroscope_v2_576w" target="_blank">Zeroscope v2 576w model</a> by @cerspense -
|
| 142 |
+
Demo by 🤗 <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
|
| 143 |
+
</p>
|
| 144 |
+
</div>
|
| 145 |
+
<div id="may-like-container" style="display: flex;justify-content: center;flex-direction: column;align-items: center;">
|
| 146 |
+
<p style="font-size: 0.8em;margin-bottom: 4px;">You may also like: </p>
|
| 147 |
+
<div id="may-like" style="display:flex; align-items:center; justify-content: center;height:20px;">
|
| 148 |
+
<svg height="20" width="148" style="margin-left:4px">
|
| 149 |
+
<a href="https://huggingface.co/spaces/fffiloni/zeroscope-XL" target="_blank">
|
| 150 |
+
<image href="https://img.shields.io/badge/🤗 Spaces-Zeroscope XL-blue" src="https://img.shields.io/badge/🤗 Spaces-Image to Music-blue.png" height="20"/>
|
| 151 |
+
</a>
|
| 152 |
+
</svg>
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
""")
|
| 156 |
+
|
| 157 |
+
submit_btn.click(fn=infer,
|
| 158 |
+
inputs=[prompt_in],
|
| 159 |
+
outputs=[video_result, share_group],
|
| 160 |
+
api_name="zrscp")
|
| 161 |
+
|
| 162 |
+
share_button.click(None, [], [], _js=share_js)
|
| 163 |
+
|
| 164 |
+
demo.queue(max_size=12).launch(show_api=True)
|
| 165 |
+
|