Spaces:
Running
Running
File size: 2,841 Bytes
ca9bb83 e40971e 00cacd9 ecb9aad cb9f424 ca9bb83 e40971e 5a02e5f 1289a5c 7038b6e ca9bb83 97c6d6a ca9bb83 e40971e 97c6d6a ecb9aad 97c6d6a 8ed4a95 ecb9aad 806791d fde3f64 97c6d6a d1cc2bb ecb9aad 97c6d6a ca9bb83 97c6d6a abefda5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
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) |