hivecorp commited on
Commit
5efe19e
·
verified ·
1 Parent(s): 7eef922

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -18,8 +18,9 @@ def toggle_audio(file):
18
 
19
  # If playing, return file path; otherwise, return None to stop audio
20
  return (
21
- gr.update(value=file if playing_states[file] else None),
22
- gr.update(elem_classes="play-btn playing" if playing_states[file] else "play-btn"),
 
23
  )
24
 
25
  # Custom CSS for styling
@@ -118,14 +119,14 @@ with gr.Blocks(css=custom_css) as demo:
118
  for voice in voices:
119
  with gr.Column(elem_classes="voice-box"):
120
  # Audio Component (Hidden, Dynamic Source)
121
- audio = gr.Audio(None, autoplay=True, elem_id=voice["name"], visible=False)
122
  # Play Button
123
- btn = gr.Button("", elem_classes="play-btn")
124
  # Voice Details
125
  info = gr.Markdown(f"<div class='voice-info'><b>{voice['name']}</b><br><span>{voice['gender']} | {voice['country']}</span></div>")
126
 
127
  # Play/Pause Click Event
128
- btn.click(fn=toggle_audio, inputs=[], outputs=[audio, btn], _js="() => {}")
129
 
130
  # Launch App
131
  demo.launch()
 
18
 
19
  # If playing, return file path; otherwise, return None to stop audio
20
  return (
21
+ file if playing_states[file] else None,
22
+ "⏹️" if playing_states[file] else "▶️", # Change button icon
23
+ "play-btn playing" if playing_states[file] else "play-btn",
24
  )
25
 
26
  # Custom CSS for styling
 
119
  for voice in voices:
120
  with gr.Column(elem_classes="voice-box"):
121
  # Audio Component (Hidden, Dynamic Source)
122
+ audio = gr.Audio(visible=False)
123
  # Play Button
124
+ btn = gr.Button("▶️", elem_classes="play-btn")
125
  # Voice Details
126
  info = gr.Markdown(f"<div class='voice-info'><b>{voice['name']}</b><br><span>{voice['gender']} | {voice['country']}</span></div>")
127
 
128
  # Play/Pause Click Event
129
+ btn.click(fn=toggle_audio, inputs=[gr.State(voice["file"])], outputs=[audio, btn, btn])
130
 
131
  # Launch App
132
  demo.launch()