farazmoradi98 commited on
Commit
a971d4b
·
verified ·
1 Parent(s): 39064bf

Add custom handler for TTS inference

Browse files
Files changed (1) hide show
  1. handler.py +8 -4
handler.py CHANGED
@@ -70,11 +70,15 @@ class EndpointHandler:
70
  if isinstance(out, np.ndarray):
71
  audio = out
72
  elif isinstance(out, list):
73
- # If output is a list, take the first element
74
- audio = np.array(out[0]) if len(out) > 0 else np.array(out)
 
 
 
 
75
  elif hasattr(out, 'cpu'):
76
- # If it's a tensor, convert to numpy
77
- audio = out.cpu().numpy()
78
  else:
79
  # Fallback: try to convert to numpy array
80
  audio = np.array(out)
 
70
  if isinstance(out, np.ndarray):
71
  audio = out
72
  elif isinstance(out, list):
73
+ # If output is a list, take the first element and handle it
74
+ first_item = out[0] if len(out) > 0 else out
75
+ if hasattr(first_item, 'cpu'):
76
+ audio = first_item.cpu().numpy()
77
+ else:
78
+ audio = np.array(first_item)
79
  elif hasattr(out, 'cpu'):
80
+ # If it's a tensor (including CUDA tensors), move to CPU and convert to numpy
81
+ audio = out.detach().cpu().numpy()
82
  else:
83
  # Fallback: try to convert to numpy array
84
  audio = np.array(out)