Shreyas094 commited on
Commit
055a6f3
·
verified ·
1 Parent(s): 188f825

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -659,6 +659,7 @@ def display_documents():
659
  label="Select documents to query or delete"
660
  )
661
 
 
662
  def initial_conversation():
663
  return [
664
  (None, "Welcome! I'm your AI assistant for web search and PDF analysis. Here's how you can use me:\n\n"
@@ -681,13 +682,13 @@ use_web_search = gr.Checkbox(label="Use Web Search", value=False)
681
 
682
  custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
683
 
 
684
  # Create the Gradio interface
685
  with gr.Blocks() as demo:
686
  gr.Markdown("# AI-powered PDF Chat and Web Search Assistant")
687
 
688
  audio_input = gr.Audio(sources=["microphone"], type="numpy", label="Speak your query")
689
 
690
- # Create the Chatbot component separately
691
  chatbot = gr.Chatbot(
692
  show_copy_button=True,
693
  likeable=True,
@@ -696,9 +697,9 @@ with gr.Blocks() as demo:
696
  value=initial_conversation()
697
  )
698
 
699
- # Create the ChatInterface using the pre-defined Chatbot
700
  chat_interface = gr.ChatInterface(
701
  fn=process_input,
 
702
  additional_inputs=[
703
  gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
704
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
@@ -707,11 +708,25 @@ with gr.Blocks() as demo:
707
  gr.CheckboxGroup(label="Select documents to query"),
708
  audio_input
709
  ],
710
- chatbot=chatbot, # Use the pre-defined Chatbot
711
  title="AI-powered PDF Chat and Web Search Assistant",
712
  description="Chat with your PDFs, use web search to answer questions, or speak your query.",
713
  theme=gr.themes.Soft(
714
- # ... (theme configuration remains the same)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  ),
716
  css=css,
717
  examples=[
@@ -724,7 +739,7 @@ with gr.Blocks() as demo:
724
  analytics_enabled=False,
725
  textbox=gr.Textbox(placeholder="Ask a question about the uploaded PDFs or any topic", container=False, scale=7),
726
  )
727
- with demo:
728
  gr.Markdown("## Upload and Manage PDF Documents")
729
  with gr.Row():
730
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
@@ -735,25 +750,23 @@ with demo:
735
  update_output = gr.Textbox(label="Update Status")
736
  delete_button = gr.Button("Delete Selected Documents")
737
 
738
- # Update both the output text and the document selector
739
  update_button.click(
740
  update_vectors,
741
  inputs=[file_input, parser_dropdown],
742
- outputs=[update_output, demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
743
  )
744
 
745
- # Add the refresh button functionality
746
  refresh_button.click(
747
  refresh_documents,
748
  inputs=[],
749
- outputs=[demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs
750
  )
751
 
752
- # Add the delete button functionality
753
  delete_button.click(
754
  delete_documents,
755
- inputs=[demo.additional_inputs[-1]], # Use the CheckboxGroup from additional_inputs
756
- outputs=[update_output, demo.additional_inputs[-1]]
757
  )
758
 
759
  gr.Markdown(
@@ -770,4 +783,4 @@ with demo:
770
  )
771
 
772
  if __name__ == "__main__":
773
- demo.launch(share=True)
 
659
  label="Select documents to query or delete"
660
  )
661
 
662
+ # Define initial conversation
663
  def initial_conversation():
664
  return [
665
  (None, "Welcome! I'm your AI assistant for web search and PDF analysis. Here's how you can use me:\n\n"
 
682
 
683
  custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
684
 
685
+ # Create the Gradio interface
686
  # Create the Gradio interface
687
  with gr.Blocks() as demo:
688
  gr.Markdown("# AI-powered PDF Chat and Web Search Assistant")
689
 
690
  audio_input = gr.Audio(sources=["microphone"], type="numpy", label="Speak your query")
691
 
 
692
  chatbot = gr.Chatbot(
693
  show_copy_button=True,
694
  likeable=True,
 
697
  value=initial_conversation()
698
  )
699
 
 
700
  chat_interface = gr.ChatInterface(
701
  fn=process_input,
702
+ chatbot=chatbot,
703
  additional_inputs=[
704
  gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
705
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
 
708
  gr.CheckboxGroup(label="Select documents to query"),
709
  audio_input
710
  ],
 
711
  title="AI-powered PDF Chat and Web Search Assistant",
712
  description="Chat with your PDFs, use web search to answer questions, or speak your query.",
713
  theme=gr.themes.Soft(
714
+ primary_hue="orange",
715
+ secondary_hue="amber",
716
+ neutral_hue="gray",
717
+ font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]
718
+ ).set(
719
+ body_background_fill_dark="#0c0505",
720
+ block_background_fill_dark="#0c0505",
721
+ block_border_width="1px",
722
+ block_title_background_fill_dark="#1b0f0f",
723
+ input_background_fill_dark="#140b0b",
724
+ button_secondary_background_fill_dark="#140b0b",
725
+ border_color_accent_dark="#1b0f0f",
726
+ border_color_primary_dark="#1b0f0f",
727
+ background_fill_secondary_dark="#0c0505",
728
+ color_accent_soft_dark="transparent",
729
+ code_background_fill_dark="#140b0b"
730
  ),
731
  css=css,
732
  examples=[
 
739
  analytics_enabled=False,
740
  textbox=gr.Textbox(placeholder="Ask a question about the uploaded PDFs or any topic", container=False, scale=7),
741
  )
742
+
743
  gr.Markdown("## Upload and Manage PDF Documents")
744
  with gr.Row():
745
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
 
750
  update_output = gr.Textbox(label="Update Status")
751
  delete_button = gr.Button("Delete Selected Documents")
752
 
753
+ # Set up event handlers for document management
754
  update_button.click(
755
  update_vectors,
756
  inputs=[file_input, parser_dropdown],
757
+ outputs=[update_output, chat_interface.additional_inputs[-2]] # Assuming the CheckboxGroup is the second-to-last additional input
758
  )
759
 
 
760
  refresh_button.click(
761
  refresh_documents,
762
  inputs=[],
763
+ outputs=[chat_interface.additional_inputs[-2]] # Assuming the CheckboxGroup is the second-to-last additional input
764
  )
765
 
 
766
  delete_button.click(
767
  delete_documents,
768
+ inputs=[chat_interface.additional_inputs[-2]], # Assuming the CheckboxGroup is the second-to-last additional input
769
+ outputs=[update_output, chat_interface.additional_inputs[-2]]
770
  )
771
 
772
  gr.Markdown(
 
783
  )
784
 
785
  if __name__ == "__main__":
786
+ demo.launch(share=True)