Update app.py
Browse files
app.py
CHANGED
@@ -153,21 +153,12 @@ def process_recorded_audio(audio_path):
|
|
153 |
return f"Error transcribing recorded audio: {str(e)}"
|
154 |
|
155 |
# Function to process the voice chat queries
|
156 |
-
def process_voice_query(transcription,
|
157 |
if not transcription or transcription.startswith("Error") or transcription.startswith("Please"):
|
158 |
return "Please ensure audio is transcribed successfully first."
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
messages = [{"role": "user", "content": [{"type": "text", "text": transcription}]}]
|
163 |
-
else:
|
164 |
-
# If a query about the transcription is provided
|
165 |
-
messages = [
|
166 |
-
{"role": "user", "content": [
|
167 |
-
{"type": "text", "text": f"Transcription: {transcription}"},
|
168 |
-
{"type": "text", "text": f"Query: {query}"}
|
169 |
-
]}
|
170 |
-
]
|
171 |
|
172 |
return query_openai(messages, temperature, top_p, max_output_tokens)
|
173 |
|
@@ -191,11 +182,9 @@ def clear_chat():
|
|
191 |
"", # pdf_output (textbox)
|
192 |
None, # audio_upload (file)
|
193 |
"", # upload_transcription (textbox)
|
194 |
-
# "", # upload_audio_query (textbox)
|
195 |
"", # upload_audio_output (textbox)
|
196 |
None, # audio_recorder (audio)
|
197 |
"", # record_transcription (textbox)
|
198 |
-
# "", # record_audio_query (textbox)
|
199 |
"", # record_audio_output (textbox)
|
200 |
1.0, # temperature (slider)
|
201 |
1.0, # top_p (slider)
|
@@ -290,16 +279,14 @@ with gr.Blocks() as demo:
|
|
290 |
audio_upload = gr.File(label="Upload an Audio File", type="binary")
|
291 |
upload_transcribe_button = gr.Button("Transcribe Audio", elem_id="transcribe_button")
|
292 |
upload_transcription = gr.Textbox(label="Transcription", interactive=False)
|
293 |
-
# upload_audio_query = gr.Textbox(label="Ask about the transcription (optional)")
|
294 |
upload_audio_output = gr.Textbox(label="Response", interactive=False)
|
295 |
upload_audio_button = gr.Button("Ask", elem_id="ask_button")
|
296 |
|
297 |
with gr.Tab("Record Audio"):
|
298 |
-
# Record audio section
|
299 |
audio_recorder = gr.Audio(label="Record your voice", type="filepath")
|
300 |
record_transcribe_button = gr.Button("Transcribe Recording", elem_id="transcribe_button")
|
301 |
record_transcription = gr.Textbox(label="Transcription", interactive=False)
|
302 |
-
# record_audio_query = gr.Textbox(label="Ask about the transcription (optional)")
|
303 |
record_audio_output = gr.Textbox(label="Response", interactive=False)
|
304 |
record_audio_button = gr.Button("Ask", elem_id="ask_button")
|
305 |
|
@@ -320,9 +307,9 @@ with gr.Blocks() as demo:
|
|
320 |
outputs=[upload_transcription]
|
321 |
)
|
322 |
|
|
|
323 |
upload_audio_button.click(
|
324 |
process_voice_query,
|
325 |
-
# inputs=[upload_transcription, upload_audio_query, temperature, top_p, max_output_tokens],
|
326 |
inputs=[upload_transcription, temperature, top_p, max_output_tokens],
|
327 |
outputs=[upload_audio_output]
|
328 |
)
|
@@ -334,9 +321,9 @@ with gr.Blocks() as demo:
|
|
334 |
outputs=[record_transcription]
|
335 |
)
|
336 |
|
|
|
337 |
record_audio_button.click(
|
338 |
process_voice_query,
|
339 |
-
# inputs=[record_transcription, record_audio_query, temperature, top_p, max_output_tokens],
|
340 |
inputs=[record_transcription, temperature, top_p, max_output_tokens],
|
341 |
outputs=[record_audio_output]
|
342 |
)
|
@@ -349,9 +336,7 @@ with gr.Blocks() as demo:
|
|
349 |
text_query, text_output,
|
350 |
image_text_query, image_output,
|
351 |
pdf_upload, pdf_text_query, pdf_output,
|
352 |
-
# audio_upload, upload_transcription, upload_audio_query, upload_audio_output,
|
353 |
audio_upload, upload_transcription, upload_audio_output,
|
354 |
-
# audio_recorder, record_transcription, record_audio_query, record_audio_output,
|
355 |
audio_recorder, record_transcription, record_audio_output,
|
356 |
temperature, top_p, max_output_tokens
|
357 |
]
|
|
|
153 |
return f"Error transcribing recorded audio: {str(e)}"
|
154 |
|
155 |
# Function to process the voice chat queries
|
156 |
+
def process_voice_query(transcription, temperature, top_p, max_output_tokens):
|
157 |
if not transcription or transcription.startswith("Error") or transcription.startswith("Please"):
|
158 |
return "Please ensure audio is transcribed successfully first."
|
159 |
|
160 |
+
# Use the transcription as the query
|
161 |
+
messages = [{"role": "user", "content": [{"type": "text", "text": transcription}]}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
return query_openai(messages, temperature, top_p, max_output_tokens)
|
164 |
|
|
|
182 |
"", # pdf_output (textbox)
|
183 |
None, # audio_upload (file)
|
184 |
"", # upload_transcription (textbox)
|
|
|
185 |
"", # upload_audio_output (textbox)
|
186 |
None, # audio_recorder (audio)
|
187 |
"", # record_transcription (textbox)
|
|
|
188 |
"", # record_audio_output (textbox)
|
189 |
1.0, # temperature (slider)
|
190 |
1.0, # top_p (slider)
|
|
|
279 |
audio_upload = gr.File(label="Upload an Audio File", type="binary")
|
280 |
upload_transcribe_button = gr.Button("Transcribe Audio", elem_id="transcribe_button")
|
281 |
upload_transcription = gr.Textbox(label="Transcription", interactive=False)
|
|
|
282 |
upload_audio_output = gr.Textbox(label="Response", interactive=False)
|
283 |
upload_audio_button = gr.Button("Ask", elem_id="ask_button")
|
284 |
|
285 |
with gr.Tab("Record Audio"):
|
286 |
+
# Record audio section
|
287 |
audio_recorder = gr.Audio(label="Record your voice", type="filepath")
|
288 |
record_transcribe_button = gr.Button("Transcribe Recording", elem_id="transcribe_button")
|
289 |
record_transcription = gr.Textbox(label="Transcription", interactive=False)
|
|
|
290 |
record_audio_output = gr.Textbox(label="Response", interactive=False)
|
291 |
record_audio_button = gr.Button("Ask", elem_id="ask_button")
|
292 |
|
|
|
307 |
outputs=[upload_transcription]
|
308 |
)
|
309 |
|
310 |
+
# FIXED: Properly order the inputs to process_voice_query
|
311 |
upload_audio_button.click(
|
312 |
process_voice_query,
|
|
|
313 |
inputs=[upload_transcription, temperature, top_p, max_output_tokens],
|
314 |
outputs=[upload_audio_output]
|
315 |
)
|
|
|
321 |
outputs=[record_transcription]
|
322 |
)
|
323 |
|
324 |
+
# FIXED: Properly order the inputs to process_voice_query
|
325 |
record_audio_button.click(
|
326 |
process_voice_query,
|
|
|
327 |
inputs=[record_transcription, temperature, top_p, max_output_tokens],
|
328 |
outputs=[record_audio_output]
|
329 |
)
|
|
|
336 |
text_query, text_output,
|
337 |
image_text_query, image_output,
|
338 |
pdf_upload, pdf_text_query, pdf_output,
|
|
|
339 |
audio_upload, upload_transcription, upload_audio_output,
|
|
|
340 |
audio_recorder, record_transcription, record_audio_output,
|
341 |
temperature, top_p, max_output_tokens
|
342 |
]
|