Views
No views yet
1pip install diffusers transformers accelerate imageio[ffmpeg]
2pip install git+ssh://git@github.com/baaivision/URSA.git1import os, torch, numpy
2from diffnext.pipelines import URSAPipeline
3from diffnext.utils import export_to_video
4os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
5
6model_id, height, width = "BAAI/URSA-0.6B-FSQ320", 320, 512
7model_args = {"torch_dtype": torch.float16, "trust_remote_code": True}
8pipe = URSAPipeline.from_pretrained(model_id, **model_args)
9pipe = pipe.to(torch.device("cuda"))
10
11text_prompt = "a lone grizzly bear walks through a misty forest at dawn, sunlight catching its fur."
12negative_prompt = "worst quality, low quality, inconsistent motion, static, still, blurry, jittery, distorted, ugly"
13
14# Text-to-Image
15prompt = text_prompt
16num_frames, num_inference_steps = 1, 25
17image = pipe(**locals()).frames[0]
18image.save("ursa.jpg")
19
20# Image-to-Video
21prompt = f"motion=9.0, {text_prompt}"
22num_frames, num_inference_steps = 49, 50
23video = pipe(**locals()).frames[0]
24export_to_video(video, "ursa_1+48f.mp4", fps=12)
25
26# Text-to-Video
27image, video = None, None
28prompt = f"motion=9.0, {text_prompt}"
29num_frames, num_inference_steps = 49, 50
30video = pipe(**locals()).frames[0]
31export_to_video(video, "ursa_49f.mp4", fps=12)
32
33# Video-to-Video
34prompt = f"motion=5.0, {text_prompt}"
35num_frames, num_inference_steps = 49, 50
36num_cond_frames, cond_noise_scale = 13, 0.1
37for i in range(12):
38 video, start_video = video[-num_cond_frames:], video
39 video = pipe(**locals()).frames[0]
40 video = numpy.concatenate([start_video, video[num_cond_frames:]])
41 export_to_video(video, "ursa_{}f.mp4".format(video.shape[0]), fps=12)