kleinay's picture
prettier output
5c968f6
raw
history blame
2.41 kB
import gradio as gr
from qasrl_model_pipeline import QASRL_Pipeline
model = "kleinay/qanom-seq2seq-model-baseline"
pipeline = QASRL_Pipeline(model)
description = f"""This is a demo of the '{model}' model, which fine-tuned a Seq2Seq pretrained model on the QANom task."""
title="QANom Parser Demo"
examples = [["The doctor was interested in Luke 's <p> treatment .", True, "treat"],
["The Veterinary student was interested in Luke 's <p> treatment of sea animals .", True, "treat"]]
input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<p>' before it."
verb_form_inp_placeholder = "e.g. 'decide' for the nominalization 'decision', 'teach' for 'teacher', etc."
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(sentence, is_nominal, verb_form):
predicate_marker="<p>"
if predicate_marker not in sentence:
raise ValueError("You must highlight one word of the sentence as a predicate using preceding '<p>'.")
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
pipe_out = pipeline(sentence,
predicate_marker=predicate_marker,
predicate_type="nominal" if is_nominal else "verbal",
verb_form=verb_form)
return pipe_out[0]["QAs"], pipe_out[0]["generated_text"]
iface = gr.Interface(fn=call,
inputs=[gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
gr.inputs.Textbox(placeholder=verb_form_inp_placeholder, label="Verbal form (for nominalizations)", default='')],
outputs=[gr.outputs.JSON(label="Model Output - QASRL"), gr.outputs.Textbox(label="Raw output sequence")],
title=title,
description=description,
article=links,
examples=examples )
iface.launch()