import gradio as gr from share_btn import community_icon_html, loading_icon_html, share_js import torch from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler from diffusers.utils import export_to_video pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe.enable_model_cpu_offload() caption = gr.load(name="spaces/fffiloni/CoCa-clone") def create_image_caption(image_init): cap = caption(image_init, "Beam search", 1.2, 0.5, 5, 20, fn_index=0) print("cap: " + cap) return cap def infer(image_init): prompt = create_image_caption(image_init) video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames video_path = export_to_video(video_frames) print(video_path) return prompt, video_path, gr.Group.update(visible=True) css = """ #col-container {max-width: 510px; margin-left: auto; margin-right: auto;} a {text-decoration-line: underline; font-weight: 600;} .animate-spin { animation: spin 1s linear infinite; } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } #share-btn-container { display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; max-width: 13rem; } #share-btn-container:hover { background-color: #060606; } #share-btn { all: initial; color: #ffffff; font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; right:0; } #share-btn * { all: unset; } #share-btn-container div:nth-child(-n+2){ width: auto !important; min-height: 0px !important; } #share-btn-container .wrap { display: none !important; } #share-btn-container.hidden { display: none!important; } img[src*='#center'] { display: block; margin: auto; } """ with gr.Blocks(css=css) as demo: with gr.Column(elem_id="col-container"): gr.Markdown( """
A watermark-free Modelscope-based video model optimized for producing high-quality 16:9 compositions and a smooth video output.
This demo is a variation that lets you upload an image as reference for video generation.