Spaces:
Running
Running
jonathanagustin
commited on
Commit
•
f43c5ad
1
Parent(s):
395c331
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import tempfile
|
3 |
import openai
|
|
|
4 |
|
5 |
def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
|
6 |
"""
|
@@ -55,6 +56,11 @@ def main():
|
|
55 |
MODEL_OPTIONS = ["tts-1", "tts-1-hd"]
|
56 |
VOICE_OPTIONS = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
with gr.Blocks() as demo:
|
59 |
with gr.Row():
|
60 |
with gr.Column(scale=1):
|
@@ -70,6 +76,21 @@ def main():
|
|
70 |
voice_dropdown = gr.Dropdown(
|
71 |
choices=VOICE_OPTIONS, label="Voice Options", value="echo"
|
72 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
with gr.Column(scale=2):
|
74 |
input_textbox = gr.Textbox(
|
75 |
label="Input Text",
|
|
|
1 |
import gradio as gr
|
2 |
import tempfile
|
3 |
import openai
|
4 |
+
import requests
|
5 |
|
6 |
def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
|
7 |
"""
|
|
|
56 |
MODEL_OPTIONS = ["tts-1", "tts-1-hd"]
|
57 |
VOICE_OPTIONS = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
|
58 |
|
59 |
+
# Predefine voice previews URLs
|
60 |
+
VOICE_PREVIEWS = {
|
61 |
+
voice: f"https://cdn.openai.com/API/docs/audio/{voice}.wav" for voice in VOICE_OPTIONS
|
62 |
+
}
|
63 |
+
|
64 |
with gr.Blocks() as demo:
|
65 |
with gr.Row():
|
66 |
with gr.Column(scale=1):
|
|
|
76 |
voice_dropdown = gr.Dropdown(
|
77 |
choices=VOICE_OPTIONS, label="Voice Options", value="echo"
|
78 |
)
|
79 |
+
|
80 |
+
# Add voice previews
|
81 |
+
gr.Markdown("### Voice Previews")
|
82 |
+
for voice in VOICE_OPTIONS:
|
83 |
+
gr.Markdown(f"**{voice.capitalize()}**")
|
84 |
+
audio_url = VOICE_PREVIEWS[voice]
|
85 |
+
# Fetch the audio data
|
86 |
+
try:
|
87 |
+
response = requests.get(audio_url)
|
88 |
+
response.raise_for_status()
|
89 |
+
audio_data = response.content
|
90 |
+
gr.Audio(value=audio_data, label=f"{voice.capitalize()} Sample", autoplay=False)
|
91 |
+
except requests.exceptions.RequestException as e:
|
92 |
+
gr.Markdown(f"Could not load preview for {voice.capitalize()}: {e}")
|
93 |
+
|
94 |
with gr.Column(scale=2):
|
95 |
input_textbox = gr.Textbox(
|
96 |
label="Input Text",
|