Update handler.py
Browse files- handler.py +30 -2
handler.py
CHANGED
|
@@ -4,6 +4,9 @@ import torch
|
|
| 4 |
import soundfile as sf
|
| 5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
| 6 |
import cloudinary.uploader
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Configure logging
|
| 9 |
logging.basicConfig(level=logging.DEBUG)
|
|
@@ -18,7 +21,7 @@ class EndpointHandler():
|
|
| 18 |
|
| 19 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
| 20 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
| 21 |
-
|
| 22 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 23 |
# Prepare the payload with input data
|
| 24 |
logging.warning(f"------input_data-- {str(data)}")
|
|
@@ -34,6 +37,7 @@ class EndpointHandler():
|
|
| 34 |
# Save the audio to a file
|
| 35 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
| 36 |
uploadGraphFile("StoryAudio.wav")
|
|
|
|
| 37 |
#return 'StoryAudio.wav'
|
| 38 |
# Check if the request was successful
|
| 39 |
|
|
@@ -46,4 +50,28 @@ def uploadGraphFile(fileName):
|
|
| 46 |
)
|
| 47 |
# Upload a file to Cloudinary
|
| 48 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
| 49 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import soundfile as sf
|
| 5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
| 6 |
import cloudinary.uploader
|
| 7 |
+
import tkinter as tk
|
| 8 |
+
from tkinter import ttk
|
| 9 |
+
import pygame
|
| 10 |
|
| 11 |
# Configure logging
|
| 12 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
| 21 |
|
| 22 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
| 23 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
| 24 |
+
pygame.init()
|
| 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 |
# 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 |
+
playAudio()
|
| 41 |
#return 'StoryAudio.wav'
|
| 42 |
# Check if the request was successful
|
| 43 |
|
|
|
|
| 50 |
)
|
| 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()
|