Commit ·
e334f76
1
Parent(s): 9705ce9
Update handler.py
Browse files- handler.py +17 -11
handler.py
CHANGED
|
@@ -162,15 +162,21 @@ class EndpointHandler():
|
|
| 162 |
else:
|
| 163 |
return None
|
| 164 |
|
| 165 |
-
def __call__(self,
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
else:
|
| 176 |
-
return {"error": "
|
|
|
|
| 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."}
|