Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,7 +68,11 @@ def get_embeddings():
|
|
| 68 |
def update_vectors(files, parser):
|
| 69 |
global uploaded_documents
|
| 70 |
if not files:
|
| 71 |
-
return "Please upload at least one PDF file."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
embed = get_embeddings()
|
| 74 |
total_chunks = 0
|
|
@@ -78,7 +82,9 @@ def update_vectors(files, parser):
|
|
| 78 |
data = load_document(file, parser)
|
| 79 |
all_data.extend(data)
|
| 80 |
total_chunks += len(data)
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if os.path.exists("faiss_database"):
|
| 84 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
|
@@ -431,13 +437,14 @@ document_selector = gr.CheckboxGroup(label="Select documents to query")
|
|
| 431 |
use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
| 432 |
|
| 433 |
demo = gr.ChatInterface(
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
|
|
|
| 441 |
title="AI-powered Web Search and PDF Chat Assistant",
|
| 442 |
description="Chat with your PDFs or use web search to answer questions.",
|
| 443 |
theme=gr.themes.Soft(
|
|
@@ -478,7 +485,6 @@ with demo:
|
|
| 478 |
update_button = gr.Button("Upload Document")
|
| 479 |
|
| 480 |
update_output = gr.Textbox(label="Update Status")
|
| 481 |
-
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
| 482 |
|
| 483 |
# Update both the output text and the document selector
|
| 484 |
update_button.click(update_vectors,
|
|
|
|
| 68 |
def update_vectors(files, parser):
|
| 69 |
global uploaded_documents
|
| 70 |
if not files:
|
| 71 |
+
return "Please upload at least one PDF file.", gr.CheckboxGroup(
|
| 72 |
+
choices=[doc["name"] for doc in uploaded_documents],
|
| 73 |
+
value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
|
| 74 |
+
label="Select documents to query"
|
| 75 |
+
)
|
| 76 |
|
| 77 |
embed = get_embeddings()
|
| 78 |
total_chunks = 0
|
|
|
|
| 82 |
data = load_document(file, parser)
|
| 83 |
all_data.extend(data)
|
| 84 |
total_chunks += len(data)
|
| 85 |
+
# Append new documents instead of replacing
|
| 86 |
+
if not any(doc["name"] == file.name for doc in uploaded_documents):
|
| 87 |
+
uploaded_documents.append({"name": file.name, "selected": True})
|
| 88 |
|
| 89 |
if os.path.exists("faiss_database"):
|
| 90 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
|
|
|
| 437 |
use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
| 438 |
|
| 439 |
demo = gr.ChatInterface(
|
| 440 |
+
respond,
|
| 441 |
+
additional_inputs=[
|
| 442 |
+
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0]),
|
| 443 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
| 444 |
+
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
| 445 |
+
use_web_search,
|
| 446 |
+
document_selector # Add the document selector to the chat interface
|
| 447 |
+
],
|
| 448 |
title="AI-powered Web Search and PDF Chat Assistant",
|
| 449 |
description="Chat with your PDFs or use web search to answer questions.",
|
| 450 |
theme=gr.themes.Soft(
|
|
|
|
| 485 |
update_button = gr.Button("Upload Document")
|
| 486 |
|
| 487 |
update_output = gr.Textbox(label="Update Status")
|
|
|
|
| 488 |
|
| 489 |
# Update both the output text and the document selector
|
| 490 |
update_button.click(update_vectors,
|