LPX55 commited on
Commit
45ee339
·
verified ·
1 Parent(s): 7759d52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -4
app.py CHANGED
@@ -96,11 +96,10 @@ def construct_video_pipeline(model_id: str, lora_path: str):
96
  pipe.unload_lora_weights()
97
 
98
  return pipe
99
-
100
- def generate_video(prompt: str, frame1_url: str, frame2_url: str, guidance_scale: float, num_frames: int, num_inference_steps: int) -> bytes:
101
  # Load and preprocess frames
102
- cond_frame1 = Image.open(requests.get(frame1_url, stream=True).raw)
103
- cond_frame2 = Image.open(requests.get(frame2_url, stream=True).raw)
104
 
105
  height, width = 720, 1280
106
  cond_frame1 = resize_image_to_bucket(cond_frame1, bucket_reso=(width, height))
@@ -145,6 +144,54 @@ def generate_video(prompt: str, frame1_url: str, frame2_url: str, guidance_scale
145
  video_bytes = video_file.read()
146
 
147
  return video_bytes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  @torch.inference_mode()
150
  def call_pipe(
 
96
  pipe.unload_lora_weights()
97
 
98
  return pipe
99
+ def generate_video(prompt: str, frame1_path: str, frame2_path: str, guidance_scale: float, num_frames: int, num_inference_steps: int) -> bytes:
 
100
  # Load and preprocess frames
101
+ cond_frame1 = Image.open(frame1_path)
102
+ cond_frame2 = Image.open(frame2_path)
103
 
104
  height, width = 720, 1280
105
  cond_frame1 = resize_image_to_bucket(cond_frame1, bucket_reso=(width, height))
 
144
  video_bytes = video_file.read()
145
 
146
  return video_bytes
147
+ # def generate_video(prompt: str, frame1_url: str, frame2_url: str, guidance_scale: float, num_frames: int, num_inference_steps: int) -> bytes:
148
+ # # Load and preprocess frames
149
+ # cond_frame1 = Image.open(requests.get(frame1_url, stream=True).raw)
150
+ # cond_frame2 = Image.open(requests.get(frame2_url, stream=True).raw)
151
+
152
+ # height, width = 720, 1280
153
+ # cond_frame1 = resize_image_to_bucket(cond_frame1, bucket_reso=(width, height))
154
+ # cond_frame2 = resize_image_to_bucket(cond_frame2, bucket_reso=(width, height))
155
+
156
+ # cond_video = np.zeros(shape=(num_frames, height, width, 3))
157
+ # cond_video[0], cond_video[-1] = np.array(cond_frame1), np.array(cond_frame2)
158
+ # cond_video = torch.from_numpy(cond_video.copy()).permute(0, 3, 1, 2)
159
+ # cond_video = torch.stack([video_transforms(x) for x in cond_video], dim=0).unsqueeze(0)
160
+
161
+ # # Initialize pipeline
162
+ # model_id = "hunyuanvideo-community/HunyuanVideo"
163
+ # lora_path = hf_hub_download("dashtoon/hunyuan-video-keyframe-control-lora", "i2v.sft") # Replace with the actual LORA path
164
+ # pipe = construct_video_pipeline(model_id, lora_path)
165
+
166
+ # with torch.no_grad():
167
+ # image_or_video = cond_video.to(device="cuda", dtype=pipe.dtype)
168
+ # image_or_video = image_or_video.permute(0, 2, 1, 3, 4).contiguous() # [B, F, C, H, W] -> [B, C, F, H, W]
169
+ # cond_latents = pipe.vae.encode(image_or_video).latent_dist.sample()
170
+ # cond_latents = cond_latents * pipe.vae.config.scaling_factor
171
+ # cond_latents = cond_latents.to(dtype=pipe.dtype)
172
+ # assert not torch.any(torch.isnan(cond_latents))
173
+
174
+ # # Generate video
175
+ # video = call_pipe(
176
+ # pipe,
177
+ # prompt=prompt,
178
+ # num_frames=num_frames,
179
+ # num_inference_steps=num_inference_steps,
180
+ # image_latents=cond_latents,
181
+ # width=width,
182
+ # height=height,
183
+ # guidance_scale=guidance_scale,
184
+ # generator=torch.Generator(device="cuda").manual_seed(0),
185
+ # ).frames[0]
186
+
187
+ # # Export to video
188
+ # video_path = "output.mp4"
189
+ # export_to_video(video, video_path, fps=24)
190
+
191
+ # with open(video_path, "rb") as video_file:
192
+ # video_bytes = video_file.read()
193
+
194
+ # return video_bytes
195
 
196
  @torch.inference_mode()
197
  def call_pipe(