rdz-falcon commited on
Commit
625c5a9
·
verified ·
1 Parent(s): 7ebdb96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -1,7 +1,7 @@
1
  """
2
  SignMotionGPT - HuggingFace Spaces Demo
3
  Text-to-Sign Language Motion Generation
4
-
5
  """
6
  # IMPORTANT: Set OpenGL platform BEFORE any OpenGL imports (for headless rendering)
7
  import os
@@ -474,40 +474,34 @@ def params_to_vertices(params_seq: np.ndarray) -> tuple:
474
  # root_pose is separate as global_orient (3 dims)
475
  body_t = tensor_parts['body_pose']
476
  L_body = body_t.shape[1]
477
- expected_body = num_body_joints * 3 # 21 * 3 = 63
 
478
 
479
- if L_body >= expected_body:
480
- body_pose_only = body_t[:, :expected_body].contiguous()
 
 
 
 
481
  else:
482
- # Pad if needed
483
- pad_len = expected_body - L_body
484
- body_pose_only = F.pad(body_t, (0, pad_len))
 
 
 
485
 
486
- # Call SMPL-X with correct parameter mapping:
487
- # - shape -> betas
488
- # - root_pose -> global_orient
489
- # - lhand_pose/rhand_pose -> left/right_hand_pose
490
- # - jaw_pose -> jaw_pose (controls mouth/lower face!)
491
- # - cam_trans -> transl
492
- # - eye poses set to zero (not in our data format)
493
  out = smplx_model(
494
- betas=tensor_parts['shape'],
495
- global_orient=tensor_parts['root_pose'],
496
- body_pose=body_pose_only,
497
- left_hand_pose=tensor_parts['lhand_pose'],
498
- right_hand_pose=tensor_parts['rhand_pose'],
499
- expression=tensor_parts['expression'],
500
- jaw_pose=tensor_parts['jaw_pose'],
501
- leye_pose=torch.zeros((B, 3), dtype=torch.float32, device=DEVICE),
502
- reye_pose=torch.zeros((B, 3), dtype=torch.float32, device=DEVICE),
503
- transl=tensor_parts['cam_trans'],
504
- return_verts=True
505
  )
506
  all_verts.append(out.vertices.detach().cpu().numpy())
507
 
508
  return np.concatenate(all_verts, axis=0), smplx_model.faces.astype(np.int32)
509
 
510
-
511
  # =====================================================================
512
  # PyRender Visualization Functions
513
  # =====================================================================
 
1
  """
2
  SignMotionGPT - HuggingFace Spaces Demo
3
  Text-to-Sign Language Motion Generation
4
+ Uses PyRender for high-quality avatar visualization
5
  """
6
  # IMPORTANT: Set OpenGL platform BEFORE any OpenGL imports (for headless rendering)
7
  import os
 
474
  # root_pose is separate as global_orient (3 dims)
475
  body_t = tensor_parts['body_pose']
476
  L_body = body_t.shape[1]
477
+ expected_no_go = num_body_joints * 3
478
+ expected_with_go = (num_body_joints + 1) * 3
479
 
480
+ if L_body == expected_with_go:
481
+ global_orient = body_t[:, :3].contiguous()
482
+ body_pose_only = body_t[:, 3:].contiguous()
483
+ elif L_body == expected_no_go:
484
+ global_orient = torch.zeros((B, 3), dtype=torch.float32, device=DEVICE)
485
+ body_pose_only = body_t
486
  else:
487
+ if L_body > expected_no_go:
488
+ global_orient = body_t[:, :3].contiguous()
489
+ body_pose_only = body_t[:, 3:].contiguous()
490
+ else:
491
+ body_pose_only = F.pad(body_t, (0, max(0, expected_no_go - L_body)))
492
+ global_orient = torch.zeros((B, 3), dtype=torch.float32, device=DEVICE)
493
 
 
 
 
 
 
 
 
494
  out = smplx_model(
495
+ betas=tensor_parts['betas'], global_orient=global_orient, body_pose=body_pose_only,
496
+ left_hand_pose=tensor_parts['left_hand_pose'], right_hand_pose=tensor_parts['right_hand_pose'],
497
+ expression=tensor_parts['expression'], jaw_pose=tensor_parts['jaw_pose'],
498
+ leye_pose=tensor_parts['eye_pose'], reye_pose=tensor_parts['eye_pose'],
499
+ transl=tensor_parts['trans'], return_verts=True
 
 
 
 
 
 
500
  )
501
  all_verts.append(out.vertices.detach().cpu().numpy())
502
 
503
  return np.concatenate(all_verts, axis=0), smplx_model.faces.astype(np.int32)
504
 
 
505
  # =====================================================================
506
  # PyRender Visualization Functions
507
  # =====================================================================