Update app.py
Browse files
app.py
CHANGED
|
@@ -24,9 +24,44 @@ voices = [
|
|
| 24 |
def play_audio(file):
|
| 25 |
return f"voices/{file}"
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Create layout
|
| 28 |
-
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("<h2
|
| 30 |
|
| 31 |
# Grid layout (3 columns, 5 rows)
|
| 32 |
for i in range(0, len(voices), 3):
|
|
@@ -36,9 +71,18 @@ with gr.Blocks() as demo:
|
|
| 36 |
voice = voices[i + j]
|
| 37 |
with gr.Column():
|
| 38 |
audio = gr.Audio(play_audio(voice["file"]), autoplay=False, elem_id=voice["name"])
|
| 39 |
-
btn = gr.Button(f"▶
|
| 40 |
info = gr.Markdown(f"**{voice['name']}**<br>{voice['gender']} | {voice['country']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
btn.click(fn=play_audio, inputs=[], outputs=[audio])
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Launch the app
|
| 44 |
demo.launch()
|
|
|
|
| 24 |
def play_audio(file):
|
| 25 |
return f"voices/{file}"
|
| 26 |
|
| 27 |
+
# Custom CSS for styling and animations
|
| 28 |
+
custom_css = """
|
| 29 |
+
h2 {
|
| 30 |
+
text-align: center;
|
| 31 |
+
color: #ffffff;
|
| 32 |
+
font-size: 24px;
|
| 33 |
+
margin-bottom: 20px;
|
| 34 |
+
}
|
| 35 |
+
body {
|
| 36 |
+
background-color: #121212;
|
| 37 |
+
font-family: Arial, sans-serif;
|
| 38 |
+
}
|
| 39 |
+
.gr-box {
|
| 40 |
+
background: #1e1e1e;
|
| 41 |
+
border-radius: 10px;
|
| 42 |
+
padding: 15px;
|
| 43 |
+
text-align: center;
|
| 44 |
+
}
|
| 45 |
+
.play-btn {
|
| 46 |
+
background-color: #FF5722 !important;
|
| 47 |
+
color: white;
|
| 48 |
+
border-radius: 50px;
|
| 49 |
+
width: 100px;
|
| 50 |
+
height: 40px;
|
| 51 |
+
font-size: 14px;
|
| 52 |
+
}
|
| 53 |
+
.playing {
|
| 54 |
+
animation: pulse 1s infinite alternate;
|
| 55 |
+
}
|
| 56 |
+
@keyframes pulse {
|
| 57 |
+
0% { transform: scale(1); }
|
| 58 |
+
100% { transform: scale(1.1); }
|
| 59 |
+
}
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
# Create layout
|
| 63 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 64 |
+
gr.Markdown("<h2>🎤 Human-Like Voices (Pro Plan)</h2>")
|
| 65 |
|
| 66 |
# Grid layout (3 columns, 5 rows)
|
| 67 |
for i in range(0, len(voices), 3):
|
|
|
|
| 71 |
voice = voices[i + j]
|
| 72 |
with gr.Column():
|
| 73 |
audio = gr.Audio(play_audio(voice["file"]), autoplay=False, elem_id=voice["name"])
|
| 74 |
+
btn = gr.Button(f"▶ {voice['name']}", elem_classes="play-btn")
|
| 75 |
info = gr.Markdown(f"**{voice['name']}**<br>{voice['gender']} | {voice['country']}")
|
| 76 |
+
|
| 77 |
+
def start_animation():
|
| 78 |
+
return gr.update(elem_classes="playing")
|
| 79 |
+
|
| 80 |
+
def stop_animation():
|
| 81 |
+
return gr.update(elem_classes="")
|
| 82 |
+
|
| 83 |
btn.click(fn=play_audio, inputs=[], outputs=[audio])
|
| 84 |
+
btn.click(fn=start_animation, inputs=[], outputs=[btn])
|
| 85 |
+
audio.change(fn=stop_animation, inputs=[], outputs=[btn])
|
| 86 |
|
| 87 |
# Launch the app
|
| 88 |
demo.launch()
|