kleinay's picture
Multiple models
6c9521b
raw history blame
No virus
2.38 kB
import gradio as gr
from qasrl_model_pipeline import QASRL_Pipeline
models = ["kleinay/qanom-seq2seq-model-baseline",
"kleinay/qanom-seq2seq-model-joint"]
pipelines = {model: QASRL_Pipeline(model) for model in models}
description = f"""This is a demo of our QASRL\QANom models, which fine-tuned Seq2Seq pretrained models on the QASRL\QANom task."""
title="QANom Parser Demo"
examples = [["The doctor was interested in Luke 's <predicate> treatment .", True, "treat"],
["The Veterinary student was interested in Luke 's <predicate> treatment of sea animals .", True, "treat"]]
input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<predicate>' before it."
links = """<p style='text-align: center'>
<a href='https://www.qasrl.org' target='_blank'>QASRL Website</a> |
<a href='https://huggingface.co/spaces/kleinay/qanom-seq2seq-demo' target='_blank'>Model Repo at Huggingface Hub</a> |
</p>"""
def call(model_name, sentence, is_nominal, verb_form):
predicate_marker="<predicate>"
if predicate_marker not in sentence:
print("You must highlight one word of the sentence as a '<predicate>'.")
return
if not verb_form:
if is_nominal:
raise ValueError("You should provide the verbal form of the nominalization")
toks = sentence.split(" ")
pred_idx = toks.index(predicate_marker)
predicate = toks(pred_idx+1)
verb_form=predicate
pipeline = pipelines[model_name]
return pipeline(sentence,
predicate_marker=predicate_marker,
predicate_type="nominal" if is_nominal else "verbal",
verb_form=verb_form)
iface = gr.Interface(fn=call,
inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
gr.inputs.Textbox(label="verbal form of nominalization", default='')],
outputs=gr.outputs.JSON(label="Model Output - QASRL"),
title=title,
description=description,
article=links,
examples=examples )