Spaces:
Paused
Paused
formatting
Browse files
app.py
CHANGED
@@ -112,24 +112,34 @@ def format_result(result, highlight_terms, exact_search, datasets_filter=None):
|
|
112 |
tokens_html = " ".join(tokens_html)
|
113 |
tokens_html = process_pii(tokens_html)
|
114 |
|
115 |
-
|
116 |
-
"""
|
117 |
-
<
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
)
|
120 |
if url is not None
|
121 |
else ""
|
122 |
)
|
123 |
docid_html = get_docid_html(docid)
|
124 |
language = "FIXME"
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
)
|
|
|
133 |
|
134 |
|
135 |
def format_result_page(
|
@@ -139,20 +149,21 @@ def format_result_page(
|
|
139 |
filtered_num_results = 0
|
140 |
header_html = ""
|
141 |
|
142 |
-
# FIX lang detection by normalizing format on the backend
|
143 |
if language == "detect_language" and not exact_search:
|
144 |
-
header_html += """<
|
145 |
-
Detected language: <b>
|
|
|
|
|
146 |
|
147 |
results_html = ""
|
148 |
for lang, results_for_lang in results.items():
|
149 |
if len(results_for_lang) == 0:
|
150 |
if exact_search:
|
151 |
-
results_html += """<
|
152 |
-
No results found
|
153 |
else:
|
154 |
-
results_html += """<
|
155 |
-
No results for language: <b>{}</b
|
156 |
lang
|
157 |
)
|
158 |
continue
|
@@ -168,15 +179,15 @@ def format_result_page(
|
|
168 |
results_for_lang_html = f"""
|
169 |
<details>
|
170 |
<summary style='font-family: Arial; color:MediumAquaMarine; text-align: left; line-height: 3em'>
|
171 |
-
Results for language: <b>{lang}</b
|
172 |
</summary>
|
173 |
{results_for_lang_html}
|
174 |
</details>"""
|
175 |
results_html += results_for_lang_html
|
176 |
|
177 |
if num_results is not None:
|
178 |
-
header_html += """<
|
179 |
-
Total number of matches: <b>{}</b
|
180 |
filtered_num_results
|
181 |
)
|
182 |
|
@@ -194,12 +205,9 @@ def extract_results_from_payload(query, language, payload, exact_search):
|
|
194 |
if exact_search:
|
195 |
highlight_terms = query
|
196 |
num_results = payload["num_results"]
|
197 |
-
results = {
|
198 |
else:
|
199 |
highlight_terms = payload["highlight_terms"]
|
200 |
-
# unify format - might be best fixed on server side
|
201 |
-
if language != "all":
|
202 |
-
results = {language: results}
|
203 |
|
204 |
for lang, results_for_lang in results.items():
|
205 |
processed_results[lang] = list()
|
|
|
112 |
tokens_html = " ".join(tokens_html)
|
113 |
tokens_html = process_pii(tokens_html)
|
114 |
|
115 |
+
url_html = (
|
116 |
+
"""
|
117 |
+
<span style='font-size:12px; font-family: Arial; color:Silver; text-align: left;'>
|
118 |
+
<a style='text-decoration:none; color:Silver;'
|
119 |
+
onmouseover="style='text-decoration:underline; color:Silver;'"
|
120 |
+
onmouseout="style='text-decoration:none; color:Silver;'"
|
121 |
+
href='{url}'
|
122 |
+
target="_blank">
|
123 |
+
{url}
|
124 |
+
</a>
|
125 |
+
</span><br>
|
126 |
+
""".format(
|
127 |
+
url=url
|
128 |
)
|
129 |
if url is not None
|
130 |
else ""
|
131 |
)
|
132 |
docid_html = get_docid_html(docid)
|
133 |
language = "FIXME"
|
134 |
+
result_html = """{}
|
135 |
+
<span style='font-size:14px; font-family: Arial; color:#7978FF; text-align: left;'>Document ID: {}</span><br>
|
136 |
+
<!-- <span style='font-size:12px; font-family: Arial; color:MediumAquaMarine'>Language: {}</span><br> -->
|
137 |
+
<span style='font-family: Arial;'>{}</span><br>
|
138 |
+
<br>
|
139 |
+
""".format(
|
140 |
+
url_html, docid_html, language, tokens_html
|
141 |
)
|
142 |
+
return "<p>" + result_html + "</p>"
|
143 |
|
144 |
|
145 |
def format_result_page(
|
|
|
149 |
filtered_num_results = 0
|
150 |
header_html = ""
|
151 |
|
|
|
152 |
if language == "detect_language" and not exact_search:
|
153 |
+
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
154 |
+
Detected language: <b style='color:MediumAquaMarine'>{}</b></div>""".format(
|
155 |
+
list(results.keys())[0]
|
156 |
+
)
|
157 |
|
158 |
results_html = ""
|
159 |
for lang, results_for_lang in results.items():
|
160 |
if len(results_for_lang) == 0:
|
161 |
if exact_search:
|
162 |
+
results_html += """<div style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
163 |
+
No results found.</div>"""
|
164 |
else:
|
165 |
+
results_html += """<div style='font-family: Arial; color:Silver; text-align: left; line-height: 3em'>
|
166 |
+
No results for language: <b>{}</b></div>""".format(
|
167 |
lang
|
168 |
)
|
169 |
continue
|
|
|
179 |
results_for_lang_html = f"""
|
180 |
<details>
|
181 |
<summary style='font-family: Arial; color:MediumAquaMarine; text-align: left; line-height: 3em'>
|
182 |
+
Results for language: <b>{lang}</b>
|
183 |
</summary>
|
184 |
{results_for_lang_html}
|
185 |
</details>"""
|
186 |
results_html += results_for_lang_html
|
187 |
|
188 |
if num_results is not None:
|
189 |
+
header_html += """<div style='font-family: Arial; color:MediumAquaMarine; text-align: center; line-height: 3em'>
|
190 |
+
Total number of matches: <b style='color:MediumAquaMarine'>{}</b></div>""".format(
|
191 |
filtered_num_results
|
192 |
)
|
193 |
|
|
|
205 |
if exact_search:
|
206 |
highlight_terms = query
|
207 |
num_results = payload["num_results"]
|
208 |
+
results = {"dummy": results}
|
209 |
else:
|
210 |
highlight_terms = payload["highlight_terms"]
|
|
|
|
|
|
|
211 |
|
212 |
for lang, results_for_lang in results.items():
|
213 |
processed_results[lang] = list()
|