Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -103,14 +103,67 @@ def process_audio(audio_file, target_language):
|
|
103 |
|
104 |
return None, transcription, translated_text, audio_output
|
105 |
|
106 |
-
# Gradio interface
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
gr.Markdown("Upload an audio file or record via microphone, select a target language, and get the transcription, translation, and translated audio! Uses Kokoro TTS for supported languages, otherwise gTTS.")
|
110 |
|
111 |
supported_langs = list(set(list(KOKORO_LANGUAGES.keys()) + list({v: k for k, v in lang.tts_langs().items()}.keys())))
|
112 |
|
113 |
-
with gr.Row():
|
114 |
audio_input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Input Audio")
|
115 |
target_lang = gr.Dropdown(
|
116 |
choices=sorted(supported_langs),
|
@@ -118,13 +171,13 @@ with gr.Blocks(title="AI Audio Translator") as demo:
|
|
118 |
label="Target Language"
|
119 |
)
|
120 |
|
121 |
-
submit_btn = gr.Button("Translate")
|
122 |
|
123 |
-
with gr.Row():
|
124 |
-
error_output = gr.Textbox(label="Error", visible=True)
|
125 |
-
transcription_output = gr.Textbox(label="Transcription")
|
126 |
-
translation_output = gr.Textbox(label="Translated Text")
|
127 |
-
audio_output = gr.Audio(label="Translated Audio")
|
128 |
|
129 |
submit_btn.click(
|
130 |
fn=process_audio,
|
|
|
103 |
|
104 |
return None, transcription, translated_text, audio_output
|
105 |
|
106 |
+
# Gradio interface with custom CSS and JavaScript
|
107 |
+
css = """
|
108 |
+
body {
|
109 |
+
font-family: 'Arial', sans-serif;
|
110 |
+
background-color: #f4f4f4;
|
111 |
+
color: #333;
|
112 |
+
}
|
113 |
+
.gradio-container {
|
114 |
+
max-width: 800px;
|
115 |
+
margin: 0 auto;
|
116 |
+
padding: 20px;
|
117 |
+
background-color: #fff;
|
118 |
+
border-radius: 10px;
|
119 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
120 |
+
}
|
121 |
+
.gradio-header {
|
122 |
+
text-align: center;
|
123 |
+
margin-bottom: 20px;
|
124 |
+
}
|
125 |
+
.gradio-header h1 {
|
126 |
+
font-size: 2.5em;
|
127 |
+
color: #444;
|
128 |
+
}
|
129 |
+
.gradio-row {
|
130 |
+
display: flex;
|
131 |
+
flex-direction: column;
|
132 |
+
gap: 15px;
|
133 |
+
}
|
134 |
+
.gradio-button {
|
135 |
+
background-color: #007bff;
|
136 |
+
color: white;
|
137 |
+
border: none;
|
138 |
+
padding: 10px 20px;
|
139 |
+
border-radius: 5px;
|
140 |
+
cursor: pointer;
|
141 |
+
font-size: 1em;
|
142 |
+
}
|
143 |
+
.gradio-button:hover {
|
144 |
+
background-color: #0056b3;
|
145 |
+
}
|
146 |
+
.gradio-output {
|
147 |
+
background-color: #f9f9f9;
|
148 |
+
padding: 15px;
|
149 |
+
border-radius: 5px;
|
150 |
+
border: 1px solid #ddd;
|
151 |
+
}
|
152 |
+
"""
|
153 |
+
|
154 |
+
js = """
|
155 |
+
function updateUI() {
|
156 |
+
// Add any custom JavaScript here if needed
|
157 |
+
}
|
158 |
+
"""
|
159 |
+
|
160 |
+
with gr.Blocks(css=css, title="AI Audio Translator") as demo:
|
161 |
+
gr.Markdown("# AI Audio Translator", elem_classes="gradio-header")
|
162 |
gr.Markdown("Upload an audio file or record via microphone, select a target language, and get the transcription, translation, and translated audio! Uses Kokoro TTS for supported languages, otherwise gTTS.")
|
163 |
|
164 |
supported_langs = list(set(list(KOKORO_LANGUAGES.keys()) + list({v: k for k, v in lang.tts_langs().items()}.keys())))
|
165 |
|
166 |
+
with gr.Row(elem_classes="gradio-row"):
|
167 |
audio_input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Input Audio")
|
168 |
target_lang = gr.Dropdown(
|
169 |
choices=sorted(supported_langs),
|
|
|
171 |
label="Target Language"
|
172 |
)
|
173 |
|
174 |
+
submit_btn = gr.Button("Translate", elem_classes="gradio-button")
|
175 |
|
176 |
+
with gr.Row(elem_classes="gradio-row"):
|
177 |
+
error_output = gr.Textbox(label="Error", visible=True, elem_classes="gradio-output")
|
178 |
+
transcription_output = gr.Textbox(label="Transcription", elem_classes="gradio-output")
|
179 |
+
translation_output = gr.Textbox(label="Translated Text", elem_classes="gradio-output")
|
180 |
+
audio_output = gr.Audio(label="Translated Audio", elem_classes="gradio-output")
|
181 |
|
182 |
submit_btn.click(
|
183 |
fn=process_audio,
|