gautamtata commited on
Commit
e334f76
1 Parent(s): 9705ce9

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +17 -11
handler.py CHANGED
@@ -162,15 +162,21 @@ class EndpointHandler():
162
  else:
163
  return None
164
 
165
- def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
166
- """
167
- The actual method called during inference. Expects data to have a 'path' to the audio file.
168
- """
169
- # Get the path to the audio file from the request data
170
- path = data.get("path")
171
-
172
- # If the path is provided, we run the prediction, else return an error message
173
- if path:
174
- return self.predict(path)
 
 
 
 
 
 
175
  else:
176
- return {"error": "Path to the audio file is required."}
 
162
  else:
163
  return None
164
 
165
+ def __call__(self, request: Dict[str, Any]) -> List[Dict[str, Any]]:
166
+ # Get the binary content of the audio file (assuming it is passed as 'inputs')
167
+ audio_data = request.get("inputs")
168
+
169
+ if audio_data:
170
+ # Convert binary content to a bytes buffer
171
+ audio_buffer = io.BytesIO(audio_data)
172
+
173
+ # However, since this handler is not loading from a path (as it does in speech_file_to_array_fn),
174
+ # we need to read and process the buffer similar to how speech_file_to_array_fn would
175
+ waveform, sample_rate = torchaudio.load(audio_buffer)
176
+ waveform = waveform.squeeze().numpy()
177
+
178
+ # Call the predict function and return its results
179
+ predictions = self.predict(waveform, sample_rate)
180
+ return predictions
181
  else:
182
+ return {"error": "Audio input is required."}