nocapdev commited on
Commit
a2e709b
·
verified ·
1 Parent(s): 9bad583

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +5 -50
app.py CHANGED
@@ -18,7 +18,7 @@ from utils.paramUtil import t2m_kinematic_chain
18
  clip_version = 'ViT-B/32'
19
 
20
  class MotionGenerator:
21
- def __init__(self, checkpoints_dir, dataset_name, model_name, res_name, vq_name, device='cuda'):
22
  self.device = torch.device(device if torch.cuda.is_available() else 'cpu')
23
  self.dataset_name = dataset_name
24
  self.dim_pose = 251 if dataset_name == 'kit' else 263
@@ -250,15 +250,10 @@ class MotionGenerator:
250
  def create_gradio_interface(generator, output_dir='./gradio_outputs'):
251
  os.makedirs(output_dir, exist_ok=True)
252
 
253
- def generate_motion(text_prompt, progress=gr.Progress()):
254
  try:
255
- import time
256
- start_time = time.time()
257
-
258
- print(f"\n{'='*70}")
259
- print(f"[START] Generating motion for: '{text_prompt}'")
260
  print(f"Device: {generator.device}")
261
- print(f"{'='*70}")
262
 
263
  # Use default parameters for simplicity
264
  motion_length = 0 # Auto-estimate
@@ -270,15 +265,7 @@ def create_gradio_interface(generator, output_dir='./gradio_outputs'):
270
  seed = 42
271
  use_ik = True
272
 
273
- # Show warning about CPU
274
- if str(generator.device) == 'cpu':
275
- print("\n⚠️ WARNING: Using CPU - this will take 10-30 minutes!")
276
- print("For faster inference, upgrade Space to GPU hardware.")
277
-
278
  # Generate motion
279
- progress(0.1, desc="[1/4] Generating motion tokens (10-20 mins on CPU)...")
280
- print("[1/4] Generating motion tokens...")
281
-
282
  joint, actual_length = generator.generate(
283
  text_prompt,
284
  motion_length,
@@ -290,13 +277,7 @@ def create_gradio_interface(generator, output_dir='./gradio_outputs'):
290
  seed
291
  )
292
 
293
- elapsed = time.time() - start_time
294
- print(f"✓ Generated {actual_length} frames in {elapsed:.1f}s")
295
-
296
  # Save BVH and video
297
- progress(0.6, desc="[2/4] Converting to BVH format...")
298
- print("[2/4] Converting to BVH format...")
299
-
300
  timestamp = str(np.random.randint(100000))
301
  video_path = pjoin(output_dir, f'motion_{timestamp}.mp4')
302
 
@@ -305,32 +286,17 @@ def create_gradio_interface(generator, output_dir='./gradio_outputs'):
305
  joint, filename=None, iterations=100, foot_ik=True
306
  )
307
 
308
- print("✓ BVH conversion complete")
309
-
310
  # Create video
311
- progress(0.8, desc="[3/4] Rendering video...")
312
- print("[3/4] Rendering video...")
313
-
314
  plot_3d_motion(video_path, generator.kinematic_chain, joint_processed,
315
  title=text_prompt, fps=20)
316
 
317
- print(f"Video saved: {video_path}")
318
-
319
- progress(1.0, desc="[4/4] Complete!")
320
- total_time = time.time() - start_time
321
- print(f"[4/4] Complete! Total time: {total_time:.1f}s")
322
- print(f"{'='*70}\n")
323
-
324
  return video_path
325
 
326
  except Exception as e:
327
  import traceback
328
  error_msg = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
329
- print("="*70)
330
- print("ERROR during generation:")
331
- print("="*70)
332
  print(error_msg)
333
- print("="*70)
334
  return None
335
 
336
  # Create Gradio interface with Blocks for custom layout
@@ -372,17 +338,6 @@ def create_gradio_interface(generator, output_dir='./gradio_outputs'):
372
 
373
  gr.Markdown("# 🎭 Text-to-Motion Generator")
374
  gr.Markdown("Generate 3D human motion animations from text descriptions")
375
-
376
- # Show CPU warning if applicable
377
- device_str = str(generator.device)
378
- if 'cpu' in device_str:
379
- gr.Markdown("""
380
- ### ⚠️ Performance Notice
381
- This Space is running on **CPU** (free tier). Generation takes **15-30 minutes** per prompt.
382
- Please be patient! For faster results (~30 seconds), upgrade to GPU in Space Settings.
383
- """)
384
- else:
385
- gr.Markdown(f"### ✅ Running on: {device_str.upper()}")
386
 
387
  with gr.Row():
388
  with gr.Column():
@@ -432,7 +387,7 @@ if __name__ == '__main__':
432
  model_name=MODEL_NAME,
433
  res_name=RES_NAME,
434
  vq_name=VQ_NAME,
435
- device='cuda'
436
  )
437
 
438
  # Create and launch Gradio interface
 
18
  clip_version = 'ViT-B/32'
19
 
20
  class MotionGenerator:
21
+ def __init__(self, checkpoints_dir, dataset_name, model_name, res_name, vq_name, device='auto'):
22
  self.device = torch.device(device if torch.cuda.is_available() else 'cpu')
23
  self.dataset_name = dataset_name
24
  self.dim_pose = 251 if dataset_name == 'kit' else 263
 
250
  def create_gradio_interface(generator, output_dir='./gradio_outputs'):
251
  os.makedirs(output_dir, exist_ok=True)
252
 
253
+ def generate_motion(text_prompt):
254
  try:
255
+ print(f"\nGenerating motion for: '{text_prompt}'")
 
 
 
 
256
  print(f"Device: {generator.device}")
 
257
 
258
  # Use default parameters for simplicity
259
  motion_length = 0 # Auto-estimate
 
265
  seed = 42
266
  use_ik = True
267
 
 
 
 
 
 
268
  # Generate motion
 
 
 
269
  joint, actual_length = generator.generate(
270
  text_prompt,
271
  motion_length,
 
277
  seed
278
  )
279
 
 
 
 
280
  # Save BVH and video
 
 
 
281
  timestamp = str(np.random.randint(100000))
282
  video_path = pjoin(output_dir, f'motion_{timestamp}.mp4')
283
 
 
286
  joint, filename=None, iterations=100, foot_ik=True
287
  )
288
 
 
 
289
  # Create video
 
 
 
290
  plot_3d_motion(video_path, generator.kinematic_chain, joint_processed,
291
  title=text_prompt, fps=20)
292
 
293
+ print(f"Video saved: {video_path}")
 
 
 
 
 
 
294
  return video_path
295
 
296
  except Exception as e:
297
  import traceback
298
  error_msg = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
 
 
 
299
  print(error_msg)
 
300
  return None
301
 
302
  # Create Gradio interface with Blocks for custom layout
 
338
 
339
  gr.Markdown("# 🎭 Text-to-Motion Generator")
340
  gr.Markdown("Generate 3D human motion animations from text descriptions")
 
 
 
 
 
 
 
 
 
 
 
341
 
342
  with gr.Row():
343
  with gr.Column():
 
387
  model_name=MODEL_NAME,
388
  res_name=RES_NAME,
389
  vq_name=VQ_NAME,
390
+ device='auto'
391
  )
392
 
393
  # Create and launch Gradio interface