File size: 718 Bytes
0156247 5210503 fa05e9e be86be9 0156247 5210503 4fbac8b be86be9 5210503 be86be9 73c9e39 be86be9 9176a6a 5210503 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import logging
from speechbrain.pretrained import EncoderClassifier
from typing import Dict, List, Any
class EndpointHandler:
def __init__(self, path=""):
self.model = EncoderClassifier.from_hparams("speechbrain/lang-id-voxlingua107-ecapa")
print('model loaded')
logging.info('model loaded')
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
inputs = data.pop("inputs",data)
print('audio_url', inputs)
logging.info(f'audio_url {inputs}')
# run normal prediction
output = self.model.classify_file(inputs)
return {
"prediction": float(output[1].exp()[0]),
"language": output[3][0],
}
|