Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -120,8 +120,6 @@ def inference(text):
|
|
120 |
voice="alloy",
|
121 |
text=text
|
122 |
)
|
123 |
-
# OpenAI API returns the temp audio URL which contains the audio file
|
124 |
-
# You can download it via requests or use the URL directly as needed
|
125 |
audio_url = response['url']
|
126 |
return audio_url
|
127 |
|
@@ -129,13 +127,20 @@ def process_audio_and_respond(audio):
|
|
129 |
text = transcribe(audio)
|
130 |
response_text = generate_response(text)
|
131 |
audio_url = inference(response_text)
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
demo = gr.Interface(
|
135 |
process_audio_and_respond,
|
136 |
gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
|
137 |
-
[gr.outputs.Textbox(label="Jibu (kwa njia ya maandishi)"),
|
138 |
-
gr.outputs.Audio(label="Jibu kwa njia ya sauti (Bofya kusikiliza Jibu)")],
|
139 |
description="Uliza Swali kuhusu haki and sheria za udongo",
|
140 |
theme="compact",
|
141 |
layout="vertical",
|
|
|
120 |
voice="alloy",
|
121 |
text=text
|
122 |
)
|
|
|
|
|
123 |
audio_url = response['url']
|
124 |
return audio_url
|
125 |
|
|
|
127 |
text = transcribe(audio)
|
128 |
response_text = generate_response(text)
|
129 |
audio_url = inference(response_text)
|
130 |
+
response = requests.get(audio_url)
|
131 |
+
|
132 |
+
# Create a temporary file
|
133 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
134 |
+
temp_file.write(response.content)
|
135 |
+
temp_filepath = temp_file.name # We need the file path for Gradio to play the audio
|
136 |
+
|
137 |
+
return response_text, temp_filepath # Return the audio file path
|
138 |
|
139 |
demo = gr.Interface(
|
140 |
process_audio_and_respond,
|
141 |
gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
|
142 |
+
[gr.outputs.Textbox(label="Jibu (kwa njia ya maandishi)"),
|
143 |
+
gr.outputs.Audio(type="filepath", label="Jibu kwa njia ya sauti (Bofya kusikiliza Jibu)")],
|
144 |
description="Uliza Swali kuhusu haki and sheria za udongo",
|
145 |
theme="compact",
|
146 |
layout="vertical",
|