Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,9 +80,9 @@ def generate_pastel_colors(n):
|
|
80 |
return []
|
81 |
|
82 |
# To generate colors, we use the HSL colorspace (see http://en.wikipedia.org/wiki/HSL_color_space)
|
83 |
-
start_hue = 0.
|
84 |
saturation = 1.0
|
85 |
-
lightness = 0.
|
86 |
# We take points around the chromatic circle (hue):
|
87 |
# (Note: we generate n+1 colors, then drop the last one ([:-1]) because
|
88 |
# it equals the first one (hue 0 = hue 1))
|
@@ -122,12 +122,13 @@ def set_sidebar(css):
|
|
122 |
|
123 |
|
124 |
def get_el_annotations(response):
|
|
|
125 |
# swap labels key with ents
|
126 |
ents = [
|
127 |
{
|
128 |
"start": l.start,
|
129 |
"end": l.end,
|
130 |
-
"label":
|
131 |
}
|
132 |
for l in response.labels
|
133 |
]
|
@@ -217,33 +218,14 @@ def run_client():
|
|
217 |
# else:
|
218 |
# response = response.json()
|
219 |
|
220 |
-
# Entity Linking
|
221 |
-
# with stylable_container(
|
222 |
-
# key="container_with_border",
|
223 |
-
# css_styles="""
|
224 |
-
# {
|
225 |
-
# border: 1px solid rgba(49, 51, 63, 0.2);
|
226 |
-
# border-radius: 0.5rem;
|
227 |
-
# padding: 0.5rem;
|
228 |
-
# padding-bottom: 2rem;
|
229 |
-
# }
|
230 |
-
# """,
|
231 |
-
# ):
|
232 |
# st.markdown("##")
|
233 |
dict_of_ents, options = get_el_annotations(response=response)
|
234 |
display = displacy.render(
|
235 |
dict_of_ents, manual=True, style="ent", options=options
|
236 |
)
|
237 |
-
display = display.replace("\n", " ")
|
238 |
with st.container():
|
239 |
st.write(display, unsafe_allow_html=True)
|
240 |
|
241 |
-
# st.markdown("####")
|
242 |
-
# st.markdown("#### Relation Extraction")
|
243 |
-
|
244 |
-
# with st.container():
|
245 |
-
# st.write("Coming :)", unsafe_allow_html=True)
|
246 |
-
|
247 |
else:
|
248 |
st.error("Please enter some text.")
|
249 |
|
|
|
80 |
return []
|
81 |
|
82 |
# To generate colors, we use the HSL colorspace (see http://en.wikipedia.org/wiki/HSL_color_space)
|
83 |
+
start_hue = 0.0 # 0=red 1/3=0.333=green 2/3=0.666=blue
|
84 |
saturation = 1.0
|
85 |
+
lightness = 0.9
|
86 |
# We take points around the chromatic circle (hue):
|
87 |
# (Note: we generate n+1 colors, then drop the last one ([:-1]) because
|
88 |
# it equals the first one (hue 0 = hue 1))
|
|
|
122 |
|
123 |
|
124 |
def get_el_annotations(response):
|
125 |
+
el_link_wrapper = "<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css'><a href='https://en.wikipedia.org/wiki/{}' style='color: #414141'><i class='fa-brands fa-wikipedia-w fa-xs'></i> <span style='font-size: 1.0em; font-family: monospace'> {}</span></a>"
|
126 |
# swap labels key with ents
|
127 |
ents = [
|
128 |
{
|
129 |
"start": l.start,
|
130 |
"end": l.end,
|
131 |
+
"label": el_link_wrapper.format(l.label.replace(" ", "_"), l.label),
|
132 |
}
|
133 |
for l in response.labels
|
134 |
]
|
|
|
218 |
# else:
|
219 |
# response = response.json()
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
# st.markdown("##")
|
222 |
dict_of_ents, options = get_el_annotations(response=response)
|
223 |
display = displacy.render(
|
224 |
dict_of_ents, manual=True, style="ent", options=options
|
225 |
)
|
|
|
226 |
with st.container():
|
227 |
st.write(display, unsafe_allow_html=True)
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
else:
|
230 |
st.error("Please enter some text.")
|
231 |
|