Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -410,15 +410,13 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 410 |
<div style='text-align:center; color:#1976D2; margin-bottom:18px;'>Upload a document, ask questions, or use your voice!</div>
|
| 411 |
""")
|
| 412 |
|
| 413 |
-
#
|
| 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 |
with gr.Row(elem_classes="centered-main"):
|
| 418 |
with gr.Column():
|
| 419 |
with gr.Group(elem_classes="compact-box"):
|
| 420 |
gr.Markdown("<div class='section-title'>1. Upload Document</div>")
|
| 421 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".doc", ".docx"], file_count="single", type="binary", elem_classes="upload-btn")
|
|
|
|
| 422 |
reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
|
| 423 |
def reset_all():
|
| 424 |
rag.thread_id = None
|
|
@@ -426,10 +424,12 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 426 |
file_input.change(process_file, file_input, file_output)
|
| 427 |
reset_btn.click(reset_all, None, [file_output, chatbot])
|
| 428 |
|
|
|
|
| 429 |
with gr.Row(elem_classes="centered-main"):
|
| 430 |
with gr.Column():
|
| 431 |
with gr.Group(elem_classes="compact-box"):
|
| 432 |
gr.Markdown("<div class='section-title'>2. Chat with your Document</div>")
|
|
|
|
| 433 |
with gr.Row():
|
| 434 |
question = gr.Textbox(label="Type your question and press Enter", placeholder="Ask a question about your document...", elem_classes="textbox")
|
| 435 |
send_btn = gr.Button("Send", elem_classes="send-btn")
|
|
@@ -437,17 +437,14 @@ with gr.Blocks(css=custom_css, title="Document Q&A System") as demo:
|
|
| 437 |
question.submit(process_question, [question, chatbot], [question, chatbot])
|
| 438 |
send_btn.click(process_question, [question, chatbot], [question, chatbot])
|
| 439 |
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
gr.Markdown("<div class='section-title'>Speak your Question</div>")
|
| 444 |
-
audio_input = gr.Audio(type="filepath", label="Record or Upload Audio", elem_classes="gradio-audio")
|
| 445 |
-
audio_status = gr.Textbox(label="Audio Status", interactive=False, elem_classes="status-text")
|
| 446 |
audio_input.change(process_audio, [audio_input, chatbot], [audio_input, chatbot])
|
| 447 |
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
|
| 452 |
# Add JavaScript for audio handling
|
| 453 |
demo.load(
|
|
|
|
| 410 |
<div style='text-align:center; color:#1976D2; margin-bottom:18px;'>Upload a document, ask questions, or use your voice!</div>
|
| 411 |
""")
|
| 412 |
|
| 413 |
+
# Document upload section
|
|
|
|
|
|
|
|
|
|
| 414 |
with gr.Row(elem_classes="centered-main"):
|
| 415 |
with gr.Column():
|
| 416 |
with gr.Group(elem_classes="compact-box"):
|
| 417 |
gr.Markdown("<div class='section-title'>1. Upload Document</div>")
|
| 418 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".doc", ".docx"], file_count="single", type="binary", elem_classes="upload-btn")
|
| 419 |
+
file_output = gr.Textbox(label="Upload Status", interactive=False, elem_classes="textbox")
|
| 420 |
reset_btn = gr.Button("Reset Chat & Upload New Document", elem_classes="reset-btn")
|
| 421 |
def reset_all():
|
| 422 |
rag.thread_id = None
|
|
|
|
| 424 |
file_input.change(process_file, file_input, file_output)
|
| 425 |
reset_btn.click(reset_all, None, [file_output, chatbot])
|
| 426 |
|
| 427 |
+
# Unified chat and voice panel
|
| 428 |
with gr.Row(elem_classes="centered-main"):
|
| 429 |
with gr.Column():
|
| 430 |
with gr.Group(elem_classes="compact-box"):
|
| 431 |
gr.Markdown("<div class='section-title'>2. Chat with your Document</div>")
|
| 432 |
+
chatbot = gr.Chatbot(height=350, elem_classes="gradio-chatbot", label=None, type="messages")
|
| 433 |
with gr.Row():
|
| 434 |
question = gr.Textbox(label="Type your question and press Enter", placeholder="Ask a question about your document...", elem_classes="textbox")
|
| 435 |
send_btn = gr.Button("Send", elem_classes="send-btn")
|
|
|
|
| 437 |
question.submit(process_question, [question, chatbot], [question, chatbot])
|
| 438 |
send_btn.click(process_question, [question, chatbot], [question, chatbot])
|
| 439 |
|
| 440 |
+
# Inline audio recorder, hidden by default
|
| 441 |
+
audio_input = gr.Audio(type="filepath", label="Record or Upload Audio", elem_classes="gradio-audio", visible=False)
|
| 442 |
+
audio_status = gr.Textbox(label="Audio Status", interactive=False, elem_classes="status-text", visible=False)
|
|
|
|
|
|
|
|
|
|
| 443 |
audio_input.change(process_audio, [audio_input, chatbot], [audio_input, chatbot])
|
| 444 |
|
| 445 |
+
def show_audio():
|
| 446 |
+
return {audio_input: gr.update(visible=True), audio_status: gr.update(visible=True)}
|
| 447 |
+
mic_btn.click(show_audio, None, [audio_input, audio_status])
|
| 448 |
|
| 449 |
# Add JavaScript for audio handling
|
| 450 |
demo.load(
|