Spaces:
Runtime error
Runtime error
fix bug
Browse files
app.py
CHANGED
@@ -23,11 +23,11 @@ links = """<p style='text-align: center'>
|
|
23 |
def call(model_name, sentence, detection_threshold):
|
24 |
|
25 |
pipeline = pipelines[model_name]
|
26 |
-
|
27 |
def pretty_pred_output(pred_info) -> str:
|
28 |
return "\n".join([f"{qa['question']} --- {';'.join(qa['answers'])}"
|
29 |
for qa in pred_info['QAs']])
|
30 |
-
pretty_qa_output = "\n".join(pretty_pred_output(pred_info) for pred_info in
|
31 |
# also present highlighted predicates
|
32 |
positives = [pred_info['predicate_idx'] for pred_info in pred_infos]
|
33 |
def color(idx):
|
@@ -38,7 +38,7 @@ def call(model_name, sentence, detection_threshold):
|
|
38 |
tooltip = f'title=" probability={idx2prob[idx]:.2}
verb={idx2verb[idx]}"' if idx in idx2verb else ''
|
39 |
return f'<span {tooltip} style="background-color: {color(idx)}">{word}</span>'
|
40 |
html = '<span>' + ' '.join(word_span(word, idx) for idx, word in enumerate(sentence.split(" "))) + '</span>'
|
41 |
-
return html, pretty_qa_output ,
|
42 |
|
43 |
iface = gr.Interface(fn=call,
|
44 |
inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
|
|
|
23 |
def call(model_name, sentence, detection_threshold):
|
24 |
|
25 |
pipeline = pipelines[model_name]
|
26 |
+
pred_infos = pipeline([sentence], detection_threshold=detection_threshold)[0]
|
27 |
def pretty_pred_output(pred_info) -> str:
|
28 |
return "\n".join([f"{qa['question']} --- {';'.join(qa['answers'])}"
|
29 |
for qa in pred_info['QAs']])
|
30 |
+
pretty_qa_output = "\n".join(pretty_pred_output(pred_info) for pred_info in pred_infos)
|
31 |
# also present highlighted predicates
|
32 |
positives = [pred_info['predicate_idx'] for pred_info in pred_infos]
|
33 |
def color(idx):
|
|
|
38 |
tooltip = f'title=" probability={idx2prob[idx]:.2}
verb={idx2verb[idx]}"' if idx in idx2verb else ''
|
39 |
return f'<span {tooltip} style="background-color: {color(idx)}">{word}</span>'
|
40 |
html = '<span>' + ' '.join(word_span(word, idx) for idx, word in enumerate(sentence.split(" "))) + '</span>'
|
41 |
+
return html, pretty_qa_output , pred_infos
|
42 |
|
43 |
iface = gr.Interface(fn=call,
|
44 |
inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
|