Shreyas094 commited on
Commit
c8a63c6
1 Parent(s): 393d34a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -11
app.py CHANGED
@@ -649,6 +649,7 @@ def refresh_documents():
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
 
@@ -658,7 +659,32 @@ custom_placeholder = "Ask a question (Note: You can toggle between Web Search an
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,7 +697,7 @@ demo = gr.ChatInterface(
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,12 +716,18 @@ demo = gr.ChatInterface(
690
  )
691
  )
692
 
693
- # Initialize dark mode state
694
- dark_mode = gr.State(False)
695
 
696
- # Add file upload functionality
697
- # Add file upload functionality
698
  with demo:
 
 
 
 
 
 
 
 
699
  gr.Markdown("## Upload and Manage PDF Documents")
700
  with gr.Row():
701
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
@@ -710,23 +742,23 @@ with demo:
710
  update_button.click(
711
  update_vectors,
712
  inputs=[file_input, parser_dropdown],
713
- outputs=[update_output, demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
714
  )
715
 
716
  # Add the refresh button functionality
717
  refresh_button.click(
718
  refresh_documents,
719
  inputs=[],
720
- outputs=[demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
721
  )
722
 
723
  # Add the delete button functionality
724
  delete_button.click(
725
  delete_documents,
726
- inputs=[demo.additional_inputs[-1]], # Use the CheckboxGroup from additional_inputs
727
- outputs=[update_output, demo.additional_inputs[-1]]
728
  )
729
-
730
  gr.Markdown(
731
  """
732
  ## How to use
@@ -739,6 +771,26 @@ with demo:
739
  7. Use the provided examples or ask your own questions.
740
  """
741
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
 
743
  if __name__ == "__main__":
744
  demo.launch(share=True)
 
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
 
 
659
 
660
  # Update the demo interface
661
  # Update the Gradio interface
662
+ import gradio as gr
663
+
664
+ # Define a custom CSS for dark mode
665
+ dark_mode_css = """
666
+ .dark-mode {
667
+ background-color: #1a1a1a;
668
+ color: #ffffff;
669
+ }
670
+ .dark-mode .gradio-slider input[type="range"] {
671
+ background-color: #4a4a4a;
672
+ }
673
+ .dark-mode .gradio-button {
674
+ background-color: #4a4a4a;
675
+ color: #ffffff;
676
+ }
677
+ """
678
+
679
+ # Create a function to toggle dark mode
680
+ def toggle_dark_mode(dark_mode):
681
+ return not dark_mode, gr.update(value="Light Mode" if dark_mode else "Dark Mode")
682
+
683
+ # Combine the existing CSS with dark mode CSS
684
+ combined_css = css + dark_mode_css
685
+
686
+ # Create the ChatInterface
687
+ chat_interface = gr.ChatInterface(
688
  respond,
689
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
690
  additional_inputs=[
 
697
  title="AI-powered PDF Chat and Web Search Assistant",
698
  description="Chat with your PDFs or use web search to answer questions.",
699
  theme=gr.Theme.from_hub("JohnSmith9982/small_and_pretty"),
700
+ css=combined_css,
701
  examples=[
702
  ["Tell me about the contents of the uploaded PDFs."],
703
  ["What are the main topics discussed in the documents?"],
 
716
  )
717
  )
718
 
719
+ # Create the main Blocks interface
720
+ demo = gr.Blocks(css=combined_css)
721
 
 
 
722
  with demo:
723
+ dark_mode = gr.State(False)
724
+
725
+ with gr.Row():
726
+ dark_mode_button = gr.Button("Dark Mode")
727
+
728
+ # Add the ChatInterface
729
+ chat_interface.render()
730
+
731
  gr.Markdown("## Upload and Manage PDF Documents")
732
  with gr.Row():
733
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
 
742
  update_button.click(
743
  update_vectors,
744
  inputs=[file_input, parser_dropdown],
745
+ outputs=[update_output, chat_interface.additional_inputs[-1]]
746
  )
747
 
748
  # Add the refresh button functionality
749
  refresh_button.click(
750
  refresh_documents,
751
  inputs=[],
752
+ outputs=[chat_interface.additional_inputs[-1]]
753
  )
754
 
755
  # Add the delete button functionality
756
  delete_button.click(
757
  delete_documents,
758
+ inputs=[chat_interface.additional_inputs[-1]],
759
+ outputs=[update_output, chat_interface.additional_inputs[-1]]
760
  )
761
+
762
  gr.Markdown(
763
  """
764
  ## How to use
 
771
  7. Use the provided examples or ask your own questions.
772
  """
773
  )
774
+
775
+ # Add the dark mode toggle functionality
776
+ dark_mode_button.click(
777
+ toggle_dark_mode,
778
+ inputs=[dark_mode],
779
+ outputs=[dark_mode, dark_mode_button]
780
+ )
781
+
782
+ # Add a function to update the CSS classes based on dark mode state
783
+ def update_dark_mode(dark_mode):
784
+ return {
785
+ "body": "dark-mode" if dark_mode else "",
786
+ ".gradio-container": "dark-mode" if dark_mode else "",
787
+ }
788
+
789
+ dark_mode.change(
790
+ update_dark_mode,
791
+ inputs=[dark_mode],
792
+ outputs=[gr.outputs.HTMLClasses()]
793
+ )
794
 
795
  if __name__ == "__main__":
796
  demo.launch(share=True)