Update app.py
Browse files648 unmodified lines6496506516526536543 unmodified lines6586596606616626636646 unmodified lines67167267367467567667712 unmodified lines6906916926936946956966976986997007018 unmodified lines7107117127137147157167177187197207217227237247257267277287297307317326 unmodified lines739740741742743744648 unmodified linesuploaded_documents = load_documents()return display_documents()# Define the checkbox outside the demo blockdocument_selector = gr.CheckboxGroup(label="Select documents to query")3 unmodified lines# Update the demo interface# Update the Gradio interfacedemo = gr.ChatInterface(respond,additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),additional_inputs=[6 unmodified linestitle="AI-powered PDF Chat and Web Search Assistant",description="Chat with your PDFs or use web search to answer questions.",theme=gr.Theme.from_hub("JohnSmith9982/small_and_pretty"),css=css,examples=[["Tell me about the contents of the uploaded PDFs."],["What are the main topics discussed in the documents?"],12 unmodified lines))# Initialize dark mode statedark_mode = gr.State(False)# Add file upload functionality# Add file upload functionalitywith demo:gr.Markdown("## Upload and Manage PDF Documents")with gr.Row():file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])8 unmodified linesupdate_button.click(update_vectors,inputs=[file_input, parser_dropdown],outputs=[update_output, demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs)# Add the refresh button functionalityrefresh_button.click(refresh_documents,inputs=[],outputs=[demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs)# Add the delete button functionalitydelete_button.click(delete_documents,inputs=[demo.additional_inputs[-1]], # Use the CheckboxGroup from additional_inputsoutputs=[update_output, demo.additional_inputs[-1]])gr.Markdown("""## How to use6 unmodified lines7. Use the provided examples or ask your own questions.""")if __name__ == "__main__":demo.launch(share=True)648 unmodified lines6496506516526536546553 unmodified lines6596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906 unmodified lines69769869970070170270312 unmodified lines7167177187197207217227237247257267277287297307317327338 unmodified lines7427437447457467477487497507517527537547557567577587597607617627637646 unmodified lines771772773774775776777778779780781782783784785786787788789790791792793794795796648 unmodified linesuploaded_documents = load_documents()return display_documents()# Define the checkbox outside the demo blockdocument_selector = gr.CheckboxGroup(label="Select documents to query")3 unmodified lines# Update the demo interface# Update the Gradio interfaceimport gradio as gr# Define a custom CSS for dark modedark_mode_css = """.dark-mode {background-color: #1a1a1a;color: #ffffff;}.dark-mode .gradio-slider input[type="range"] {background-color: #4a4a4a;}.dark-mode .gradio-button {background-color: #4a4a4a;color: #ffffff;}"""# Create a function to toggle dark modedef toggle_dark_mode(dark_mode):return not dark_mode, gr.update(value="Light Mode" if dark_mode else "Dark Mode")# Combine the existing CSS with dark mode CSScombined_css = css + dark_mode_css# Create the ChatInterfacechat_interface = gr.ChatInterface(respond,additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),additional_inputs=[6 unmodified linestitle="AI-powered PDF Chat and Web Search Assistant",description="Chat with your PDFs or use web search to answer questions.",theme=gr.Theme.from_hub("JohnSmith9982/small_and_pretty"),css=combined_css,examples=[["Tell me about the contents of the uploaded PDFs."],["What are the main topics discussed in the documents?"],12 unmodified lines))# Create the main Blocks interfacedemo = gr.Blocks(css=combined_css)with demo:dark_mode = gr.State(False)with gr.Row():dark_mode_button = gr.Button("Dark Mode")# Add the ChatInterfacechat_interface.render()gr.Markdown("## Upload and Manage PDF Documents")with gr.Row():file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])8 unmodified linesupdate_button.click(update_vectors,inputs=[file_input, parser_dropdown],outputs=[update_output, chat_interface.additional_inputs[-1]])# Add the refresh button functionalityrefresh_button.click(refresh_documents,inputs=[],outputs=[chat_interface.additional_inputs[-1]])# Add the delete button functionalitydelete_button.click(delete_documents,inputs=[chat_interface.additional_inputs[-1]],outputs=[update_output, chat_interface.additional_inputs[-1]])gr.Markdown("""## How to use6 unmodified lines7. Use the provided examples or ask your own questions.""")# Add the dark mode toggle functionalitydark_mode_button.click(toggle_dark_mode,inputs=[dark_mode],outputs=[dark_mode, dark_mode_button])# Add a function to update the CSS classes based on dark mode statedef update_dark_mode(dark_mode):return {"body": "dark-mode" if dark_mode else "",".gradio-container": "dark-mode" if dark_mode else "",}dark_mode.change(update_dark_mode,inputs=[dark_mode],outputs=[gr.outputs.HTMLClasses()])if __name__ == "__main__":demo.launch(share=True)
app.py+63-11