WesScivetti commited on
Commit
b88120f
·
1 Parent(s): ed221f7

update app

Browse files
Files changed (1) hide show
  1. app.py +17 -38
app.py CHANGED
@@ -257,54 +257,33 @@ def classify_tokens(text):
257
 
258
  color = color_dict.get(label, "#D3D3D3")
259
  tooltip = f"{label} ({score:.2f})"
260
-
261
- style_block = """
262
- <style>
263
- span:hover .tooltip {
264
- visibility: visible;
265
- }
266
- </style>
267
- """
268
-
269
- output += f"""
270
- <span style='position: relative; background-color: {color}; padding: 2px; border-radius: 4px; margin-right: 2px;'>
271
- {word}
272
- <span style='
273
- visibility: hidden;
274
- background-color: black;
275
- color: #fff;
276
- text-align: center;
277
- border-radius: 4px;
278
- padding: 2px 6px;
279
- position: absolute;
280
- z-index: 1;
281
- bottom: 120%;
282
- left: 50%;
283
- transform: translateX(-50%);
284
- white-space: nowrap;
285
- font-size: 0.75rem;
286
- ' class='tooltip'>{label}</span>
287
- </span>
288
- """
289
  last_idx = end
290
 
291
  output += html.escape(text[last_idx:])
292
 
293
- style_block = """
294
- <style>
295
- span:hover .tooltip {
296
- visibility: visible;
297
- }
298
- </style>
299
- """
300
 
301
- return f"{style_block}<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
 
 
 
 
 
 
 
 
302
 
303
 
304
  iface = gr.Interface(
305
  fn=classify_tokens,
306
  inputs=gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
307
- outputs=gr.HTML(label="SNACS Tagged Sentence"),
 
 
 
308
  title="SNACS English Classification",
309
  description="SNACS English Classification. See the <a href='https://arxiv.org/abs/1704.02134'>SNACS guidelines</a> for details.",
310
  theme="default"
 
257
 
258
  color = color_dict.get(label, "#D3D3D3")
259
  tooltip = f"{label} ({score:.2f})"
260
+ output += (
261
+ f"<span style='background-color: {color}; padding: 2px; border-radius: 4px;' "
262
+ f"title='{tooltip}'>{word}</span>"
263
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  last_idx = end
265
 
266
  output += html.escape(text[last_idx:])
267
 
 
 
 
 
 
 
 
268
 
269
+ table = [
270
+ [entity["word"], entity["entity_group"], f"{entity['score']:.2f}"]
271
+ for entity in sorted_results
272
+ ]
273
+
274
+ # Return both: HTML and table
275
+ styled_html = f"<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
276
+ return styled_html, table
277
+
278
 
279
 
280
  iface = gr.Interface(
281
  fn=classify_tokens,
282
  inputs=gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
283
+ outputs=[
284
+ gr.HTML(label="SNACS Tagged Sentence"),
285
+ gr.Dataframe(headers=["Token", "SNACS Label", "Confidence"], label="SNACS Table")
286
+ ],
287
  title="SNACS English Classification",
288
  description="SNACS English Classification. See the <a href='https://arxiv.org/abs/1704.02134'>SNACS guidelines</a> for details.",
289
  theme="default"