Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
|
| 4 |
# Define available voices
|
| 5 |
voices = [
|
|
@@ -24,31 +23,42 @@ voices = [
|
|
| 24 |
def play_audio(file):
|
| 25 |
return f"voices/{file}"
|
| 26 |
|
| 27 |
-
# Custom CSS for
|
| 28 |
custom_css = """
|
| 29 |
h2 {
|
| 30 |
text-align: center;
|
| 31 |
color: #ffffff;
|
| 32 |
-
font-size:
|
| 33 |
margin-bottom: 20px;
|
| 34 |
}
|
| 35 |
body {
|
| 36 |
background-color: #121212;
|
| 37 |
font-family: Arial, sans-serif;
|
| 38 |
}
|
| 39 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
background: #1e1e1e;
|
| 41 |
-
border-radius:
|
| 42 |
padding: 15px;
|
| 43 |
-
margin-bottom: 20px;
|
| 44 |
text-align: center;
|
| 45 |
-
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.
|
| 46 |
-
}
|
| 47 |
-
.gr-column {
|
| 48 |
display: flex;
|
| 49 |
-
|
|
|
|
| 50 |
align-items: center;
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
.play-btn {
|
| 54 |
background-color: #FF5722 !important;
|
|
@@ -56,10 +66,12 @@ body {
|
|
| 56 |
border-radius: 50%;
|
| 57 |
width: 60px;
|
| 58 |
height: 60px;
|
| 59 |
-
font-size:
|
| 60 |
-
|
| 61 |
cursor: pointer;
|
|
|
|
| 62 |
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.2);
|
|
|
|
| 63 |
}
|
| 64 |
.play-btn:hover {
|
| 65 |
background-color: #ff8a50;
|
|
@@ -74,40 +86,41 @@ body {
|
|
| 74 |
}
|
| 75 |
.voice-info {
|
| 76 |
color: #ffffff;
|
| 77 |
-
text-align:
|
| 78 |
}
|
| 79 |
.voice-info b {
|
| 80 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
| 82 |
"""
|
| 83 |
|
| 84 |
-
# Create
|
| 85 |
with gr.Blocks(css=custom_css) as demo:
|
| 86 |
gr.Markdown("<h2>🎤 Human-Like Voices (Pro Plan)</h2>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
for i in range(0, len(voices), 3):
|
| 90 |
-
with gr.Row():
|
| 91 |
-
for j in range(3):
|
| 92 |
-
if i + j < len(voices):
|
| 93 |
-
voice = voices[i + j]
|
| 94 |
-
with gr.Column():
|
| 95 |
-
# Hidden Audio Component
|
| 96 |
-
audio = gr.Audio(play_audio(voice["file"]), autoplay=False, elem_id=voice["name"], visible=False)
|
| 97 |
-
# Play Button with FontAwesome Icon
|
| 98 |
-
btn = gr.Button("▶", elem_classes="play-btn")
|
| 99 |
-
# Voice Info (Name in Bold, Other Info Normal)
|
| 100 |
-
info = gr.Markdown(f"<div class='voice-info'><b>{voice['name']}</b><br>{voice['gender']} | {voice['country']}</div>")
|
| 101 |
-
|
| 102 |
-
def start_animation():
|
| 103 |
-
return gr.update(elem_classes="playing")
|
| 104 |
-
|
| 105 |
-
def stop_animation():
|
| 106 |
-
return gr.update(elem_classes="")
|
| 107 |
-
|
| 108 |
-
btn.click(fn=play_audio, inputs=[], outputs=[audio])
|
| 109 |
-
btn.click(fn=start_animation, inputs=[], outputs=[btn])
|
| 110 |
-
audio.change(fn=stop_animation, inputs=[], outputs=[btn])
|
| 111 |
-
|
| 112 |
-
# Launch the app
|
| 113 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
# Define available voices
|
| 4 |
voices = [
|
|
|
|
| 23 |
def play_audio(file):
|
| 24 |
return f"voices/{file}"
|
| 25 |
|
| 26 |
+
# Custom CSS for better design and responsiveness
|
| 27 |
custom_css = """
|
| 28 |
h2 {
|
| 29 |
text-align: center;
|
| 30 |
color: #ffffff;
|
| 31 |
+
font-size: 26px;
|
| 32 |
margin-bottom: 20px;
|
| 33 |
}
|
| 34 |
body {
|
| 35 |
background-color: #121212;
|
| 36 |
font-family: Arial, sans-serif;
|
| 37 |
}
|
| 38 |
+
.voice-container {
|
| 39 |
+
display: grid;
|
| 40 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 41 |
+
gap: 15px;
|
| 42 |
+
padding: 20px;
|
| 43 |
+
}
|
| 44 |
+
.voice-box {
|
| 45 |
background: #1e1e1e;
|
| 46 |
+
border-radius: 12px;
|
| 47 |
padding: 15px;
|
|
|
|
| 48 |
text-align: center;
|
| 49 |
+
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.3);
|
|
|
|
|
|
|
| 50 |
display: flex;
|
| 51 |
+
flex-direction: column;
|
| 52 |
+
justify-content: center;
|
| 53 |
align-items: center;
|
| 54 |
+
width: 100%;
|
| 55 |
+
max-width: 220px;
|
| 56 |
+
height: 220px;
|
| 57 |
+
margin: auto;
|
| 58 |
+
transition: transform 0.2s ease-in-out;
|
| 59 |
+
}
|
| 60 |
+
.voice-box:hover {
|
| 61 |
+
transform: scale(1.05);
|
| 62 |
}
|
| 63 |
.play-btn {
|
| 64 |
background-color: #FF5722 !important;
|
|
|
|
| 66 |
border-radius: 50%;
|
| 67 |
width: 60px;
|
| 68 |
height: 60px;
|
| 69 |
+
font-size: 26px;
|
| 70 |
+
border: none;
|
| 71 |
cursor: pointer;
|
| 72 |
+
margin-bottom: 10px;
|
| 73 |
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.2);
|
| 74 |
+
transition: background 0.3s ease-in-out;
|
| 75 |
}
|
| 76 |
.play-btn:hover {
|
| 77 |
background-color: #ff8a50;
|
|
|
|
| 86 |
}
|
| 87 |
.voice-info {
|
| 88 |
color: #ffffff;
|
| 89 |
+
text-align: center;
|
| 90 |
}
|
| 91 |
.voice-info b {
|
| 92 |
font-weight: bold;
|
| 93 |
+
font-size: 16px;
|
| 94 |
+
}
|
| 95 |
+
.voice-info span {
|
| 96 |
+
font-size: 14px;
|
| 97 |
+
color: #bbbbbb;
|
| 98 |
}
|
| 99 |
"""
|
| 100 |
|
| 101 |
+
# Create Gradio UI
|
| 102 |
with gr.Blocks(css=custom_css) as demo:
|
| 103 |
gr.Markdown("<h2>🎤 Human-Like Voices (Pro Plan)</h2>")
|
| 104 |
+
|
| 105 |
+
with gr.Column(elem_classes="voice-container"):
|
| 106 |
+
for voice in voices:
|
| 107 |
+
with gr.Column(elem_classes="voice-box"):
|
| 108 |
+
# Hidden Audio Component
|
| 109 |
+
audio = gr.Audio(play_audio(voice["file"]), autoplay=False, elem_id=voice["name"], visible=False)
|
| 110 |
+
# Round Play Button
|
| 111 |
+
btn = gr.Button("▶", elem_classes="play-btn")
|
| 112 |
+
# Voice Details (Name in Bold, Other Info Below)
|
| 113 |
+
info = gr.Markdown(f"<div class='voice-info'><b>{voice['name']}</b><br><span>{voice['gender']} | {voice['country']}</span></div>")
|
| 114 |
+
|
| 115 |
+
def start_animation():
|
| 116 |
+
return gr.update(elem_classes="playing")
|
| 117 |
+
|
| 118 |
+
def stop_animation():
|
| 119 |
+
return gr.update(elem_classes="")
|
| 120 |
+
|
| 121 |
+
btn.click(fn=play_audio, inputs=[], outputs=[audio])
|
| 122 |
+
btn.click(fn=start_animation, inputs=[], outputs=[btn])
|
| 123 |
+
audio.change(fn=stop_animation, inputs=[], outputs=[btn])
|
| 124 |
|
| 125 |
+
# Launch App
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
demo.launch()
|