Shreyas094 commited on
Commit
d1cc2bb
·
verified ·
1 Parent(s): 9acbbf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -45,8 +45,6 @@ llama_parser = LlamaParse(
45
  language="en",
46
  )
47
 
48
- uploaded_documents = []
49
-
50
  def load_document(file: NamedTemporaryFile, parser: str = "llamaparse") -> List[Document]:
51
  """Loads and splits the document into pages."""
52
  if parser == "pypdf":
@@ -410,7 +408,8 @@ css = """
410
  /* Add your custom CSS here */
411
  """
412
 
413
- # Define the checkbox outside the demo block
 
414
  def display_documents():
415
  return gr.CheckboxGroup(
416
  choices=[doc["name"] for doc in uploaded_documents],
@@ -418,6 +417,7 @@ def display_documents():
418
  label="Select documents to query"
419
  )
420
 
 
421
  document_selector = gr.CheckboxGroup(label="Select documents to query")
422
 
423
  use_web_search = gr.Checkbox(label="Use Web Search", value=False)
@@ -429,7 +429,7 @@ demo = gr.ChatInterface(
429
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
430
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
431
  use_web_search,
432
- document_selector # Add this line to include the document selector
433
  ],
434
  title="AI-powered Web Search and PDF Chat Assistant",
435
  description="Chat with your PDFs or use web search to answer questions.",
@@ -451,7 +451,6 @@ demo = gr.ChatInterface(
451
  color_accent_soft_dark="transparent",
452
  code_background_fill_dark="#140b0b"
453
  ),
454
-
455
  css=css,
456
  examples=[
457
  ["Tell me about the contents of the uploaded PDFs."],
@@ -473,17 +472,18 @@ with demo:
473
 
474
  update_output = gr.Textbox(label="Update Status")
475
  update_button.click(update_vectors, inputs=[file_input, parser_dropdown], outputs=update_output)
 
476
 
477
-
478
  gr.Markdown(
479
  """
480
  ## How to use
481
  1. Upload PDF documents using the file input at the top.
482
  2. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store.
483
- 3. Ask questions in the chat interface.
484
- 4. Toggle "Use Web Search" to switch between PDF chat and web search.
485
- 5. Adjust Temperature and Number of API Calls to fine-tune the response generation.
486
- 6. Use the provided examples or ask your own questions.
 
487
  """
488
  )
489
 
 
45
  language="en",
46
  )
47
 
 
 
48
  def load_document(file: NamedTemporaryFile, parser: str = "llamaparse") -> List[Document]:
49
  """Loads and splits the document into pages."""
50
  if parser == "pypdf":
 
408
  /* Add your custom CSS here */
409
  """
410
 
411
+ uploaded_documents = []
412
+
413
  def display_documents():
414
  return gr.CheckboxGroup(
415
  choices=[doc["name"] for doc in uploaded_documents],
 
417
  label="Select documents to query"
418
  )
419
 
420
+ # Define the checkbox outside the demo block
421
  document_selector = gr.CheckboxGroup(label="Select documents to query")
422
 
423
  use_web_search = gr.Checkbox(label="Use Web Search", value=False)
 
429
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
430
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
431
  use_web_search,
432
+ document_selector
433
  ],
434
  title="AI-powered Web Search and PDF Chat Assistant",
435
  description="Chat with your PDFs or use web search to answer questions.",
 
451
  color_accent_soft_dark="transparent",
452
  code_background_fill_dark="#140b0b"
453
  ),
 
454
  css=css,
455
  examples=[
456
  ["Tell me about the contents of the uploaded PDFs."],
 
472
 
473
  update_output = gr.Textbox(label="Update Status")
474
  update_button.click(update_vectors, inputs=[file_input, parser_dropdown], outputs=update_output)
475
+ update_button.click(display_documents, outputs=document_selector)
476
 
 
477
  gr.Markdown(
478
  """
479
  ## How to use
480
  1. Upload PDF documents using the file input at the top.
481
  2. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store.
482
+ 3. Select the documents you want to query using the checkboxes.
483
+ 4. Ask questions in the chat interface.
484
+ 5. Toggle "Use Web Search" to switch between PDF chat and web search.
485
+ 6. Adjust Temperature and Number of API Calls to fine-tune the response generation.
486
+ 7. Use the provided examples or ask your own questions.
487
  """
488
  )
489