Awaz-e-Sehat commited on
Commit
bc9659c
1 Parent(s): 46a4bf6

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +35 -0
handler.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from transformers import pipeline
3
+ import faster_whisper
4
+ import json
5
+ import logging
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ class EndpointHandler():
10
+ def __init__(self, path=""):
11
+ self.model = faster_whisper.WhisperModel(path, device = "cuda")
12
+ logger.info("Model initialized")
13
+
14
+ def __call__(self, data: Any) -> str:
15
+ """
16
+ data args:
17
+ inputs (:obj: `str`)
18
+ date (:obj: `str`)
19
+ Return:
20
+ A :obj:`list` | `dict`: will be serialized and returned
21
+ """
22
+ # get inputs
23
+ logger.info("In inference")
24
+ logger.info(data)
25
+ inputs = data.pop("inputs",data)
26
+ logger.info("Data pop")
27
+ logger.info(inputs)
28
+ segments, _ = self.model.transcribe(inputs, language = "ur", task = "transcribe")
29
+ logger.info("model transcribe")
30
+ segments = list(segments)
31
+ logger.info("Actual transcribed")
32
+ prediction = ''
33
+ for i in segments:
34
+ prediction += i[4]
35
+ return prediction