Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import openai
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
from gtts import gTTS
|
| 7 |
-
|
| 8 |
|
| 9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
|
|
@@ -50,16 +50,20 @@ def inference(text):
|
|
| 50 |
tts.save(output_file)
|
| 51 |
return output_file
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
return response_text, output_file
|
| 58 |
|
| 59 |
demo = gr.Interface(
|
| 60 |
process_audio_and_respond,
|
| 61 |
gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
|
| 62 |
-
[gr.outputs.
|
|
|
|
|
|
|
|
|
|
| 63 |
title="Mtaalamu wa Viazi Lishe",
|
| 64 |
description="Uliza Mtaalamu wetu swali lolote Kuhusu viazi Lishe",
|
| 65 |
theme="compact",
|
|
@@ -68,4 +72,5 @@ demo = gr.Interface(
|
|
| 68 |
live=True,
|
| 69 |
)
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
from gtts import gTTS
|
| 7 |
+
import asyncio # Import asyncio for the asynchronous functionality
|
| 8 |
|
| 9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
|
|
|
|
| 50 |
tts.save(output_file)
|
| 51 |
return output_file
|
| 52 |
|
| 53 |
+
# Here is the new function
|
| 54 |
+
async def process_audio_and_respond(audio):
|
| 55 |
+
text = await asyncio.to_thread(transcribe, audio)
|
| 56 |
+
response_text = await asyncio.to_thread(generate_response, text)
|
| 57 |
+
output_file = await asyncio.to_thread(inference, response_text)
|
| 58 |
return response_text, output_file
|
| 59 |
|
| 60 |
demo = gr.Interface(
|
| 61 |
process_audio_and_respond,
|
| 62 |
gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
|
| 63 |
+
[gr.outputs.TextOops, my previous message got cut off. Here's the rest of the code:
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Textbox(label="Jibu (kwa njia ya maandishi)"), gr.outputs.Audio(type="filepath", label="Jibu kwa njia ya sauti (Bofya kusikiliza Jibu)")],
|
| 67 |
title="Mtaalamu wa Viazi Lishe",
|
| 68 |
description="Uliza Mtaalamu wetu swali lolote Kuhusu viazi Lishe",
|
| 69 |
theme="compact",
|
|
|
|
| 72 |
live=True,
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Use asyncio.run to start the Gradio interface
|
| 76 |
+
asyncio.run(demo.launch())
|