Update app.py
Browse files
app.py
CHANGED
|
@@ -649,7 +649,6 @@ def refresh_documents():
|
|
| 649 |
uploaded_documents = load_documents()
|
| 650 |
return display_documents()
|
| 651 |
|
| 652 |
-
|
| 653 |
# Define the checkbox outside the demo block
|
| 654 |
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
| 655 |
|
|
@@ -657,38 +656,9 @@ use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
|
| 657 |
|
| 658 |
custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
|
| 659 |
|
| 660 |
-
#
|
| 661 |
-
|
| 662 |
-
.
|
| 663 |
-
background-color: #1a1a1a;
|
| 664 |
-
color: #ffffff;
|
| 665 |
-
}
|
| 666 |
-
.dark-mode .gradio-slider input[type="range"] {
|
| 667 |
-
background-color: #4a4a4a;
|
| 668 |
-
}
|
| 669 |
-
.dark-mode .gradio-button {
|
| 670 |
-
background-color: #4a4a4a;
|
| 671 |
-
color: #ffffff;
|
| 672 |
-
}
|
| 673 |
-
"""
|
| 674 |
-
|
| 675 |
-
# JavaScript to toggle dark mode
|
| 676 |
-
dark_mode_js = """
|
| 677 |
-
function toggleDarkMode() {
|
| 678 |
-
document.body.classList.toggle('dark-mode');
|
| 679 |
-
return document.body.classList.contains('dark-mode');
|
| 680 |
-
}
|
| 681 |
-
"""
|
| 682 |
-
|
| 683 |
-
# Create a function to toggle dark mode
|
| 684 |
-
def toggle_dark_mode(dark_mode):
|
| 685 |
-
return not dark_mode, gr.update(value="Light Mode" if dark_mode else "Dark Mode")
|
| 686 |
-
|
| 687 |
-
# Combine the existing CSS with dark mode CSS
|
| 688 |
-
combined_css = css + dark_mode_css
|
| 689 |
-
|
| 690 |
-
# Create the ChatInterface
|
| 691 |
-
chat_interface = gr.ChatInterface(
|
| 692 |
respond,
|
| 693 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
|
| 694 |
additional_inputs=[
|
|
@@ -701,7 +671,7 @@ chat_interface = gr.ChatInterface(
|
|
| 701 |
title="AI-powered PDF Chat and Web Search Assistant",
|
| 702 |
description="Chat with your PDFs or use web search to answer questions.",
|
| 703 |
theme=gr.Theme.from_hub("JohnSmith9982/small_and_pretty"),
|
| 704 |
-
css=
|
| 705 |
examples=[
|
| 706 |
["Tell me about the contents of the uploaded PDFs."],
|
| 707 |
["What are the main topics discussed in the documents?"],
|
|
@@ -720,18 +690,8 @@ chat_interface = gr.ChatInterface(
|
|
| 720 |
)
|
| 721 |
)
|
| 722 |
|
| 723 |
-
#
|
| 724 |
-
demo = gr.Blocks(css=combined_css)
|
| 725 |
-
|
| 726 |
with demo:
|
| 727 |
-
dark_mode = gr.State(False)
|
| 728 |
-
|
| 729 |
-
with gr.Row():
|
| 730 |
-
dark_mode_button = gr.Button("Dark Mode")
|
| 731 |
-
|
| 732 |
-
# Add the ChatInterface
|
| 733 |
-
chat_interface.render()
|
| 734 |
-
|
| 735 |
gr.Markdown("## Upload and Manage PDF Documents")
|
| 736 |
with gr.Row():
|
| 737 |
file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
|
|
@@ -746,23 +706,23 @@ with demo:
|
|
| 746 |
update_button.click(
|
| 747 |
update_vectors,
|
| 748 |
inputs=[file_input, parser_dropdown],
|
| 749 |
-
outputs=[update_output,
|
| 750 |
)
|
| 751 |
|
| 752 |
# Add the refresh button functionality
|
| 753 |
refresh_button.click(
|
| 754 |
refresh_documents,
|
| 755 |
inputs=[],
|
| 756 |
-
outputs=[
|
| 757 |
)
|
| 758 |
|
| 759 |
# Add the delete button functionality
|
| 760 |
delete_button.click(
|
| 761 |
delete_documents,
|
| 762 |
-
inputs=[
|
| 763 |
-
outputs=[update_output,
|
| 764 |
)
|
| 765 |
-
|
| 766 |
gr.Markdown(
|
| 767 |
"""
|
| 768 |
## How to use
|
|
@@ -775,14 +735,6 @@ with demo:
|
|
| 775 |
7. Use the provided examples or ask your own questions.
|
| 776 |
"""
|
| 777 |
)
|
| 778 |
-
|
| 779 |
-
# Add the dark mode toggle functionality
|
| 780 |
-
dark_mode_button.click(
|
| 781 |
-
toggle_dark_mode,
|
| 782 |
-
inputs=[dark_mode],
|
| 783 |
-
outputs=[dark_mode, dark_mode_button],
|
| 784 |
-
_js=dark_mode_js
|
| 785 |
-
)
|
| 786 |
|
| 787 |
if __name__ == "__main__":
|
| 788 |
demo.launch(share=True)
|
|
|
|
| 649 |
uploaded_documents = load_documents()
|
| 650 |
return display_documents()
|
| 651 |
|
|
|
|
| 652 |
# Define the checkbox outside the demo block
|
| 653 |
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
| 654 |
|
|
|
|
| 656 |
|
| 657 |
custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
|
| 658 |
|
| 659 |
+
# Update the demo interface
|
| 660 |
+
# Update the Gradio interface
|
| 661 |
+
demo = gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
respond,
|
| 663 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
|
| 664 |
additional_inputs=[
|
|
|
|
| 671 |
title="AI-powered PDF Chat and Web Search Assistant",
|
| 672 |
description="Chat with your PDFs or use web search to answer questions.",
|
| 673 |
theme=gr.Theme.from_hub("JohnSmith9982/small_and_pretty"),
|
| 674 |
+
css=css,
|
| 675 |
examples=[
|
| 676 |
["Tell me about the contents of the uploaded PDFs."],
|
| 677 |
["What are the main topics discussed in the documents?"],
|
|
|
|
| 690 |
)
|
| 691 |
)
|
| 692 |
|
| 693 |
+
# Add file upload functionality
|
|
|
|
|
|
|
| 694 |
with demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
gr.Markdown("## Upload and Manage PDF Documents")
|
| 696 |
with gr.Row():
|
| 697 |
file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
|
|
|
|
| 706 |
update_button.click(
|
| 707 |
update_vectors,
|
| 708 |
inputs=[file_input, parser_dropdown],
|
| 709 |
+
outputs=[update_output, demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
|
| 710 |
)
|
| 711 |
|
| 712 |
# Add the refresh button functionality
|
| 713 |
refresh_button.click(
|
| 714 |
refresh_documents,
|
| 715 |
inputs=[],
|
| 716 |
+
outputs=[demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
|
| 717 |
)
|
| 718 |
|
| 719 |
# Add the delete button functionality
|
| 720 |
delete_button.click(
|
| 721 |
delete_documents,
|
| 722 |
+
inputs=[demo.additional_inputs[-1]], # Use the CheckboxGroup from additional_inputs
|
| 723 |
+
outputs=[update_output, demo.additional_inputs[-1]]
|
| 724 |
)
|
| 725 |
+
|
| 726 |
gr.Markdown(
|
| 727 |
"""
|
| 728 |
## How to use
|
|
|
|
| 735 |
7. Use the provided examples or ask your own questions.
|
| 736 |
"""
|
| 737 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
|
| 739 |
if __name__ == "__main__":
|
| 740 |
demo.launch(share=True)
|