Update app.py
Browse files648 unmodified lines6496506516526536546553 unmodified lines6596606616626636646656666676686696706716726736746756766776786796806816826836846856866616876886896906 unmodified lines69769869967470070170270312 unmodified lines7167177186936947197207216966977227237247257267277287297307317327338 unmodified lines7427437447137457467477487497507517207527537547557567577267277587597607297617627637646 unmodified lines771772773774775776777778779780781782783784785786787788789790791792793794795796648 unmodified lines uploaded_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 ChatInterfacedemo = gr.ChatInterface(chat_interface = gr.ChatInterface( respond, additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False), additional_inputs=[6 unmodified lines title="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, 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 ))
# Initialize dark mode statedark_mode = gr.State(False)# Create the main Blocks interfacedemo = gr.Blocks(css=combined_css)
# Add file upload functionality# Add file upload functionalitywith demo: dark_mode = gr.State(False) with gr.Row(): dark_mode_button = gr.Button("Dark Mode") # Add the ChatInterface chat_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 lines update_button.click( update_vectors, inputs=[file_input, parser_dropdown], outputs=[update_output, demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs outputs=[update_output, chat_interface.additional_inputs[-1]] ) # Add the refresh button functionality refresh_button.click( refresh_documents, inputs=[], outputs=[demo.additional_inputs[-1]] # Use the CheckboxGroup from additional_inputs outputs=[chat_interface.additional_inputs[-1]] ) # Add the delete button functionality delete_button.click( delete_documents, inputs=[demo.additional_inputs[-1]], # Use the CheckboxGroup from additional_inputs outputs=[update_output, demo.additional_inputs[-1]] inputs=[chat_interface.additional_inputs[-1]], outputs=[update_output, chat_interface.additional_inputs[-1]] )
gr.Markdown( """ ## How to use6 unmodified lines 7. Use the provided examples or ask your own questions. """ ) # Add the dark mode toggle functionality dark_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 state def 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