Shreyas094 commited on
Commit
578fd28
·
verified ·
1 Parent(s): 8ec7ba0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
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, use_web_search, selected_docs, instruction_key=None):
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'}")
@@ -251,7 +251,7 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
251
  logging.info(f"Instruction Key: {instruction_key}")
252
 
253
  try:
254
- if instruction_key:
255
  # This is a summary generation request
256
  instruction = INSTRUCTION_PROMPTS[instruction_key]
257
  context_str = get_context_for_summary(selected_docs)
@@ -535,12 +535,7 @@ use_web_search = gr.Checkbox(label="Use Web Search", value=True)
535
 
536
  custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
537
 
538
- instruction_dropdown = gr.Dropdown(choices=list(INSTRUCTION_PROMPTS.keys()), label="Select Entity Type", value=list(INSTRUCTION_PROMPTS.keys())[0])
539
- summary_button = gr.Button("Generate Summary")
540
-
541
- def generate_summary(instruction_key, history, model, temperature, num_calls, use_web_search, selected_docs):
542
- summary_response = next(respond("", history, model, temperature, num_calls, use_web_search, selected_docs, instruction_key))
543
- return history + [("Generate summary for " + instruction_key, summary_response)]
544
 
545
  demo = gr.ChatInterface(
546
  respond,
@@ -550,10 +545,10 @@ demo = gr.ChatInterface(
550
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
551
  use_web_search,
552
  document_selector,
553
- instruction_dropdown,
554
  ],
555
  title="AI-powered Web Search and PDF Chat Assistant",
556
- description="Chat with your PDFs or use web search to answer questions. Toggle between Web Search and PDF Chat in Additional Inputs below.",
557
  theme=gr.themes.Soft(
558
  primary_hue="orange",
559
  secondary_hue="amber",
@@ -589,12 +584,6 @@ demo = gr.ChatInterface(
589
  )
590
  )
591
 
592
- summary_button.click(
593
- generate_summary,
594
- inputs=[instruction_dropdown, demo.chatbot, demo.additional_inputs[0], demo.additional_inputs[1], demo.additional_inputs[2], demo.additional_inputs[3], demo.additional_inputs[4]],
595
- outputs=[demo.chatbot]
596
- )
597
-
598
  # Add file upload functionality
599
  with demo:
600
  gr.Markdown("## Upload PDF Documents")
 
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, instruction_key):
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'}")
 
251
  logging.info(f"Instruction Key: {instruction_key}")
252
 
253
  try:
254
+ if instruction_key and instruction_key != "None":
255
  # This is a summary generation request
256
  instruction = INSTRUCTION_PROMPTS[instruction_key]
257
  context_str = get_context_for_summary(selected_docs)
 
535
 
536
  custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
537
 
538
+ instruction_choices = ["None"] + list(INSTRUCTION_PROMPTS.keys())
 
 
 
 
 
539
 
540
  demo = gr.ChatInterface(
541
  respond,
 
545
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
546
  use_web_search,
547
  document_selector,
548
+ gr.Dropdown(choices=instruction_choices, label="Select Entity Type for Summary", value="None")
549
  ],
550
  title="AI-powered Web Search and PDF Chat Assistant",
551
+ description="Chat with your PDFs, use web search to answer questions, or generate summaries. Select an Entity Type for Summary to generate a specific summary.",
552
  theme=gr.themes.Soft(
553
  primary_hue="orange",
554
  secondary_hue="amber",
 
584
  )
585
  )
586
 
 
 
 
 
 
 
587
  # Add file upload functionality
588
  with demo:
589
  gr.Markdown("## Upload PDF Documents")