Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,13 @@ import gradio as gr
|
|
9 |
import requests
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def process_results(results, highlight_terms):
|
13 |
if len(results) == 0:
|
14 |
return """<br><p style='font-family: Arial; color:Silver; text-align: center;'>
|
@@ -16,14 +23,8 @@ def process_results(results, highlight_terms):
|
|
16 |
|
17 |
results_html = ""
|
18 |
for result in results:
|
19 |
-
|
20 |
-
|
21 |
-
for token in tokens:
|
22 |
-
if token in highlight_terms:
|
23 |
-
tokens_html.append("<b>{}</b>".format(token))
|
24 |
-
else:
|
25 |
-
tokens_html.append(token)
|
26 |
-
tokens_html = " ".join(tokens_html)
|
27 |
meta_html = (
|
28 |
"""
|
29 |
<p class='underline-on-hover' style='font-size:12px; font-family: Arial; color:#585858; text-align: left;'>
|
|
|
9 |
import requests
|
10 |
|
11 |
|
12 |
+
def mark_tokens_bold(string, tokens):
|
13 |
+
for token in tokens:
|
14 |
+
pattern = r"\b" + re.escape(token) + r"\b"
|
15 |
+
string = re.sub(pattern, "<b>" + token + "</b>", string)
|
16 |
+
return string
|
17 |
+
|
18 |
+
|
19 |
def process_results(results, highlight_terms):
|
20 |
if len(results) == 0:
|
21 |
return """<br><p style='font-family: Arial; color:Silver; text-align: center;'>
|
|
|
23 |
|
24 |
results_html = ""
|
25 |
for result in results:
|
26 |
+
text_html = result["text"]
|
27 |
+
text_html = mark_tokens_bold(text_html, highlight_terms)
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
meta_html = (
|
29 |
"""
|
30 |
<p class='underline-on-hover' style='font-size:12px; font-family: Arial; color:#585858; text-align: left;'>
|