eventhorizon28 commited on
Commit
afac378
·
verified ·
1 Parent(s): e74c06a

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +37 -0
handler.py CHANGED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, AutoTokenizer
2
+
3
+ from transformers import pipeline
4
+ import scipy
5
+
6
+ model_id = "eventhorizon28/195000_2"
7
+ synthesiser = pipeline("text-to-speech", model_id, device=0) # add device=0 if you want to use a GPU
8
+
9
+ speech = synthesiser("आदरणीय उपस्थित मंडळी, माझ्या भगिनींनो आणि बंधूंनो... आज आपण या आरोग्य संमेलनात एकत्र आलो आहोत, एक महत्त्वाचा संदेश घेऊन. आपल्या जीवनात आरोग्याचा किती महत्त्वाचा भाग आहे, हे आपणा सर्वांना माहीत आहे. आपण सशक्त असलो, तरच आपले घर, आपला समाज, आणि आपला देश मजबूत होऊ शकतो. म्हणूनच आज मी तुम्हा सर्वांशी आरोग्यासंबंधी काही महत्त्वाच्या गोष्टी शेअर करू इच्छिते.")
10
+
11
+ scipy.io.wavfile.write("finetuned_output_5.wav", rate=speech["sampling_rate"], data=speech["audio"][0])
12
+
13
+ class EndpointHandler():
14
+ def __init__(self, path=""):
15
+ # create inference pipeline
16
+ self.pipeline = pipeline("text-to-speech", path)
17
+
18
+ def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
19
+ """
20
+ Args:
21
+ data (:obj:):
22
+ includes the input data and the parameters for the inference.
23
+ Return:
24
+ A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
25
+ - "label": A string representing what the label/class is. There can be multiple labels.
26
+ - "score": A score between 0 and 1 describing how confident the model is for this label/class.
27
+ """
28
+ inputs = data.pop("inputs", data)
29
+ parameters = data.pop("parameters", None)
30
+
31
+ # pass inputs with all kwargs in data
32
+ if parameters is not None:
33
+ prediction = self.pipeline(inputs, **parameters)
34
+ else:
35
+ prediction = self.pipeline(inputs)
36
+ # postprocess the prediction
37
+ return prediction