sourxbhh commited on
Commit
d8a502b
·
1 Parent(s): 1751c05

Fix: Batch generation - use persistent directory for videos

Browse files
Files changed (1) hide show
  1. app.py +41 -6
app.py CHANGED
@@ -336,14 +336,49 @@ def generate_motion_batch(
336
  status_msg = f"Processing {len(text_prompts)} prompts...\n"
337
  video_paths = []
338
 
 
 
 
 
339
  for idx, (text, motion_length) in enumerate(text_prompts):
340
- video_path, gen_msg = generate_motion_single(
341
- text, motion_length, cfg_scale, use_auto_length, gpu_id, seed + idx
342
- )
343
- video_paths.append(video_path)
344
- status_msg += f"\n[{idx+1}/{len(text_prompts)}] {gen_msg}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
 
346
- return video_paths, status_msg
347
 
348
 
349
  # Gradio Interface
 
336
  status_msg = f"Processing {len(text_prompts)} prompts...\n"
337
  video_paths = []
338
 
339
+ # Create a persistent directory for batch videos (not temp, so Gradio can access them)
340
+ batch_output_dir = pjoin('generation', 'batch_temp')
341
+ os.makedirs(batch_output_dir, exist_ok=True)
342
+
343
  for idx, (text, motion_length) in enumerate(text_prompts):
344
+ try:
345
+ video_path, gen_msg = generate_motion_single(
346
+ text, motion_length, cfg_scale, use_auto_length, gpu_id, seed + idx
347
+ )
348
+
349
+ # If video was created, copy it to persistent location for batch gallery
350
+ if video_path and os.path.exists(video_path):
351
+ # Create a unique filename for this batch item
352
+ batch_video_path = pjoin(batch_output_dir, f'motion_{idx:04d}{os.path.splitext(video_path)[1]}')
353
+
354
+ # Copy file to persistent location
355
+ import shutil
356
+ shutil.copy2(video_path, batch_video_path)
357
+
358
+ # Verify the copied file exists
359
+ if os.path.exists(batch_video_path):
360
+ video_paths.append(batch_video_path)
361
+ status_msg += f"\n[{idx+1}/{len(text_prompts)}] ✓ {text[:50]}... - Video saved"
362
+ else:
363
+ status_msg += f"\n[{idx+1}/{len(text_prompts)}] ⚠ {text[:50]}... - Video copy failed"
364
+ video_paths.append(None)
365
+ else:
366
+ status_msg += f"\n[{idx+1}/{len(text_prompts)}] ❌ {text[:50]}... - Generation failed"
367
+ video_paths.append(None)
368
+
369
+ except Exception as e:
370
+ status_msg += f"\n[{idx+1}/{len(text_prompts)}] ❌ Error: {str(e)}"
371
+ video_paths.append(None)
372
+
373
+ # Filter out None values - Gradio Gallery doesn't handle None well
374
+ valid_video_paths = [path for path in video_paths if path is not None and os.path.exists(path)]
375
+
376
+ if len(valid_video_paths) == 0:
377
+ status_msg += "\n\n❌ No videos were successfully generated."
378
+ else:
379
+ status_msg += f"\n\n✓ Successfully generated {len(valid_video_paths)}/{len(text_prompts)} motions."
380
 
381
+ return valid_video_paths, status_msg
382
 
383
 
384
  # Gradio Interface