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 = """

QASRL Website | Model Repo at Huggingface Hub

""" 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()