neuralworm commited on
Commit
d300238
·
1 Parent(s): 4eaf9a0

add search interface

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -414,14 +414,19 @@ with gr.Blocks() as app:
414
  with gr.Row():
415
  main_book_filter = gr.Dropdown(label="Filter by Main Book",
416
  choices=["All", "Torah", "Bible", "Quran", "Rig Veda", "Tripitaka"],
417
- value="All")
418
  # Keine choices hier, nur das Label und den Initialwert
419
- rounds_filter = gr.Dropdown(label="Filter by Rounds", value="All")
420
 
421
  with gr.Row():
422
  search_type = gr.Radio(label="Search by",
423
  choices=["Text in result_text", "Gematria Sum in results"],
424
  value="Text in result_text")
 
 
 
 
 
425
  with gr.Row():
426
  search_term = gr.Textbox(label="Search Term", visible=True)
427
  gematria_sum_search = gr.Number(label="Gematria Sum", visible=False)
@@ -438,9 +443,10 @@ with gr.Blocks() as app:
438
  return gr.Textbox.update(visible=False), gr.Number.update(visible=True)
439
 
440
 
441
- def search_cache_database(search_type, search_term, gematria_sum_search, main_book_filter, rounds_filter):
442
  """Searches the cache database based on the selected filters and search term."""
443
  results = []
 
444
  if main_book_filter == "All" and rounds_filter == "All" and not search_term and not gematria_sum_search:
445
  return results
446
 
@@ -487,14 +493,23 @@ with gr.Blocks() as app:
487
  try:
488
  results_json = json.loads(row_dict['results'])
489
  for result_entry in results_json:
490
- if 'result_text' in result_entry and search_term in result_entry['result_text']:
491
- entry = {
492
- 'function_name': function_name,
493
- 'step': args_dict.get('step'),
494
- 'rounds': args_dict.get('rounds'),
495
- 'result': result_entry
496
- }
497
- results.append(entry)
 
 
 
 
 
 
 
 
 
498
  except (json.JSONDecodeError, TypeError) as e:
499
  logger.error(f"Error processing row: {e}")
500
  continue
@@ -581,7 +596,7 @@ with gr.Blocks() as app:
581
 
582
  search_db_btn.click(
583
  fn=search_cache_database,
584
- inputs=[search_type, search_term, gematria_sum_search, main_book_filter, rounds_filter],
585
  outputs=cache_search_results
586
  )
587
 
@@ -690,10 +705,10 @@ with gr.Blocks() as app:
690
  most_frequent_phrase = get_most_frequent_phrase(matching_phrases)
691
  most_frequent_phrases[book_name] = most_frequent_phrase
692
  else:
693
- closest_phrase = find_closest_phrase(result['result_text'],
694
- search_gematria_in_db(gematria_sum, max_words_limit))
695
  most_frequent_phrases[
696
- book_name] = closest_phrase or ""
697
 
698
  result['Most Frequent Phrase'] = most_frequent_phrases[book_name]
699
  if 'book' in result:
 
414
  with gr.Row():
415
  main_book_filter = gr.Dropdown(label="Filter by Main Book",
416
  choices=["All", "Torah", "Bible", "Quran", "Rig Veda", "Tripitaka"],
417
+ value="Torah")
418
  # Keine choices hier, nur das Label und den Initialwert
419
+ rounds_filter = gr.Dropdown(label="Filter by Rounds", allow_custom_value=True, value="1,-1")
420
 
421
  with gr.Row():
422
  search_type = gr.Radio(label="Search by",
423
  choices=["Text in result_text", "Gematria Sum in results"],
424
  value="Text in result_text")
425
+ with gr.Row():
426
+ search_mode = gr.Radio(label="Search Mode",
427
+ choices=["Exact Search", "Contains Word"],
428
+ value="Contains Word")
429
+
430
  with gr.Row():
431
  search_term = gr.Textbox(label="Search Term", visible=True)
432
  gematria_sum_search = gr.Number(label="Gematria Sum", visible=False)
 
443
  return gr.Textbox.update(visible=False), gr.Number.update(visible=True)
444
 
445
 
446
+ def search_cache_database(search_type, search_term, gematria_sum_search, main_book_filter, rounds_filter, search_mode):
447
  """Searches the cache database based on the selected filters and search term."""
448
  results = []
449
+ search_term = strip_diacritics(search_term)
450
  if main_book_filter == "All" and rounds_filter == "All" and not search_term and not gematria_sum_search:
451
  return results
452
 
 
493
  try:
494
  results_json = json.loads(row_dict['results'])
495
  for result_entry in results_json:
496
+ if 'result_text' in result_entry:
497
+ if search_mode == "Exact Search" and search_term == result_entry['result_text']:
498
+ entry = {
499
+ 'function_name': function_name,
500
+ 'step': args_dict.get('step'),
501
+ 'rounds': args_dict.get('rounds'),
502
+ 'result': result_entry
503
+ }
504
+ results.append(entry)
505
+ elif search_mode == "Contains Word" and search_term in result_entry['result_text']:
506
+ entry = {
507
+ 'function_name': function_name,
508
+ 'step': args_dict.get('step'),
509
+ 'rounds': args_dict.get('rounds'),
510
+ 'result': result_entry
511
+ }
512
+ results.append(entry)
513
  except (json.JSONDecodeError, TypeError) as e:
514
  logger.error(f"Error processing row: {e}")
515
  continue
 
596
 
597
  search_db_btn.click(
598
  fn=search_cache_database,
599
+ inputs=[search_type, search_term, gematria_sum_search, main_book_filter, rounds_filter, search_mode],
600
  outputs=cache_search_results
601
  )
602
 
 
705
  most_frequent_phrase = get_most_frequent_phrase(matching_phrases)
706
  most_frequent_phrases[book_name] = most_frequent_phrase
707
  else:
708
+ # closest_phrase = find_closest_phrase(result['result_text'],
709
+ # search_gematria_in_db(gematria_sum, max_words_limit)) # Removed fuzzywuzzy
710
  most_frequent_phrases[
711
+ book_name] = "" # closest_phrase or ""
712
 
713
  result['Most Frequent Phrase'] = most_frequent_phrases[book_name]
714
  if 'book' in result: