jonathanagustin commited on
Commit
1a29ae8
1 Parent(s): e847c01

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -3,6 +3,7 @@ import tempfile
3
  import openai
4
  import requests
5
  import os
 
6
 
7
 
8
  def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
@@ -104,20 +105,25 @@ def main():
104
 
105
  # Wrap the voice previews inside an Accordion that is closed by default
106
  with gr.Accordion(label="Voice Previews", open=False):
 
 
 
 
 
107
  for voice in VOICE_OPTIONS:
108
- # Use the relative path for the audio file
109
- audio_url = f"file/{PREVIEW_DIR}/{voice}.wav"
110
- # Create an HTML audio player with minimal controls
111
- html_snippet = f'''
112
- <div>
113
- <p><strong>{voice.capitalize()}</strong></p>
114
- <audio controls preload="auto">
115
- <source src="{audio_url}" type="audio/wav">
116
- Your browser does not support the audio element.
117
- </audio>
118
- </div>
119
- '''
120
- gr.HTML(html_snippet)
121
 
122
  with gr.Column(scale=2):
123
  input_textbox = gr.Textbox(
 
3
  import openai
4
  import requests
5
  import os
6
+ from functools import partial
7
 
8
 
9
  def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
 
105
 
106
  # Wrap the voice previews inside an Accordion that is closed by default
107
  with gr.Accordion(label="Voice Previews", open=False):
108
+ # Create an audio component to play the samples
109
+ preview_audio = gr.Audio(
110
+ interactive=False, label="Preview Audio", value=None
111
+ )
112
+
113
  for voice in VOICE_OPTIONS:
114
+ # Create a button for each voice
115
+ voice_button = gr.Button(
116
+ value=f"▶ {voice.capitalize()}", variant="secondary"
117
+ )
118
+
119
+ # Define the handler function for this voice using partial
120
+ def play_voice_sample(voice):
121
+ return VOICE_PREVIEW_FILES[voice]
122
+
123
+ voice_handler = partial(play_voice_sample, voice)
124
+
125
+ # Attach the click handler
126
+ voice_button.click(fn=voice_handler, outputs=preview_audio)
127
 
128
  with gr.Column(scale=2):
129
  input_textbox = gr.Textbox(