Spaces:
Running
Running
demo = gr.ChatInterface( | |
respond, | |
additional_inputs=[ | |
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0]), | |
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"), | |
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"), | |
use_web_search, | |
document_selector # Add the document selector to the chat interface | |
], | |
title="AI-powered Web Search and PDF Chat Assistant", | |
description="Chat with your PDFs or use web search to answer questions.", | |
theme=gr.themes.Soft( | |
primary_hue="orange", | |
secondary_hue="amber", | |
neutral_hue="gray", | |
font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"] | |
).set( | |
body_background_fill_dark="#0c0505", | |
block_background_fill_dark="#0c0505", | |
block_border_width="1px", | |
block_title_background_fill_dark="#1b0f0f", | |
input_background_fill_dark="#140b0b", | |
button_secondary_background_fill_dark="#140b0b", | |
border_color_accent_dark="#1b0f0f", | |
border_color_primary_dark="#1b0f0f", | |
background_fill_secondary_dark="#0c0505", | |
color_accent_soft_dark="transparent", | |
code_background_fill_dark="#140b0b" | |
), | |
css=css, | |
examples=[ | |
["Tell me about the contents of the uploaded PDFs."], | |
["What are the main topics discussed in the documents?"], | |
["Can you summarize the key points from the PDFs?"] | |
], | |
cache_examples=False, | |
analytics_enabled=False, | |
) | |
# Add file upload functionality | |
with demo: | |
gr.Markdown("## Upload PDF Documents") | |
with gr.Row(): | |
file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"]) | |
parser_dropdown = gr.Dropdown(choices=["pypdf", "llamaparse"], label="Select PDF Parser", value="llamaparse") | |
update_button = gr.Button("Upload Document") | |
update_output = gr.Textbox(label="Update Status") | |
# Update both the output text and the document selector | |
update_button.click(update_vectors, | |
inputs=[file_input, parser_dropdown], | |
outputs=[update_output, document_selector]) | |
gr.Markdown( | |
""" | |
## How to use | |
1. Upload PDF documents using the file input at the top. | |
2. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store. | |
3. Select the documents you want to query using the checkboxes. | |
4. Ask questions in the chat interface. | |
5. Toggle "Use Web Search" to switch between PDF chat and web search. | |
6. Adjust Temperature and Number of API Calls to fine-tune the response generation. | |
7. Use the provided examples or ask your own questions. | |
""" | |
) | |
if __name__ == "__main__": | |
demo.launch(share=True) |