Spaces:
Paused
Paused
fix num results
Browse files
app.py
CHANGED
|
@@ -127,28 +127,35 @@ def format_result(result, highlight_terms, exact_search, datasets_filter=None):
|
|
| 127 |
def format_result_page(
|
| 128 |
language, results, highlight_terms, num_results, exact_search, datasets_filter=None
|
| 129 |
) -> gr.HTML:
|
|
|
|
|
|
|
| 130 |
header_html = ""
|
| 131 |
|
| 132 |
# FIX lang detection by normalizing format on the backend
|
| 133 |
if language == "detect_language" and not exact_search:
|
| 134 |
-
header_html
|
| 135 |
-
Detected language: <b> FIX MEEEE !!! </b></p><br
|
| 136 |
|
| 137 |
results_html = ""
|
| 138 |
for lang, results_for_lang in results.items():
|
| 139 |
if len(results_for_lang) == 0:
|
| 140 |
if exact_search:
|
| 141 |
-
results_html +=
|
| 142 |
No results found.<hr></p>"""
|
| 143 |
else:
|
| 144 |
-
results_html +=
|
| 145 |
-
No results for language: <b>{
|
|
|
|
|
|
|
| 146 |
continue
|
| 147 |
results_for_lang_html = ""
|
| 148 |
for result in results_for_lang:
|
| 149 |
-
|
| 150 |
result, highlight_terms, exact_search, datasets_filter
|
| 151 |
)
|
|
|
|
|
|
|
|
|
|
| 152 |
if language == "all" and not exact_search:
|
| 153 |
results_for_lang_html = f"""
|
| 154 |
<details>
|
|
@@ -159,6 +166,12 @@ def format_result_page(
|
|
| 159 |
</details>"""
|
| 160 |
results_html += results_for_lang_html
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
return header_html + results_html
|
| 163 |
|
| 164 |
|
|
@@ -215,9 +228,7 @@ def extract_error_from_payload(payload):
|
|
| 215 |
return None
|
| 216 |
|
| 217 |
|
| 218 |
-
def request_payload(
|
| 219 |
-
query, language, exact_search, num_results=10
|
| 220 |
-
) -> List[Tuple[str, str]]:
|
| 221 |
post_data = {"query": query, "k": num_results}
|
| 222 |
if language != "detect_language":
|
| 223 |
post_data["lang"] = language
|
|
|
|
| 127 |
def format_result_page(
|
| 128 |
language, results, highlight_terms, num_results, exact_search, datasets_filter=None
|
| 129 |
) -> gr.HTML:
|
| 130 |
+
|
| 131 |
+
filtered_num_results = 0
|
| 132 |
header_html = ""
|
| 133 |
|
| 134 |
# FIX lang detection by normalizing format on the backend
|
| 135 |
if language == "detect_language" and not exact_search:
|
| 136 |
+
header_html += """<p style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
| 137 |
+
Detected language: <b> FIX MEEEE !!! </b><hr></p><br>"""
|
| 138 |
|
| 139 |
results_html = ""
|
| 140 |
for lang, results_for_lang in results.items():
|
| 141 |
if len(results_for_lang) == 0:
|
| 142 |
if exact_search:
|
| 143 |
+
results_html += """<p style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
| 144 |
No results found.<hr></p>"""
|
| 145 |
else:
|
| 146 |
+
results_html += """<p style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
| 147 |
+
No results for language: <b>{}</b><hr></p>""".format(
|
| 148 |
+
lang
|
| 149 |
+
)
|
| 150 |
continue
|
| 151 |
results_for_lang_html = ""
|
| 152 |
for result in results_for_lang:
|
| 153 |
+
result_html = format_result(
|
| 154 |
result, highlight_terms, exact_search, datasets_filter
|
| 155 |
)
|
| 156 |
+
if result_html != "":
|
| 157 |
+
filtered_num_results += 1
|
| 158 |
+
results_for_lang_html += result_html
|
| 159 |
if language == "all" and not exact_search:
|
| 160 |
results_for_lang_html = f"""
|
| 161 |
<details>
|
|
|
|
| 166 |
</details>"""
|
| 167 |
results_html += results_for_lang_html
|
| 168 |
|
| 169 |
+
if num_results is not None:
|
| 170 |
+
header_html += """<p style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
| 171 |
+
Total number of matches: <b>{}</b><hr></p><br>""".format(
|
| 172 |
+
filtered_num_results
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
return header_html + results_html
|
| 176 |
|
| 177 |
|
|
|
|
| 228 |
return None
|
| 229 |
|
| 230 |
|
| 231 |
+
def request_payload(query, language, exact_search, num_results=10):
|
|
|
|
|
|
|
| 232 |
post_data = {"query": query, "k": num_results}
|
| 233 |
if language != "detect_language":
|
| 234 |
post_data["lang"] = language
|