Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import subprocess
|
|
| 13 |
|
| 14 |
default_lang = "en"
|
| 15 |
|
| 16 |
-
engines = {default_lang: Model(default_lang)}
|
| 17 |
|
| 18 |
def transcribe(audio):
|
| 19 |
if audio is None:
|
|
@@ -175,6 +175,16 @@ def voice_assistant_tab():
|
|
| 175 |
def speech_translation_tab():
|
| 176 |
return "# <center><b>Hear how you sound in another language</b></center>"
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
with gr.Blocks(css="style.css") as demo:
|
| 179 |
description = gr.Markdown("# <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>")
|
| 180 |
|
|
@@ -198,21 +208,29 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 198 |
value=0,
|
| 199 |
visible=False
|
| 200 |
)
|
| 201 |
-
input = gr.Audio(
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
-
|
| 208 |
-
fn=
|
| 209 |
inputs=[input, select, seed],
|
| 210 |
-
outputs=[output]
|
| 211 |
-
live=True
|
| 212 |
)
|
| 213 |
|
| 214 |
with gr.TabItem("Speech Translation") as speech_translation:
|
| 215 |
-
input_audio = gr.Audio(label="User", sources="microphone", type="filepath",
|
| 216 |
target_lang = gr.Dropdown(
|
| 217 |
choices=list(LANGUAGE_CODES.keys()),
|
| 218 |
value="German",
|
|
@@ -230,16 +248,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 230 |
live=True
|
| 231 |
)
|
| 232 |
|
| 233 |
-
# clear_button = gr.Button("Clear")
|
| 234 |
-
# clear_button.click(
|
| 235 |
-
# fn=clear_history,
|
| 236 |
-
# inputs=[],
|
| 237 |
-
# outputs=[input, output, input_audio, output_audio],
|
| 238 |
-
# api_name="clear"
|
| 239 |
-
# )
|
| 240 |
-
|
| 241 |
voice_assistant.select(fn=voice_assistant_tab, inputs=None, outputs=description)
|
| 242 |
speech_translation.select(fn=speech_translation_tab, inputs=None, outputs=description)
|
| 243 |
|
| 244 |
if __name__ == "__main__":
|
| 245 |
-
demo.queue(max_size=200).launch()
|
|
|
|
| 13 |
|
| 14 |
default_lang = "en"
|
| 15 |
|
| 16 |
+
engines = { default_lang: Model(default_lang) }
|
| 17 |
|
| 18 |
def transcribe(audio):
|
| 19 |
if audio is None:
|
|
|
|
| 175 |
def speech_translation_tab():
|
| 176 |
return "# <center><b>Hear how you sound in another language</b></center>"
|
| 177 |
|
| 178 |
+
# New function to handle streaming audio input
|
| 179 |
+
def process_audio(audio, model, seed):
|
| 180 |
+
if audio is None:
|
| 181 |
+
return None
|
| 182 |
+
user_input = transcribe(audio)
|
| 183 |
+
if not user_input:
|
| 184 |
+
return None
|
| 185 |
+
reply = models(user_input, model, seed)
|
| 186 |
+
return asyncio.run(respond(audio, model, seed))
|
| 187 |
+
|
| 188 |
with gr.Blocks(css="style.css") as demo:
|
| 189 |
description = gr.Markdown("# <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>")
|
| 190 |
|
|
|
|
| 208 |
value=0,
|
| 209 |
visible=False
|
| 210 |
)
|
| 211 |
+
input = gr.Audio(
|
| 212 |
+
label="User",
|
| 213 |
+
sources="microphone",
|
| 214 |
+
type="filepath",
|
| 215 |
+
streaming=True,
|
| 216 |
+
waveform_options={"show_controls": False, "height": 100}
|
| 217 |
+
)
|
| 218 |
+
output = gr.Audio(
|
| 219 |
+
label="AI",
|
| 220 |
+
type="filepath",
|
| 221 |
+
interactive=False,
|
| 222 |
+
autoplay=True,
|
| 223 |
+
elem_classes="audio"
|
| 224 |
+
)
|
| 225 |
|
| 226 |
+
input.stream(
|
| 227 |
+
fn=process_audio,
|
| 228 |
inputs=[input, select, seed],
|
| 229 |
+
outputs=[output]
|
|
|
|
| 230 |
)
|
| 231 |
|
| 232 |
with gr.TabItem("Speech Translation") as speech_translation:
|
| 233 |
+
input_audio = gr.Audio(label="User", sources="microphone", type="filepath", waveform_options=False)
|
| 234 |
target_lang = gr.Dropdown(
|
| 235 |
choices=list(LANGUAGE_CODES.keys()),
|
| 236 |
value="German",
|
|
|
|
| 248 |
live=True
|
| 249 |
)
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
voice_assistant.select(fn=voice_assistant_tab, inputs=None, outputs=description)
|
| 252 |
speech_translation.select(fn=speech_translation_tab, inputs=None, outputs=description)
|
| 253 |
|
| 254 |
if __name__ == "__main__":
|
| 255 |
+
demo.queue(max_size=200).launch()
|