DreamStream-1 commited on
Commit
3150019
·
verified ·
1 Parent(s): 0f50d71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -412,6 +412,14 @@ def process_voice_note(audio_file, history):
412
  history.append({"role": "assistant", "content": "It seems there was an error while transcribing audio due to a technical issue. If there's anything specific from the document or any other questions you have regarding the content, please let me know, and I can assist you with that information."})
413
  return "", history, "", None, None
414
 
 
 
 
 
 
 
 
 
415
  # Create Gradio interface with improved layout
416
  with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
417
  gr.Markdown("""
@@ -425,34 +433,33 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
425
  audio_input = gr.Audio(type="filepath", label="Record or Upload Audio", elem_classes="gradio-audio", visible=False)
426
  tts_output = gr.Audio(label="Assistant Voice Reply", interactive=False, visible=False)
427
 
428
- with gr.Group(elem_classes="compact-box"):
429
- gr.Markdown("<div class='section-title'>Document Q&A</div>")
430
- with gr.Row():
431
- with gr.Column(scale=1, min_width=350):
 
432
  file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".doc", ".docx"], file_count="single", type="binary", elem_classes="upload-btn")
433
  mic_btn = gr.Button("🎤 Record Voice", elem_classes="audio-btn")
434
  audio_input
435
  send_voice_btn = gr.Button("Send Voice Note", elem_classes="send-btn", visible=False)
436
  reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
437
  file_output
438
- with gr.Column(scale=3, min_width=500):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
  chatbot
440
- with gr.Row():
441
- question
442
- file_input.change(process_file, file_input, file_output)
443
- def reset_all():
444
- rag.thread_id = None
445
- return "", [], "", None, None
446
- reset_btn.click(reset_all, None, [file_output, chatbot, question, audio_input, tts_output])
447
- def show_audio():
448
- return {audio_input: gr.update(visible=True), send_voice_btn: gr.update(visible=True)}
449
- mic_btn.click(show_audio, None, [audio_input, send_voice_btn])
450
- def hide_audio():
451
- return {audio_input: gr.update(visible=False), send_voice_btn: gr.update(visible=False)}
452
- send_voice_btn.click(process_voice_note, [audio_input, chatbot], [file_output, chatbot, question, audio_input, tts_output])
453
- send_voice_btn.click(hide_audio, None, [audio_input, send_voice_btn])
454
- question.submit(process_question, [question, chatbot], [question, chatbot, question, audio_input])
455
- tts_output
456
 
457
  # Add JavaScript for audio handling
458
  demo.load(
 
412
  history.append({"role": "assistant", "content": "It seems there was an error while transcribing audio due to a technical issue. If there's anything specific from the document or any other questions you have regarding the content, please let me know, and I can assist you with that information."})
413
  return "", history, "", None, None
414
 
415
+ def reset_all():
416
+ rag.thread_id = None
417
+ if hasattr(rag, 'file_ids'):
418
+ rag.file_ids = []
419
+ if hasattr(rag, 'vector_store_id'):
420
+ rag.vector_store_id = None
421
+ return "", [], "", None, None
422
+
423
  # Create Gradio interface with improved layout
424
  with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
425
  gr.Markdown("""
 
433
  audio_input = gr.Audio(type="filepath", label="Record or Upload Audio", elem_classes="gradio-audio", visible=False)
434
  tts_output = gr.Audio(label="Assistant Voice Reply", interactive=False, visible=False)
435
 
436
+ with gr.Row():
437
+ # Left: Document Q&A controls
438
+ with gr.Column(scale=1, min_width=350):
439
+ with gr.Group(elem_classes="compact-box"):
440
+ gr.Markdown("<div class='section-title'>Document Q&A Controls</div>")
441
  file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".doc", ".docx"], file_count="single", type="binary", elem_classes="upload-btn")
442
  mic_btn = gr.Button("🎤 Record Voice", elem_classes="audio-btn")
443
  audio_input
444
  send_voice_btn = gr.Button("Send Voice Note", elem_classes="send-btn", visible=False)
445
  reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
446
  file_output
447
+ question
448
+ file_input.change(process_file, file_input, file_output)
449
+ reset_btn.click(reset_all, None, [file_output, chatbot, question, audio_input, tts_output])
450
+ def show_audio():
451
+ return {audio_input: gr.update(visible=True), send_voice_btn: gr.update(visible=True)}
452
+ mic_btn.click(show_audio, None, [audio_input, send_voice_btn])
453
+ def hide_audio():
454
+ return {audio_input: gr.update(visible=False), send_voice_btn: gr.update(visible=False)}
455
+ send_voice_btn.click(process_voice_note, [audio_input, chatbot], [file_output, chatbot, question, audio_input, tts_output])
456
+ send_voice_btn.click(hide_audio, None, [audio_input, send_voice_btn])
457
+ question.submit(process_question, [question, chatbot], [question, chatbot, question, audio_input])
458
+ tts_output
459
+ # Right: Chatbot screen
460
+ with gr.Column(scale=2, min_width=500):
461
+ with gr.Group(elem_classes="compact-box"):
462
  chatbot
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
 
464
  # Add JavaScript for audio handling
465
  demo.load(