AhmadMustafa Claude commited on
Commit
93fbc4c
·
1 Parent(s): 9f296e7

Fix tensor to numpy conversion for video export

Browse files

- Import numpy for array handling
- Convert torch tensors to numpy arrays
- Handle float [0,1] to uint8 [0,255] conversion
- Convert 4D array to list of frames for export_to_video

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import tempfile
3
 
4
  import gradio as gr
 
5
  import spaces
6
  import torch
7
  from diffusers.utils import export_to_video
@@ -79,6 +80,20 @@ def generate_interpolation(
79
  else:
80
  video_frames = output
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  # Export to temporary file
83
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
84
  output_path = temp_file.name
 
2
  import tempfile
3
 
4
  import gradio as gr
5
+ import numpy as np
6
  import spaces
7
  import torch
8
  from diffusers.utils import export_to_video
 
80
  else:
81
  video_frames = output
82
 
83
+ # Convert tensor to numpy if needed
84
+ if torch.is_tensor(video_frames):
85
+ video_frames = video_frames.cpu().numpy()
86
+
87
+ # Ensure correct format: list of numpy arrays in [0, 255] range
88
+ if isinstance(video_frames, np.ndarray):
89
+ # If shape is (frames, height, width, channels)
90
+ if video_frames.ndim == 4:
91
+ # Convert from float [0, 1] to uint8 [0, 255] if needed
92
+ if video_frames.dtype == np.float32 or video_frames.dtype == np.float64:
93
+ video_frames = (video_frames * 255).astype(np.uint8)
94
+ # Convert to list of frames
95
+ video_frames = [video_frames[i] for i in range(video_frames.shape[0])]
96
+
97
  # Export to temporary file
98
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
99
  output_path = temp_file.name