File size: 771 Bytes
fe8b90f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ad414b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from typing import Dict, List, Any
from transformers import pipeline
import torch

class EndpointHandler():
    def __init__(self, path=""):
        device = 0 if torch.cuda.is_available() else "cpu"
        self.pipe = pipeline(
            task="automatic-speech-recognition",
            model=path,
            chunk_length_s=30,
            device=device,
        )

        self.pipe.model.config.forced_decoder_ids = self.pipe.tokenizer.get_decoder_prompt_ids(language="turkish", task="transcribe")

    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        inputs = data.pop("inputs",data)
        prediction = self.pipe(inputs, return_timestamps=False, generate_kwargs={"language": "turkish", "task": "transcribe"})
        return prediction