File size: 2,280 Bytes
23fab59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from qanom.qanom_end_to_end_pipeline import QANomEndToEndPipeline


models = ["kleinay/qanom-seq2seq-model-baseline", 
          "kleinay/qanom-seq2seq-model-joint"]
pipelines = {model: QANomEndToEndPipeline(model) for model in models}


description = f"""This is a demo of the full QANom Pipeline - identifying deverbal nominalizations and parsing them with question-answer driven semantic role labeling (QASRL) """ 
title="QANom End-to-End Pipeline Demo"
examples = [[models[0], "The doctor was interested in Luke 's treatment .", 0.75],
            [models[1], "The Veterinary student was interested in Luke 's treatment of sea animals .", 0.75],
            [models[1], "Some reviewers agreed that the criticism raised by the AC is mostly justified .", 0.75]]

input_sent_box_label = "Insert sentence here, or select from the examples below"
links = """<p style='text-align: center'>
<a href='https://www.qasrl.org' target='_blank'>QASRL Website</a>  |  <a href='https://huggingface.co/kleinay/qanom-seq2seq-model-baseline' target='_blank'>Model Repo at Huggingface Hub</a>
</p>"""


def call(model_name, sentence, detection_threshold):

    pipeline = pipelines[model_name]
    pipe_out_pred_infos = pipeline([sentence], detection_threshold=detection_threshold)[0]
    def pretty_pred_output(pred_info) -> str:
        return "\n".join([f"{qa['question']} --- {';'.join(qa['answers'])}"
                          for qa in pred_info['QAs']])
    pretty_output = "\n".join(pretty_pred_output(pred_info) for pred_info in pipe_out_pred_infos)
    return pretty_output, pipe_out_pred_infos

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.Slider(minimum=0., maximum=1., step=0.01, default=0.5, label="Nominalization Detection Threshold")], 
                     outputs=[gr.outputs.Textbox(label="Model Output"), gr.outputs.JSON(label="Model Output - JSON")],
                     title=title,
                     description=description,
                     article=links,
                     examples=examples)
iface.launch()