ola13 commited on
Commit
996f0c9
1 Parent(s): a113452
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -276,7 +276,6 @@ if __name__ == "__main__":
276
  highlight_terms_state = gr.State([])
277
  num_results_state = gr.State(0)
278
  exact_search_state = gr.State(False)
279
- lang_state = gr.State("")
280
  received_results_state = gr.State(0)
281
 
282
  with gr.Row():
@@ -344,7 +343,14 @@ if __name__ == "__main__":
344
  else:
345
  query = " ".join(query.split())
346
  if query == "" or query is None:
347
- return no_query_error_message()
 
 
 
 
 
 
 
348
 
349
  payload = request_payload(query, lang, exact_search, k, received_results)
350
  err = extract_error_from_payload(payload)
@@ -376,9 +382,6 @@ if __name__ == "__main__":
376
 
377
  def submit(query, lang, k, dropdown_input):
378
  print("submitting", query, lang, k)
379
- response = run_query(query, lang, k, dropdown_input, 0)
380
- if not isinstance(response, tuple):
381
- return {result_page_html: response}
382
  (
383
  processed_results,
384
  highlight_terms,
@@ -386,17 +389,24 @@ if __name__ == "__main__":
386
  exact_search,
387
  result_page,
388
  datasets,
389
- ) = response
390
  has_more_results = exact_search and (num_results > k)
 
 
 
 
 
391
  return [
392
  processed_results,
393
  highlight_terms,
394
  num_results,
395
  exact_search,
396
- gr.update(visible=True),
 
 
397
  gr.Dropdown.update(choices=datasets, value=datasets),
398
  gr.update(visible=has_more_results),
399
- len(next(iter(processed_results.values()))),
400
  result_page,
401
  ]
402
 
@@ -408,9 +418,6 @@ if __name__ == "__main__":
408
  received_results,
409
  processed_results,
410
  ):
411
- response = run_query(query, lang, k, dropdown_input, received_results)
412
- if not isinstance(response, tuple):
413
- return {result_page_html: response}
414
  (
415
  processed_results,
416
  highlight_terms,
@@ -418,7 +425,7 @@ if __name__ == "__main__":
418
  exact_search,
419
  result_page,
420
  datasets,
421
- ) = response
422
  current_results = sum(
423
  len(results) for results in processed_results.values()
424
  )
@@ -433,7 +440,9 @@ if __name__ == "__main__":
433
  highlight_terms,
434
  num_results,
435
  exact_search,
436
- gr.update(visible=True),
 
 
437
  gr.Dropdown.update(choices=datasets, value=datasets),
438
  gr.update(visible=current_results >= k and has_more_results),
439
  received_results + current_results,
 
276
  highlight_terms_state = gr.State([])
277
  num_results_state = gr.State(0)
278
  exact_search_state = gr.State(False)
 
279
  received_results_state = gr.State(0)
280
 
281
  with gr.Row():
 
343
  else:
344
  query = " ".join(query.split())
345
  if query == "" or query is None:
346
+ return (
347
+ [],
348
+ [],
349
+ 0,
350
+ False,
351
+ no_query_error_message(),
352
+ [],
353
+ )
354
 
355
  payload = request_payload(query, lang, exact_search, k, received_results)
356
  err = extract_error_from_payload(payload)
 
382
 
383
  def submit(query, lang, k, dropdown_input):
384
  print("submitting", query, lang, k)
 
 
 
385
  (
386
  processed_results,
387
  highlight_terms,
 
389
  exact_search,
390
  result_page,
391
  datasets,
392
+ ) = run_query(query, lang, k, dropdown_input, 0)
393
  has_more_results = exact_search and (num_results > k)
394
+ current_results = (
395
+ len(next(iter(processed_results.values())))
396
+ if len(processed_results) > 0
397
+ else 0
398
+ )
399
  return [
400
  processed_results,
401
  highlight_terms,
402
  num_results,
403
  exact_search,
404
+ gr.update(visible=True)
405
+ if current_results > 0
406
+ else gr.update(visible=False),
407
  gr.Dropdown.update(choices=datasets, value=datasets),
408
  gr.update(visible=has_more_results),
409
+ current_results,
410
  result_page,
411
  ]
412
 
 
418
  received_results,
419
  processed_results,
420
  ):
 
 
 
421
  (
422
  processed_results,
423
  highlight_terms,
 
425
  exact_search,
426
  result_page,
427
  datasets,
428
+ ) = run_query(query, lang, k, dropdown_input, received_results)
429
  current_results = sum(
430
  len(results) for results in processed_results.values()
431
  )
 
440
  highlight_terms,
441
  num_results,
442
  exact_search,
443
+ gr.update(visible=True)
444
+ if current_results > 0
445
+ else gr.update(visible=False),
446
  gr.Dropdown.update(choices=datasets, value=datasets),
447
  gr.update(visible=current_results >= k and has_more_results),
448
  received_results + current_results,