jonathanagustin commited on
Commit
ce4caa3
1 Parent(s): c3b1e7e

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -3,8 +3,6 @@ import tempfile
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:
10
  """
@@ -52,7 +50,6 @@ def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
52
 
53
  return temp_file_path
54
 
55
-
56
  def main():
57
  """
58
  Main function to create and launch the Gradio interface.
@@ -107,33 +104,38 @@ def main():
107
  value="echo",
108
  )
109
 
110
- # Wrap the voice previews inside an Accordion that is closed by default
111
- with gr.Accordion(label="Voice Previews", open=False):
 
 
112
  # Create an audio component to play the samples
113
  preview_audio = gr.Audio(
114
  interactive=False,
115
  label="Preview Audio",
116
  value=None,
117
- visible=False,
118
  autoplay=True,
119
  )
120
 
121
- for voice in VOICE_OPTIONS:
122
- # Create a button for each voice
123
- voice_button = gr.Button(
124
- value=f"▶ {voice.capitalize()}",
125
- variant="secondary",
126
- size="sm",
127
- )
128
-
129
- # Define the handler function for this voice using partial
130
- def play_voice_sample(voice):
131
- return VOICE_PREVIEW_FILES[voice]
132
-
133
- voice_handler = partial(play_voice_sample, voice)
134
-
135
- # Attach the click handler
136
- voice_button.click(fn=voice_handler, outputs=preview_audio)
 
 
 
137
 
138
  with gr.Column(scale=2):
139
  input_textbox = gr.Textbox(
@@ -163,6 +165,5 @@ def main():
163
  # Launch the Gradio app with error display enabled
164
  demo.launch(show_error=True)
165
 
166
-
167
  if __name__ == "__main__":
168
- main()
 
3
  import openai
4
  import requests
5
  import os
 
 
6
 
7
  def tts(input_text: str, model: str, voice: str, api_key: str) -> str:
8
  """
 
50
 
51
  return temp_file_path
52
 
 
53
  def main():
54
  """
55
  Main function to create and launch the Gradio interface.
 
104
  value="echo",
105
  )
106
 
107
+ # Replace the Accordion with a Group for Voice Previews
108
+ with gr.Group():
109
+ gr.Markdown("### Voice Previews")
110
+
111
  # Create an audio component to play the samples
112
  preview_audio = gr.Audio(
113
  interactive=False,
114
  label="Preview Audio",
115
  value=None,
116
+ visible=True,
117
  autoplay=True,
118
  )
119
 
120
+ # A function to update the preview_audio component
121
+ def play_voice_sample(voice):
122
+ return gr.update(value=VOICE_PREVIEW_FILES[voice])
123
+
124
+ # Create buttons for each voice inside a grid
125
+ with gr.Grid():
126
+ for voice in VOICE_OPTIONS:
127
+ # Create a button for each voice
128
+ voice_button = gr.Button(
129
+ value=f"{voice.capitalize()}",
130
+ variant="secondary",
131
+ size="sm",
132
+ )
133
+
134
+ # Attach the click handler
135
+ voice_button.click(
136
+ fn=lambda v=voice: play_voice_sample(v),
137
+ outputs=preview_audio,
138
+ )
139
 
140
  with gr.Column(scale=2):
141
  input_textbox = gr.Textbox(
 
165
  # Launch the Gradio app with error display enabled
166
  demo.launch(show_error=True)
167
 
 
168
  if __name__ == "__main__":
169
+ main()