Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
7073b95
1
Parent(s):
cb8e8be
Update app.py
Browse files
app.py
CHANGED
@@ -230,8 +230,30 @@ def classify_tokens(text):
|
|
230 |
|
231 |
# Return both: HTML and table
|
232 |
styled_html = f"<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
|
233 |
-
return styled_html, table
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
|
237 |
iface = gr.Interface(
|
@@ -239,11 +261,27 @@ iface = gr.Interface(
|
|
239 |
inputs=gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
|
240 |
outputs=[
|
241 |
gr.HTML(label="SNACS Tagged Sentence"),
|
242 |
-
gr.
|
243 |
],
|
244 |
title="SNACS Classification",
|
245 |
description="SNACS Classification. Now Multilingual! See the <a href='https://arxiv.org/abs/1704.02134'>SNACS guidelines</a> for details.",
|
246 |
theme="default"
|
247 |
)
|
248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
iface.launch()
|
|
|
230 |
|
231 |
# Return both: HTML and table
|
232 |
styled_html = f"<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
|
|
|
233 |
|
234 |
+
# Generate a colored HTML table
|
235 |
+
table_html = "<table style='border-collapse: collapse; font-family: sans-serif;'>"
|
236 |
+
table_html += "<tr><th style='border: 1px solid #ccc; padding: 6px;'>Token</th>"
|
237 |
+
table_html += "<th style='border: 1px solid #ccc; padding: 6px;'>SNACS Label</th>"
|
238 |
+
table_html += "<th style='border: 1px solid #ccc; padding: 6px;'>Confidence</th></tr>"
|
239 |
+
|
240 |
+
for entity in sorted_results:
|
241 |
+
token = html.escape(entity["word"])
|
242 |
+
label = entity["entity_group"]
|
243 |
+
score = f"{entity['score']:.2f}"
|
244 |
+
color = color_dict.get(label, "#D3D3D3")
|
245 |
+
|
246 |
+
table_html += "<tr>"
|
247 |
+
table_html += f"<td style='border: 1px solid #ccc; padding: 6px;'>{token}</td>"
|
248 |
+
table_html += (
|
249 |
+
f"<td style='border: 1px solid #ccc; padding: 6px; background-color: {color};'>{label}</td>"
|
250 |
+
)
|
251 |
+
table_html += f"<td style='border: 1px solid #ccc; padding: 6px;'>{score}</td>"
|
252 |
+
table_html += "</tr>"
|
253 |
+
|
254 |
+
table_html += "</table>"
|
255 |
+
|
256 |
+
return styled_html, table_html
|
257 |
|
258 |
|
259 |
iface = gr.Interface(
|
|
|
261 |
inputs=gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
|
262 |
outputs=[
|
263 |
gr.HTML(label="SNACS Tagged Sentence"),
|
264 |
+
gr.HTML(label="SNACS Table with Colored Labels")
|
265 |
],
|
266 |
title="SNACS Classification",
|
267 |
description="SNACS Classification. Now Multilingual! See the <a href='https://arxiv.org/abs/1704.02134'>SNACS guidelines</a> for details.",
|
268 |
theme="default"
|
269 |
)
|
270 |
|
271 |
+
|
272 |
+
|
273 |
+
|
274 |
+
|
275 |
+
# iface = gr.Interface(
|
276 |
+
# fn=classify_tokens,
|
277 |
+
# inputs=gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
|
278 |
+
# outputs=[
|
279 |
+
# gr.HTML(label="SNACS Tagged Sentence"),
|
280 |
+
# gr.Dataframe(headers=["Token", "SNACS Label", "Confidence"], label="SNACS Table")
|
281 |
+
# ],
|
282 |
+
# title="SNACS Classification",
|
283 |
+
# description="SNACS Classification. Now Multilingual! See the <a href='https://arxiv.org/abs/1704.02134'>SNACS guidelines</a> for details.",
|
284 |
+
# theme="default"
|
285 |
+
# )
|
286 |
+
|
287 |
iface.launch()
|