dagloop5 commited on
Commit
8580bc6
verified
1 Parent(s): f6f9a22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -537,7 +537,21 @@ def _generate(
537
  video = pk.interpolate(FILM, video, multiplier)
538
  fps = FPS * multiplier
539
 
540
- return video, audio, sampling_rate, fps, multiplier
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
 
542
 
543
  def generate(
@@ -609,17 +623,12 @@ def generate(
609
 
610
  progress(0.1, desc=f"Generating {num_frames / FPS:.1f} s at {width}x{height} ...")
611
  started = time.time()
612
- video, audio, sampling_rate, fps, multiplier = _generate(
613
  prompt_embeds, text_token_tags, references, height, width, num_frames, steps, seed,
614
  sampler_key, schedule_key, float(video_shift), float(audio_shift), float(sharpen), multiplier,
615
  )
616
  generate_seconds = time.time() - started
617
 
618
- directory = os.path.join(tempfile.gettempdir(), "h3-outputs")
619
- os.makedirs(directory, exist_ok=True)
620
- path = os.path.join(directory, f"h3-ref2va-{int(time.time() * 1000)}.mp4")
621
- encode_video(video, fps=fps, output_path=path, audio=audio, audio_sample_rate=sampling_rate)
622
-
623
  print(
624
  f"[ref2va] {[kind for kind, _ in references]} 路 `{width}x{height}`, {num_frames} frames "
625
  f"({num_frames / FPS:.3f} s), {int(steps)} steps of `{schedule_key}` 路 sampler `{sampler_key}` 路 "
 
537
  video = pk.interpolate(FILM, video, multiplier)
538
  fps = FPS * multiplier
539
 
540
+ # Muxed to an mp4 here, before returning, rather than in the caller: a raw CUDA tensor can't cross a
541
+ # `@spaces.GPU` return at all under ZeroGPU's CUDA-emulation mode (`RuntimeError: Low-level CUDA init
542
+ # reached` trying to reconstruct it in the dispatching process), and a CPU float tensor of several hundred
543
+ # interpolated frames is needlessly large to pickle anyway when the finished file is a few MB of h264.
544
+ from diffusers.utils import encode_video
545
+
546
+ frames = (video.permute(0, 2, 3, 1).float() * 255.0).round_().clamp_(0, 255).to(torch.uint8).cpu()
547
+ del video
548
+
549
+ directory = os.path.join(tempfile.gettempdir(), "h3-outputs")
550
+ os.makedirs(directory, exist_ok=True)
551
+ path = os.path.join(directory, f"h3-ref2va-{int(time.time() * 1000)}.mp4")
552
+ encode_video(frames, fps=fps, output_path=path, audio=audio, audio_sample_rate=sampling_rate)
553
+
554
+ return path, fps, multiplier
555
 
556
 
557
  def generate(
 
623
 
624
  progress(0.1, desc=f"Generating {num_frames / FPS:.1f} s at {width}x{height} ...")
625
  started = time.time()
626
+ path, fps, multiplier = _generate(
627
  prompt_embeds, text_token_tags, references, height, width, num_frames, steps, seed,
628
  sampler_key, schedule_key, float(video_shift), float(audio_shift), float(sharpen), multiplier,
629
  )
630
  generate_seconds = time.time() - started
631
 
 
 
 
 
 
632
  print(
633
  f"[ref2va] {[kind for kind, _ in references]} 路 `{width}x{height}`, {num_frames} frames "
634
  f"({num_frames / FPS:.3f} s), {int(steps)} steps of `{schedule_key}` 路 sampler `{sampler_key}` 路 "