Spaces:
Runtime error
Runtime error
Works with highlighting using HTML
Browse files
app.py
CHANGED
@@ -18,13 +18,27 @@ examples = [["The doctor was interested in Luke 's treatment .", True, True, 0.6
|
|
18 |
|
19 |
def call(sentence: str, return_all_candidates: bool, threshold: float):
|
20 |
ret = detector([sentence], return_all_candidates, True, threshold)[0]
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
iface = gr.Interface(
|
24 |
inputs=[gr.inputs.Textbox(label="Sentence", lines=3),
|
25 |
gr.inputs.Checkbox(default=True, label="Return all candidates?"),
|
26 |
gr.inputs.Slider(minimum=0., maximum=1., step=0.01, default=0.5, label="Threshold")],
|
27 |
-
outputs=[gr.outputs.
|
|
|
28 |
title=title,
|
29 |
description=description,
|
30 |
article=links,
|
|
|
18 |
|
19 |
def call(sentence: str, return_all_candidates: bool, threshold: float):
|
20 |
ret = detector([sentence], return_all_candidates, True, threshold)[0]
|
21 |
+
if return_all_candidates:
|
22 |
+
positives = [d["predicate_idx"] for d in ret if d['predicate_detector_prediction']]
|
23 |
+
negatives = [d["predicate_idx"] for d in ret if not d['predicate_detector_prediction']]
|
24 |
+
else:
|
25 |
+
positives = [d["predicate_idx"] for d in ret]
|
26 |
+
negatives = []
|
27 |
+
def color(idx):
|
28 |
+
if idx in positives: return "lightgreen"
|
29 |
+
if idx in negatives: return "pink"
|
30 |
+
highlighted = [(word, color(idx)) for idx, word in enumerate(sentence.split(" "))]
|
31 |
+
def word_span(word, idx):
|
32 |
+
return f'<span style="background-color: {color(idx)}">{word}</span>'
|
33 |
+
html = '<span>' + ' '.join(word_span(word, idx) for idx, word in enumerate(sentence.split(" "))) + '</span>'
|
34 |
+
return html, ret
|
35 |
|
36 |
+
iface = gr.Interface(call,
|
37 |
inputs=[gr.inputs.Textbox(label="Sentence", lines=3),
|
38 |
gr.inputs.Checkbox(default=True, label="Return all candidates?"),
|
39 |
gr.inputs.Slider(minimum=0., maximum=1., step=0.01, default=0.5, label="Threshold")],
|
40 |
+
outputs=[gr.outputs.HTML(label="Detected Nominalizations"),
|
41 |
+
gr.outputs.JSON(label="Raw Model Output")],
|
42 |
title=title,
|
43 |
description=description,
|
44 |
article=links,
|