Spaces:
Runtime error
Runtime error
handle no qas or no predicates
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import nltk
|
3 |
from qanom.qanom_end_to_end_pipeline import QANomEndToEndPipeline
|
4 |
-
|
5 |
|
6 |
models = ["kleinay/qanom-seq2seq-model-baseline",
|
7 |
"kleinay/qanom-seq2seq-model-joint"]
|
@@ -26,10 +26,17 @@ def call(model_name, sentence, detection_threshold):
|
|
26 |
|
27 |
pipeline = pipelines[model_name]
|
28 |
pred_infos = pipeline([sentence], detection_threshold=detection_threshold)[0]
|
29 |
-
def
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# also present highlighted predicates
|
34 |
positives = [pred_info['predicate_idx'] for pred_info in pred_infos]
|
35 |
def color(idx):
|
|
|
1 |
import gradio as gr
|
2 |
import nltk
|
3 |
from qanom.qanom_end_to_end_pipeline import QANomEndToEndPipeline
|
4 |
+
from typing import List
|
5 |
|
6 |
models = ["kleinay/qanom-seq2seq-model-baseline",
|
7 |
"kleinay/qanom-seq2seq-model-joint"]
|
|
|
26 |
|
27 |
pipeline = pipelines[model_name]
|
28 |
pred_infos = pipeline([sentence], detection_threshold=detection_threshold)[0]
|
29 |
+
def pretty_qas(pred_info) -> List[str]:
|
30 |
+
if not pred_info or not pred_info['QAs']: return []
|
31 |
+
return [f"{qa['question']} --- {';'.join(qa['answers'])}"
|
32 |
+
for qa in pred_info['QAs']]
|
33 |
+
all_qas = [qa for pred_info in pred_infos for qa in pretty_qas(pred_info)]
|
34 |
+
if not pred_infos:
|
35 |
+
pretty_qa_output = "NO NOMINALIZATION FOUND"
|
36 |
+
elif not all_qas:
|
37 |
+
pretty_qa_output = "NO QA GENERATED"
|
38 |
+
else:
|
39 |
+
pretty_qa_output = "\n".join(all_qas)
|
40 |
# also present highlighted predicates
|
41 |
positives = [pred_info['predicate_idx'] for pred_info in pred_infos]
|
42 |
def color(idx):
|