Spaces:
Sleeping
Sleeping
Fix: Video path handling and add imageio dependencies
Browse files- app.py +32 -11
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -251,20 +251,41 @@ def generate_motion_single(
|
|
| 251 |
|
| 252 |
# Create temporary file for video
|
| 253 |
temp_dir = tempfile.mkdtemp()
|
|
|
|
| 254 |
video_path = pjoin(temp_dir, 'motion.mp4')
|
| 255 |
|
| 256 |
-
# Generate video
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
status_msg += "✓ Motion generated successfully!"
|
| 267 |
-
return
|
| 268 |
|
| 269 |
except Exception as e:
|
| 270 |
error_msg = f"Error generating motion: {str(e)}"
|
|
|
|
| 251 |
|
| 252 |
# Create temporary file for video
|
| 253 |
temp_dir = tempfile.mkdtemp()
|
| 254 |
+
os.makedirs(temp_dir, exist_ok=True)
|
| 255 |
video_path = pjoin(temp_dir, 'motion.mp4')
|
| 256 |
|
| 257 |
+
# Generate video - plot_3d_motion returns the actual path (may be .mp4 or .gif)
|
| 258 |
+
try:
|
| 259 |
+
actual_video_path = plot_3d_motion(
|
| 260 |
+
video_path,
|
| 261 |
+
t2m_kinematic_chain,
|
| 262 |
+
joints,
|
| 263 |
+
title=text,
|
| 264 |
+
fps=20,
|
| 265 |
+
radius=4
|
| 266 |
+
)
|
| 267 |
+
except Exception as e:
|
| 268 |
+
status_msg += f"\n⚠ Error in plot_3d_motion: {str(e)}"
|
| 269 |
+
raise
|
| 270 |
+
|
| 271 |
+
# Verify file exists - check both the returned path and original path
|
| 272 |
+
if not os.path.exists(actual_video_path):
|
| 273 |
+
# Check if file exists with original path
|
| 274 |
+
if os.path.exists(video_path):
|
| 275 |
+
actual_video_path = video_path
|
| 276 |
+
# Check if it was saved as GIF instead
|
| 277 |
+
elif os.path.exists(video_path.replace('.mp4', '.gif')):
|
| 278 |
+
actual_video_path = video_path.replace('.mp4', '.gif')
|
| 279 |
+
else:
|
| 280 |
+
# List files in temp directory for debugging
|
| 281 |
+
files_in_dir = os.listdir(temp_dir) if os.path.exists(temp_dir) else []
|
| 282 |
+
error_msg = f"Video file not found. Expected: {actual_video_path}\n"
|
| 283 |
+
error_msg += f"Files in temp directory: {files_in_dir}"
|
| 284 |
+
status_msg += f"\n❌ {error_msg}"
|
| 285 |
+
raise FileNotFoundError(error_msg)
|
| 286 |
|
| 287 |
+
status_msg += f"\n✓ Motion generated successfully! Video saved."
|
| 288 |
+
return actual_video_path, status_msg
|
| 289 |
|
| 290 |
except Exception as e:
|
| 291 |
error_msg = f"Error generating motion: {str(e)}"
|
requirements.txt
CHANGED
|
@@ -20,6 +20,8 @@ tqdm>=4.64.0
|
|
| 20 |
matplotlib>=3.5.0
|
| 21 |
opencv-python>=4.6.0
|
| 22 |
Pillow>=9.0.0
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# ODE/SDE solvers for diffusion
|
| 25 |
torchdiffeq>=0.2.5
|
|
|
|
| 20 |
matplotlib>=3.5.0
|
| 21 |
opencv-python>=4.6.0
|
| 22 |
Pillow>=9.0.0
|
| 23 |
+
imageio>=2.25.0
|
| 24 |
+
imageio-ffmpeg>=0.4.8
|
| 25 |
|
| 26 |
# ODE/SDE solvers for diffusion
|
| 27 |
torchdiffeq>=0.2.5
|