Spaces:
Runtime error
Runtime error
Multiple models
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from qasrl_model_pipeline import QASRL_Pipeline
|
| 3 |
-
model = "kleinay/qanom-seq2seq-model-baseline"
|
| 4 |
-
pipeline = QASRL_Pipeline(model)
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
title="QANom Parser Demo"
|
| 8 |
-
examples = [["The doctor was interested in Luke 's <
|
| 9 |
-
["The Veterinary student was interested in Luke 's <
|
| 10 |
-
input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<
|
| 11 |
-
verb_form_inp_placeholder = "e.g. 'decide' for the nominalization 'decision', 'teach' for 'teacher', etc."
|
| 12 |
links = """<p style='text-align: center'>
|
| 13 |
-
<a href='https://www.qasrl.org' target='_blank'>QASRL Website</a>
|
|
|
|
| 14 |
</p>"""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
predicate_marker="<p>"
|
| 18 |
if predicate_marker not in sentence:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
if not verb_form:
|
| 22 |
if is_nominal:
|
| 23 |
raise ValueError("You should provide the verbal form of the nominalization")
|
|
@@ -26,18 +28,18 @@ def call(sentence, is_nominal, verb_form):
|
|
| 26 |
pred_idx = toks.index(predicate_marker)
|
| 27 |
predicate = toks(pred_idx+1)
|
| 28 |
verb_form=predicate
|
| 29 |
-
|
|
|
|
| 30 |
predicate_marker=predicate_marker,
|
| 31 |
predicate_type="nominal" if is_nominal else "verbal",
|
| 32 |
verb_form=verb_form)
|
| 33 |
-
return pipe_out[0]["QAs"], pipe_out[0]["generated_text"]
|
| 34 |
iface = gr.Interface(fn=call,
|
| 35 |
-
inputs=[gr.inputs.
|
|
|
|
| 36 |
gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
|
| 37 |
-
gr.inputs.Textbox(
|
| 38 |
-
outputs=
|
| 39 |
title=title,
|
| 40 |
description=description,
|
| 41 |
article=links,
|
| 42 |
-
examples=examples )
|
| 43 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from qasrl_model_pipeline import QASRL_Pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
models = ["kleinay/qanom-seq2seq-model-baseline",
|
| 5 |
+
"kleinay/qanom-seq2seq-model-joint"]
|
| 6 |
+
pipelines = {model: QASRL_Pipeline(model) for model in models}
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
description = f"""This is a demo of our QASRL\QANom models, which fine-tuned Seq2Seq pretrained models on the QASRL\QANom task."""
|
| 10 |
title="QANom Parser Demo"
|
| 11 |
+
examples = [["The doctor was interested in Luke 's <predicate> treatment .", True, "treat"],
|
| 12 |
+
["The Veterinary student was interested in Luke 's <predicate> treatment of sea animals .", True, "treat"]]
|
| 13 |
+
input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<predicate>' before it."
|
|
|
|
| 14 |
links = """<p style='text-align: center'>
|
| 15 |
+
<a href='https://www.qasrl.org' target='_blank'>QASRL Website</a> |
|
| 16 |
+
<a href='https://huggingface.co/spaces/kleinay/qanom-seq2seq-demo' target='_blank'>Model Repo at Huggingface Hub</a> |
|
| 17 |
</p>"""
|
| 18 |
+
def call(model_name, sentence, is_nominal, verb_form):
|
| 19 |
+
predicate_marker="<predicate>"
|
|
|
|
| 20 |
if predicate_marker not in sentence:
|
| 21 |
+
print("You must highlight one word of the sentence as a '<predicate>'.")
|
| 22 |
+
return
|
| 23 |
if not verb_form:
|
| 24 |
if is_nominal:
|
| 25 |
raise ValueError("You should provide the verbal form of the nominalization")
|
|
|
|
| 28 |
pred_idx = toks.index(predicate_marker)
|
| 29 |
predicate = toks(pred_idx+1)
|
| 30 |
verb_form=predicate
|
| 31 |
+
pipeline = pipelines[model_name]
|
| 32 |
+
return pipeline(sentence,
|
| 33 |
predicate_marker=predicate_marker,
|
| 34 |
predicate_type="nominal" if is_nominal else "verbal",
|
| 35 |
verb_form=verb_form)
|
|
|
|
| 36 |
iface = gr.Interface(fn=call,
|
| 37 |
+
inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
|
| 38 |
+
gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
|
| 39 |
gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
|
| 40 |
+
gr.inputs.Textbox(label="verbal form of nominalization", default='')],
|
| 41 |
+
outputs=gr.outputs.JSON(label="Model Output - QASRL"),
|
| 42 |
title=title,
|
| 43 |
description=description,
|
| 44 |
article=links,
|
| 45 |
+
examples=examples )
|
|
|