Spaces:
Paused
Paused
Shreyas094
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -243,7 +243,7 @@ def retry_last_response(history, use_web_search, model, temperature, num_calls):
|
|
243 |
|
244 |
return chatbot_interface(last_user_msg, history, use_web_search, model, temperature, num_calls)
|
245 |
|
246 |
-
def respond(message, history, model, temperature, num_calls,
|
247 |
logging.info(f"User Query: {message}")
|
248 |
logging.info(f"Model Used: {model}")
|
249 |
logging.info(f"Search Type: {'Web Search' if use_web_search else 'PDF Search'}")
|
@@ -478,60 +478,56 @@ def display_documents():
|
|
478 |
|
479 |
# Define the checkbox outside the demo block
|
480 |
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
|
|
481 |
use_web_search = gr.Checkbox(label="Use Web Search", value=True)
|
482 |
|
483 |
-
demo = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
|
|
|
485 |
with demo:
|
486 |
-
chatbot = gr.ChatInterface(
|
487 |
-
respond,
|
488 |
-
additional_inputs=[
|
489 |
-
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
|
490 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
491 |
-
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
492 |
-
document_selector, # Add the document selector to the chat interface
|
493 |
-
use_web_search
|
494 |
-
],
|
495 |
-
title="AI-powered Web Search and PDF Chat Assistant",
|
496 |
-
description="Chat with your PDFs or use web search to answer questions",
|
497 |
-
theme=gr.themes.Soft(
|
498 |
-
primary_hue="orange",
|
499 |
-
secondary_hue="amber",
|
500 |
-
neutral_hue="gray",
|
501 |
-
font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]
|
502 |
-
).set(
|
503 |
-
body_background_fill_dark="#0c0505",
|
504 |
-
block_background_fill_dark="#0c0505",
|
505 |
-
block_border_width="1px",
|
506 |
-
block_title_background_fill_dark="#1b0f0f",
|
507 |
-
input_background_fill_dark="#140b0b",
|
508 |
-
button_secondary_background_fill_dark="#140b0b",
|
509 |
-
border_color_accent_dark="#1b0f0f",
|
510 |
-
border_color_primary_dark="#1b0f0f",
|
511 |
-
background_fill_secondary_dark="#0c0505",
|
512 |
-
color_accent_soft_dark="transparent",
|
513 |
-
code_background_fill_dark="#140b0b"
|
514 |
-
),
|
515 |
-
css=css,
|
516 |
-
examples=[
|
517 |
-
["Tell me about the contents of the uploaded PDFs."],
|
518 |
-
["What are the main topics discussed in the documents?"],
|
519 |
-
["Can you summarize the key points from the PDFs?"]
|
520 |
-
],
|
521 |
-
cache_examples=False,
|
522 |
-
analytics_enabled=False,
|
523 |
-
)
|
524 |
-
|
525 |
-
|
526 |
-
# Add file upload functionality
|
527 |
gr.Markdown("## Upload PDF Documents")
|
528 |
|
529 |
with gr.Row():
|
530 |
file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
|
531 |
parser_dropdown = gr.Dropdown(choices=["pypdf", "llamaparse"], label="Select PDF Parser", value="llamaparse")
|
532 |
update_button = gr.Button("Upload Document")
|
533 |
-
|
534 |
-
|
535 |
|
536 |
update_output = gr.Textbox(label="Update Status")
|
537 |
|
|
|
243 |
|
244 |
return chatbot_interface(last_user_msg, history, use_web_search, model, temperature, num_calls)
|
245 |
|
246 |
+
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
247 |
logging.info(f"User Query: {message}")
|
248 |
logging.info(f"Model Used: {model}")
|
249 |
logging.info(f"Search Type: {'Web Search' if use_web_search else 'PDF Search'}")
|
|
|
478 |
|
479 |
# Define the checkbox outside the demo block
|
480 |
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
481 |
+
|
482 |
use_web_search = gr.Checkbox(label="Use Web Search", value=True)
|
483 |
|
484 |
+
demo = gr.ChatInterface(
|
485 |
+
respond,
|
486 |
+
additional_inputs=[
|
487 |
+
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
|
488 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
489 |
+
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
490 |
+
use_web_search,
|
491 |
+
document_selector # Add the document selector to the chat interface
|
492 |
+
],
|
493 |
+
title="AI-powered Web Search and PDF Chat Assistant",
|
494 |
+
description="Chat with your PDFs or use web search to answer questions (Please use toggle under Additional Inputs to swithc between PDF and Web Search, Default Value Web Search)",
|
495 |
+
theme=gr.themes.Soft(
|
496 |
+
primary_hue="orange",
|
497 |
+
secondary_hue="amber",
|
498 |
+
neutral_hue="gray",
|
499 |
+
font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]
|
500 |
+
).set(
|
501 |
+
body_background_fill_dark="#0c0505",
|
502 |
+
block_background_fill_dark="#0c0505",
|
503 |
+
block_border_width="1px",
|
504 |
+
block_title_background_fill_dark="#1b0f0f",
|
505 |
+
input_background_fill_dark="#140b0b",
|
506 |
+
button_secondary_background_fill_dark="#140b0b",
|
507 |
+
border_color_accent_dark="#1b0f0f",
|
508 |
+
border_color_primary_dark="#1b0f0f",
|
509 |
+
background_fill_secondary_dark="#0c0505",
|
510 |
+
color_accent_soft_dark="transparent",
|
511 |
+
code_background_fill_dark="#140b0b"
|
512 |
+
),
|
513 |
+
css=css,
|
514 |
+
examples=[
|
515 |
+
["Tell me about the contents of the uploaded PDFs."],
|
516 |
+
["What are the main topics discussed in the documents?"],
|
517 |
+
["Can you summarize the key points from the PDFs?"]
|
518 |
+
],
|
519 |
+
cache_examples=False,
|
520 |
+
analytics_enabled=False,
|
521 |
+
)
|
522 |
|
523 |
+
# Add file upload functionality
|
524 |
with demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
gr.Markdown("## Upload PDF Documents")
|
526 |
|
527 |
with gr.Row():
|
528 |
file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
|
529 |
parser_dropdown = gr.Dropdown(choices=["pypdf", "llamaparse"], label="Select PDF Parser", value="llamaparse")
|
530 |
update_button = gr.Button("Upload Document")
|
|
|
|
|
531 |
|
532 |
update_output = gr.Textbox(label="Update Status")
|
533 |
|