Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -413,6 +413,9 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 413 |
# Define shared components at the top
|
| 414 |
chatbot = gr.Chatbot(height=350, elem_classes="gradio-chatbot", label=None, type="messages")
|
| 415 |
file_output = gr.Textbox(label="Upload Status", interactive=False, elem_classes="textbox")
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
# Document upload section
|
| 418 |
with gr.Row(elem_classes="centered-main"):
|
|
@@ -423,9 +426,9 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 423 |
reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
|
| 424 |
def reset_all():
|
| 425 |
rag.thread_id = None
|
| 426 |
-
return "", []
|
| 427 |
file_input.change(process_file, file_input, file_output)
|
| 428 |
-
reset_btn.click(reset_all, None, [file_output, chatbot])
|
| 429 |
|
| 430 |
# Unified chat and voice panel
|
| 431 |
with gr.Row(elem_classes="centered-main"):
|
|
@@ -433,16 +436,13 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 433 |
with gr.Group(elem_classes="compact-box"):
|
| 434 |
gr.Markdown("<div class='section-title'>2. Chat with your Document</div>")
|
| 435 |
with gr.Row():
|
| 436 |
-
question = gr.Textbox(label="Type your question and press Enter", placeholder="Ask a question about your document...", elem_classes="textbox")
|
| 437 |
send_btn = gr.Button("Send", elem_classes="send-btn")
|
| 438 |
mic_btn = gr.Button("🎤", elem_classes="audio-btn")
|
| 439 |
-
question.submit(process_question, [question, chatbot], [question, chatbot])
|
| 440 |
-
send_btn.click(process_question, [question, chatbot], [question, chatbot])
|
| 441 |
|
| 442 |
# Inline audio recorder, hidden by default
|
| 443 |
-
audio_input
|
| 444 |
-
audio_status = gr.Textbox(label="Audio Status", interactive=False, elem_classes="status-text", visible=False)
|
| 445 |
-
audio_input.change(process_audio, [audio_input, chatbot], [audio_input, chatbot])
|
| 446 |
|
| 447 |
def show_audio():
|
| 448 |
return {audio_input: gr.update(visible=True), audio_status: gr.update(visible=True)}
|
|
|
|
| 413 |
# Define shared components at the top
|
| 414 |
chatbot = gr.Chatbot(height=350, elem_classes="gradio-chatbot", label=None, type="messages")
|
| 415 |
file_output = gr.Textbox(label="Upload Status", interactive=False, elem_classes="textbox")
|
| 416 |
+
question = gr.Textbox(label="Type your question and press Enter", placeholder="Ask a question about your document...", elem_classes="textbox")
|
| 417 |
+
audio_input = gr.Audio(type="filepath", label="Record or Upload Audio", elem_classes="gradio-audio", visible=False)
|
| 418 |
+
audio_status = gr.Textbox(label="Audio Status", interactive=False, elem_classes="status-text", visible=False)
|
| 419 |
|
| 420 |
# Document upload section
|
| 421 |
with gr.Row(elem_classes="centered-main"):
|
|
|
|
| 426 |
reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
|
| 427 |
def reset_all():
|
| 428 |
rag.thread_id = None
|
| 429 |
+
return "", [], "", None # file_output, chatbot, question, audio_input
|
| 430 |
file_input.change(process_file, file_input, file_output)
|
| 431 |
+
reset_btn.click(reset_all, None, [file_output, chatbot, question, audio_input])
|
| 432 |
|
| 433 |
# Unified chat and voice panel
|
| 434 |
with gr.Row(elem_classes="centered-main"):
|
|
|
|
| 436 |
with gr.Group(elem_classes="compact-box"):
|
| 437 |
gr.Markdown("<div class='section-title'>2. Chat with your Document</div>")
|
| 438 |
with gr.Row():
|
|
|
|
| 439 |
send_btn = gr.Button("Send", elem_classes="send-btn")
|
| 440 |
mic_btn = gr.Button("🎤", elem_classes="audio-btn")
|
| 441 |
+
question.submit(process_question, [question, chatbot], [question, chatbot, question, audio_input])
|
| 442 |
+
send_btn.click(process_question, [question, chatbot], [question, chatbot, question, audio_input])
|
| 443 |
|
| 444 |
# Inline audio recorder, hidden by default
|
| 445 |
+
audio_input.change(process_audio, [audio_input, chatbot], [audio_input, chatbot, question, audio_input])
|
|
|
|
|
|
|
| 446 |
|
| 447 |
def show_audio():
|
| 448 |
return {audio_input: gr.update(visible=True), audio_status: gr.update(visible=True)}
|