Commit
•
0af51be
1
Parent(s):
e4ab0b1
Update handler.py
Browse files- handler.py +3 -29
handler.py
CHANGED
@@ -4,9 +4,7 @@ import torch
|
|
4 |
import soundfile as sf
|
5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
6 |
import cloudinary.uploader
|
7 |
-
|
8 |
-
import pygame
|
9 |
-
import tkinter as tk
|
10 |
|
11 |
# Configure logging
|
12 |
logging.basicConfig(level=logging.DEBUG)
|
@@ -21,7 +19,7 @@ class EndpointHandler():
|
|
21 |
|
22 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
23 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
24 |
-
|
25 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
26 |
# Prepare the payload with input data
|
27 |
logging.warning(f"------input_data-- {str(data)}")
|
@@ -37,7 +35,7 @@ class EndpointHandler():
|
|
37 |
# Save the audio to a file
|
38 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
39 |
uploadGraphFile("StoryAudio.wav")
|
40 |
-
|
41 |
#return 'StoryAudio.wav'
|
42 |
# Check if the request was successful
|
43 |
|
@@ -51,27 +49,3 @@ def uploadGraphFile(fileName):
|
|
51 |
# Upload a file to Cloudinary
|
52 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
53 |
return result
|
54 |
-
|
55 |
-
def play_audio():
|
56 |
-
pygame.mixer.music.load("StoryAudio.wav")
|
57 |
-
pygame.mixer.music.play()
|
58 |
-
|
59 |
-
def stop_audio():
|
60 |
-
pygame.mixer.music.stop()
|
61 |
-
|
62 |
-
def playAudio():
|
63 |
-
root = tk.Tk()
|
64 |
-
root.title("Audio Player")
|
65 |
-
|
66 |
-
# Create a play button
|
67 |
-
play_button = tk.Button(root, text="Play", command=play_audio)
|
68 |
-
play_button.pack()
|
69 |
-
|
70 |
-
# Create a stop button
|
71 |
-
stop_button = tk.Button(root, text="Stop", command=stop_audio)
|
72 |
-
stop_button.pack()
|
73 |
-
|
74 |
-
# Create a progress bar
|
75 |
-
progress_bar = ttk.Progressbar(root, orient="horizontal", length=200, mode="determinate")
|
76 |
-
progress_bar.pack()
|
77 |
-
root.mainloop()
|
|
|
4 |
import soundfile as sf
|
5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
6 |
import cloudinary.uploader
|
7 |
+
|
|
|
|
|
8 |
|
9 |
# Configure logging
|
10 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
19 |
|
20 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
21 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
22 |
+
|
23 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
24 |
# Prepare the payload with input data
|
25 |
logging.warning(f"------input_data-- {str(data)}")
|
|
|
35 |
# Save the audio to a file
|
36 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
37 |
uploadGraphFile("StoryAudio.wav")
|
38 |
+
|
39 |
#return 'StoryAudio.wav'
|
40 |
# Check if the request was successful
|
41 |
|
|
|
49 |
# Upload a file to Cloudinary
|
50 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
51 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|