Cachoups commited on
Commit
ba7023b
·
verified ·
1 Parent(s): cf618bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -80,6 +80,21 @@ def extract_and_paragraph(pdf1, pdf2, paragraph):
80
 
81
  return paragraphs_1, paragraphs_2
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def process_paragraph_1_sum(paragraph):
84
  try:
85
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
@@ -464,7 +479,14 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
464
  b1 = gr.Button("Extract and Display Paragraphs")
465
  paragraph_1_dropdown = gr.Dropdown(label="Select Paragraph from PDF 1")
466
  paragraph_2_dropdown = gr.Dropdown(label="Select Paragraph from PDF 2")
467
-
 
 
 
 
 
 
 
468
  # Extract paragraphs from PDFs and update dropdowns
469
  def update_paragraphs(pdf1, pdf2):
470
  global stored_paragraphs_1, stored_paragraphs_2
 
80
 
81
  return paragraphs_1, paragraphs_2
82
 
83
+ # Filter
84
+ def filter_paragraphs(keyword):
85
+ global stored_paragraphs_1, stored_paragraphs_2
86
+ if not keyword:
87
+ return gr.update(choices=stored_paragraphs_1, value=None), gr.update(choices=stored_paragraphs_2, value=None) # No keyword entered, return original list
88
+
89
+ # Filter paragraphs that contain the keyword (case-insensitive)
90
+ filtered1 = [p for p in stored_paragraphs_1 if keyword.lower() in p.lower()]
91
+ filtered2 = [p for p in stored_paragraphs_2 if keyword.lower() in p.lower()]
92
+ # Update dropdown with filtered results
93
+ return gr.update(choices=filtered1, value=None), gr.update(choices=filtered2, value=None)
94
+
95
+ def clear_paragraphs():
96
+ global stored_paragraphs_1, stored_paragraphs_2
97
+ return gr.update(choices=stored_paragraphs_1, value=None), gr.update(choices=stored_paragraphs_2, value=None)
98
  def process_paragraph_1_sum(paragraph):
99
  try:
100
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
 
479
  b1 = gr.Button("Extract and Display Paragraphs")
480
  paragraph_1_dropdown = gr.Dropdown(label="Select Paragraph from PDF 1")
481
  paragraph_2_dropdown = gr.Dropdown(label="Select Paragraph from PDF 2")
482
+
483
+ keyword_input = gr.Textbox(label="Enter keyword to search")
484
+ # Button to trigger the filtering
485
+ with gr.Row():
486
+ search_button = gr.Button("Search")
487
+ clear_button = gr.Button("Clear")
488
+ search_button.click(filter_paragraphs, inputs=keyword_input, outputs=[pdf1, pdf2])
489
+ clear_button.click(clear_parargraphs, inputs=[], outputs=[pdf1, pdf2])
490
  # Extract paragraphs from PDFs and update dropdowns
491
  def update_paragraphs(pdf1, pdf2):
492
  global stored_paragraphs_1, stored_paragraphs_2