File size: 1,056 Bytes
bc9659c |
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 26 27 28 29 30 31 32 33 34 35 |
from typing import Dict, List, Any
from transformers import pipeline
import faster_whisper
import json
import logging
logger = logging.getLogger(__name__)
class EndpointHandler():
def __init__(self, path=""):
self.model = faster_whisper.WhisperModel(path, device = "cuda")
logger.info("Model initialized")
def __call__(self, data: Any) -> str:
"""
data args:
inputs (:obj: `str`)
date (:obj: `str`)
Return:
A :obj:`list` | `dict`: will be serialized and returned
"""
# get inputs
logger.info("In inference")
logger.info(data)
inputs = data.pop("inputs",data)
logger.info("Data pop")
logger.info(inputs)
segments, _ = self.model.transcribe(inputs, language = "ur", task = "transcribe")
logger.info("model transcribe")
segments = list(segments)
logger.info("Actual transcribed")
prediction = ''
for i in segments:
prediction += i[4]
return prediction |