rahul7star commited on
Commit
59bbf3c
·
verified ·
1 Parent(s): d8bee93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -42,25 +42,27 @@ def get_duration(prompt, height, width, negative_prompt, duration_seconds, guida
42
  # Gradio inference function with spaces GPU decorator
43
  @spaces.GPU(duration=get_duration)
44
  def generate_video(prompt, height, width, negative_prompt, duration_seconds, guidance_scale, steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
45
- generator = torch.manual_seed(seed) if seed else None
46
- fps = 8
47
- num_frames = int(duration_seconds * fps) if duration_seconds else 16
48
 
49
- video_frames = pipe(
50
  prompt=prompt,
 
 
 
51
  num_frames=num_frames,
52
- generator=generator,
53
- num_inference_steps=steps
 
54
  ).frames[0]
55
 
56
- processed_frames = [
57
- (np.clip(frame * 255, 0, 255).astype(np.uint8) if frame.dtype in [np.float32, np.float64] else frame)
58
- for frame in video_frames
59
- ]
 
 
60
 
61
- out_path = "output.gif"
62
- imageio.mimsave(out_path, processed_frames, fps=fps)
63
- return out_path
64
 
65
  # Build Gradio UI with all parameters
66
  with gr.Blocks(css="body { max-width: 100vw; overflow-x: hidden; }") as demo:
 
42
  # Gradio inference function with spaces GPU decorator
43
  @spaces.GPU(duration=get_duration)
44
  def generate_video(prompt, height, width, negative_prompt, duration_seconds, guidance_scale, steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
45
+ num_frames = np.clip(int(round(duration_seconds * FIXED_FPS)), MIN_FRAMES_MODEL, MAX_FRAMES_MODEL)
46
+ current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
 
47
 
48
+ output_frames_list = pipe(
49
  prompt=prompt,
50
+ negative_prompt=negative_prompt,
51
+ height=int(height),
52
+ width=int(width),
53
  num_frames=num_frames,
54
+ guidance_scale=float(guidance_scale),
55
+ num_inference_steps=int(steps),
56
+ generator=torch.Generator(device="cuda").manual_seed(current_seed),
57
  ).frames[0]
58
 
59
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
60
+ video_path = tmpfile.name
61
+
62
+ export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
63
+
64
+ return video_path, current_seed
65
 
 
 
 
66
 
67
  # Build Gradio UI with all parameters
68
  with gr.Blocks(css="body { max-width: 100vw; overflow-x: hidden; }") as demo: