Spaces:
Paused
Paused
fixes + flagging
Browse files
app.py
CHANGED
@@ -144,7 +144,7 @@ def format_result(result, highlight_terms, exact_search, datasets_filter=None):
|
|
144 |
return "<p>" + result_html + "</p>"
|
145 |
|
146 |
|
147 |
-
def
|
148 |
language, results, highlight_terms, num_results, exact_search, datasets_filter=None
|
149 |
) -> gr.HTML:
|
150 |
|
@@ -157,14 +157,14 @@ def format_result_page_old(
|
|
157 |
list(results.keys())[0]
|
158 |
)
|
159 |
|
160 |
-
|
161 |
for lang, results_for_lang in results.items():
|
162 |
if len(results_for_lang) == 0:
|
163 |
if exact_search:
|
164 |
-
|
165 |
No results found.</div>"""
|
166 |
else:
|
167 |
-
|
168 |
No results for language: <b>{}</b></div>""".format(
|
169 |
lang
|
170 |
)
|
@@ -185,7 +185,7 @@ def format_result_page_old(
|
|
185 |
</summary>
|
186 |
{results_for_lang_html}
|
187 |
</details>"""
|
188 |
-
|
189 |
|
190 |
if num_results is not None:
|
191 |
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
@@ -193,20 +193,7 @@ def format_result_page_old(
|
|
193 |
num_results
|
194 |
)
|
195 |
|
196 |
-
return header_html +
|
197 |
-
|
198 |
-
|
199 |
-
def format_result_page(
|
200 |
-
results, highlight_terms, num_results, exact_search, datasets_filter=None
|
201 |
-
):
|
202 |
-
results_html = []
|
203 |
-
for result in results:
|
204 |
-
result_html = format_result(
|
205 |
-
result, highlight_terms, exact_search, datasets_filter
|
206 |
-
)
|
207 |
-
if result_html != "":
|
208 |
-
results_html.append(result_html)
|
209 |
-
return results_html
|
210 |
|
211 |
|
212 |
def extract_results_from_payload(query, language, payload, exact_search):
|
@@ -344,7 +331,7 @@ if __name__ == "__main__":
|
|
344 |
multiselect=True,
|
345 |
)
|
346 |
with gr.Row():
|
347 |
-
|
348 |
|
349 |
with gr.Row(visible=False) as pagination:
|
350 |
next_page_btn = gr.Button("Next Page")
|
@@ -378,22 +365,7 @@ if __name__ == "__main__":
|
|
378 |
payload,
|
379 |
exact_search,
|
380 |
)
|
381 |
-
|
382 |
-
if lang == "detect_language" and not exact_search:
|
383 |
-
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
384 |
-
Detected language: <b style='color:MediumAquaMarine'>{}</b></div>""".format(
|
385 |
-
"FIX ME!"
|
386 |
-
)
|
387 |
-
if len(processed_results) == 0:
|
388 |
-
header_html += """<div style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
389 |
-
No results found.</div>"""
|
390 |
-
elif num_results is not None:
|
391 |
-
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
392 |
-
Total number of matches: <b style='color:MediumAquaMarine'>{}</b></div>""".format(
|
393 |
-
num_results
|
394 |
-
)
|
395 |
-
# print("processed_results", processed_results)
|
396 |
-
results_html = format_result_page_old(
|
397 |
lang, processed_results, highlight_terms, num_results, exact_search
|
398 |
)
|
399 |
return (
|
@@ -401,7 +373,7 @@ if __name__ == "__main__":
|
|
401 |
highlight_terms,
|
402 |
num_results,
|
403 |
exact_search,
|
404 |
-
|
405 |
ds,
|
406 |
)
|
407 |
|
@@ -411,7 +383,7 @@ if __name__ == "__main__":
|
|
411 |
highlight_terms,
|
412 |
num_results,
|
413 |
exact_search,
|
414 |
-
|
415 |
datasets,
|
416 |
) = run_query(query, lang, k, dropdown_input, max_page_size, 0)
|
417 |
has_more_results = exact_search and (num_results > max_page_size)
|
@@ -423,8 +395,8 @@ if __name__ == "__main__":
|
|
423 |
gr.update(visible=True),
|
424 |
gr.Dropdown.update(choices=datasets, value=datasets),
|
425 |
gr.update(visible=has_more_results),
|
426 |
-
len(processed_results),
|
427 |
-
|
428 |
]
|
429 |
|
430 |
def next_page(
|
@@ -441,12 +413,12 @@ if __name__ == "__main__":
|
|
441 |
highlight_terms,
|
442 |
num_results,
|
443 |
exact_search,
|
444 |
-
|
445 |
datasets,
|
446 |
) = run_query(
|
447 |
query, lang, k, dropdown_input, max_page_size, received_results
|
448 |
)
|
449 |
-
num_processed_results = len(processed_results)
|
450 |
has_more_results = exact_search and (num_results > max_page_size)
|
451 |
print("num_processed_results", num_processed_results)
|
452 |
print("has_more_results", has_more_results)
|
@@ -462,7 +434,7 @@ if __name__ == "__main__":
|
|
462 |
visible=num_processed_results >= max_page_size and has_more_results
|
463 |
),
|
464 |
received_results + num_processed_results,
|
465 |
-
|
466 |
]
|
467 |
|
468 |
def filter_datasets(
|
@@ -473,14 +445,15 @@ if __name__ == "__main__":
|
|
473 |
exact_search,
|
474 |
datasets_filter,
|
475 |
):
|
476 |
-
|
|
|
477 |
processed_results,
|
478 |
highlight_terms,
|
479 |
num_results,
|
480 |
exact_search,
|
481 |
datasets_filter,
|
482 |
)
|
483 |
-
return
|
484 |
|
485 |
query.submit(
|
486 |
fn=submit,
|
@@ -494,7 +467,7 @@ if __name__ == "__main__":
|
|
494 |
available_datasets,
|
495 |
pagination,
|
496 |
received_results_state,
|
497 |
-
|
498 |
],
|
499 |
)
|
500 |
submit_btn.click(
|
@@ -509,7 +482,7 @@ if __name__ == "__main__":
|
|
509 |
available_datasets,
|
510 |
pagination,
|
511 |
received_results_state,
|
512 |
-
|
513 |
],
|
514 |
)
|
515 |
|
@@ -533,7 +506,7 @@ if __name__ == "__main__":
|
|
533 |
available_datasets,
|
534 |
pagination,
|
535 |
received_results_state,
|
536 |
-
|
537 |
],
|
538 |
)
|
539 |
|
@@ -547,6 +520,6 @@ if __name__ == "__main__":
|
|
547 |
exact_search_state,
|
548 |
available_datasets,
|
549 |
],
|
550 |
-
outputs=
|
551 |
)
|
552 |
demo.launch(enable_queue=True, debug=True)
|
|
|
144 |
return "<p>" + result_html + "</p>"
|
145 |
|
146 |
|
147 |
+
def format_result_page(
|
148 |
language, results, highlight_terms, num_results, exact_search, datasets_filter=None
|
149 |
) -> gr.HTML:
|
150 |
|
|
|
157 |
list(results.keys())[0]
|
158 |
)
|
159 |
|
160 |
+
result_page_html = ""
|
161 |
for lang, results_for_lang in results.items():
|
162 |
if len(results_for_lang) == 0:
|
163 |
if exact_search:
|
164 |
+
result_page_html += """<div style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
165 |
No results found.</div>"""
|
166 |
else:
|
167 |
+
result_page_html += """<div style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
168 |
No results for language: <b>{}</b></div>""".format(
|
169 |
lang
|
170 |
)
|
|
|
185 |
</summary>
|
186 |
{results_for_lang_html}
|
187 |
</details>"""
|
188 |
+
result_page_html += results_for_lang_html
|
189 |
|
190 |
if num_results is not None:
|
191 |
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
|
|
193 |
num_results
|
194 |
)
|
195 |
|
196 |
+
return header_html + result_page_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
|
199 |
def extract_results_from_payload(query, language, payload, exact_search):
|
|
|
331 |
multiselect=True,
|
332 |
)
|
333 |
with gr.Row():
|
334 |
+
result_page_html = gr.HTML(label="Results")
|
335 |
|
336 |
with gr.Row(visible=False) as pagination:
|
337 |
next_page_btn = gr.Button("Next Page")
|
|
|
365 |
payload,
|
366 |
exact_search,
|
367 |
)
|
368 |
+
result_page_html = format_result_page(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
lang, processed_results, highlight_terms, num_results, exact_search
|
370 |
)
|
371 |
return (
|
|
|
373 |
highlight_terms,
|
374 |
num_results,
|
375 |
exact_search,
|
376 |
+
result_page_html,
|
377 |
ds,
|
378 |
)
|
379 |
|
|
|
383 |
highlight_terms,
|
384 |
num_results,
|
385 |
exact_search,
|
386 |
+
result_page_html,
|
387 |
datasets,
|
388 |
) = run_query(query, lang, k, dropdown_input, max_page_size, 0)
|
389 |
has_more_results = exact_search and (num_results > max_page_size)
|
|
|
395 |
gr.update(visible=True),
|
396 |
gr.Dropdown.update(choices=datasets, value=datasets),
|
397 |
gr.update(visible=has_more_results),
|
398 |
+
len(next(iter(processed_results.values()))),
|
399 |
+
result_page_html,
|
400 |
]
|
401 |
|
402 |
def next_page(
|
|
|
413 |
highlight_terms,
|
414 |
num_results,
|
415 |
exact_search,
|
416 |
+
result_page_html,
|
417 |
datasets,
|
418 |
) = run_query(
|
419 |
query, lang, k, dropdown_input, max_page_size, received_results
|
420 |
)
|
421 |
+
num_processed_results = len(next(iter(processed_results.values())))
|
422 |
has_more_results = exact_search and (num_results > max_page_size)
|
423 |
print("num_processed_results", num_processed_results)
|
424 |
print("has_more_results", has_more_results)
|
|
|
434 |
visible=num_processed_results >= max_page_size and has_more_results
|
435 |
),
|
436 |
received_results + num_processed_results,
|
437 |
+
result_page_html,
|
438 |
]
|
439 |
|
440 |
def filter_datasets(
|
|
|
445 |
exact_search,
|
446 |
datasets_filter,
|
447 |
):
|
448 |
+
result_page_html = format_result_page(
|
449 |
+
lang,
|
450 |
processed_results,
|
451 |
highlight_terms,
|
452 |
num_results,
|
453 |
exact_search,
|
454 |
datasets_filter,
|
455 |
)
|
456 |
+
return result_page_html
|
457 |
|
458 |
query.submit(
|
459 |
fn=submit,
|
|
|
467 |
available_datasets,
|
468 |
pagination,
|
469 |
received_results_state,
|
470 |
+
result_page_html,
|
471 |
],
|
472 |
)
|
473 |
submit_btn.click(
|
|
|
482 |
available_datasets,
|
483 |
pagination,
|
484 |
received_results_state,
|
485 |
+
result_page_html,
|
486 |
],
|
487 |
)
|
488 |
|
|
|
506 |
available_datasets,
|
507 |
pagination,
|
508 |
received_results_state,
|
509 |
+
result_page_html,
|
510 |
],
|
511 |
)
|
512 |
|
|
|
520 |
exact_search_state,
|
521 |
available_datasets,
|
522 |
],
|
523 |
+
outputs=result_page_html,
|
524 |
)
|
525 |
demo.launch(enable_queue=True, debug=True)
|