|
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 |
|
""" |
|
|
|
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 |