ai-forever commited on
Commit
24472b6
1 Parent(s): 9d3c2b7
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -7,7 +7,8 @@ from glob import glob
7
  from pathlib import Path
8
  from typing import Optional
9
 
10
- from diffusers import StableVideoDiffusionPipeline
 
11
  from diffusers.utils import load_image, export_to_video
12
  from PIL import Image
13
 
@@ -17,13 +18,20 @@ from huggingface_hub import hf_hub_download
17
 
18
  #gradio.helpers.CACHED_FOLDER = '/data/cache'
19
 
20
- pipe = StableVideoDiffusionPipeline.from_pretrained(
21
- "multimodalart/stable-video-diffusion", torch_dtype=torch.float16, variant="fp16"
22
- )
23
- pipe.to("cuda")
24
  #pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
25
  #pipe.vae = torch.compile(pipe.vae, mode="reduce-overhead", fullgraph=True)
26
 
 
 
 
 
 
 
 
27
  max_64_bit_int = 2**63 - 1
28
 
29
  @spaces.GPU(duration=120)
@@ -40,21 +48,29 @@ def sample(
40
  output_folder: str = "outputs",
41
  progress=gr.Progress(track_tqdm=True)
42
  ):
43
- if image.mode == "RGBA":
44
- image = image.convert("RGB")
45
 
46
- if(randomize_seed):
47
- seed = random.randint(0, max_64_bit_int)
48
- generator = torch.manual_seed(seed)
49
-
50
  os.makedirs(output_folder, exist_ok=True)
51
  base_count = len(glob(os.path.join(output_folder, "*.mp4")))
52
  video_path = os.path.join(output_folder, f"{base_count:06d}.mp4")
53
 
54
- frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
55
- export_to_video(frames, video_path, fps=fps_id)
 
 
 
 
 
 
 
 
56
  torch.manual_seed(seed)
57
-
58
  return video_path, seed
59
 
60
  def resize_image(image, output_size=(1024, 576)):
 
7
  from pathlib import Path
8
  from typing import Optional
9
 
10
+ # from diffusers import StableVideoDiffusionPipeline
11
+ from kandinsky import get_T2V_pipeline
12
  from diffusers.utils import load_image, export_to_video
13
  from PIL import Image
14
 
 
18
 
19
  #gradio.helpers.CACHED_FOLDER = '/data/cache'
20
 
21
+ # pipe = StableVideoDiffusionPipeline.from_pretrained(
22
+ # "multimodalart/stable-video-diffusion", torch_dtype=torch.float16, variant="fp16"
23
+ # )
24
+ # pipe.to("cuda")
25
  #pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
26
  #pipe.vae = torch.compile(pipe.vae, mode="reduce-overhead", fullgraph=True)
27
 
28
+ device_map = {
29
+ "dit": torch.device('cuda'),
30
+ "vae": torch.device('cuda'),
31
+ "text_embedder": torch.device('cuda')
32
+ }
33
+ pipe = get_T2V_pipeline(device_map)
34
+
35
  max_64_bit_int = 2**63 - 1
36
 
37
  @spaces.GPU(duration=120)
 
48
  output_folder: str = "outputs",
49
  progress=gr.Progress(track_tqdm=True)
50
  ):
51
+ # if image.mode == "RGBA":
52
+ # image = image.convert("RGB")
53
 
54
+ # if(randomize_seed):
55
+ # seed = random.randint(0, max_64_bit_int)
56
+ # generator = torch.manual_seed(seed)
57
+
58
  os.makedirs(output_folder, exist_ok=True)
59
  base_count = len(glob(os.path.join(output_folder, "*.mp4")))
60
  video_path = os.path.join(output_folder, f"{base_count:06d}.mp4")
61
 
62
+ # frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
63
+ frames = pipe(
64
+ seed=seed,
65
+ time_length=12,
66
+ width = 672,
67
+ height = 384,
68
+ save_path=video_path,
69
+ text=prompt,
70
+ )
71
+ export_to_video(frames, video_path, fps=8)
72
  torch.manual_seed(seed)
73
+
74
  return video_path, seed
75
 
76
  def resize_image(image, output_size=(1024, 576)):