djgoettel commited on
Commit
d8f0ec6
1 Parent(s): 30de317

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"""Using Seq2Seq T5 model which takes a sequence of items and outputs another sequence this model generates Questions and Answers (QA) with focus on Semantic Role Labeling (SRL)"""
10
+ title="Seq2Seq T5 Questions and Answers (QA) with Semantic Role Labeling (SRL)"
11
+ examples = [[models[0], "In March and April the patient <p> had two falls. One was related to asthma, heart palpitations. The second was due to syncope and post covid vaccination dizziness during exercise. The patient is now getting an EKG. Former EKG had shown that there was a bundle branch block. Patient had some uncontrolled immune system reactions like anaphylaxis and shortness of breath.", True, "fall"],
12
+ [models[1], "In March and April the patient had two falls. One was related to asthma, heart palpitations. The second was due to syncope and post covid vaccination dizziness during exercise. The patient is now getting an EKG. Former EKG had shown that there was a bundle branch block. Patient had some uncontrolled immune system reactions <p> like anaphylaxis and shortness of breath.", True, "reactions"],
13
+ [models[0], "In March and April the patient had two falls. One was related <p> to asthma, heart palpitations. The second was due to syncope and post covid vaccination dizziness during exercise. The patient is now getting an EKG. Former EKG had shown that there was a bundle branch block. Patient had some uncontrolled immune system reactions like anaphylaxis and shortness of breath.", True, "relate"],
14
+ [models[1], "In March and April the patient <p> had two falls. One was related to asthma, heart palpitations. The second was due to syncope and post covid vaccination dizziness during exercise. The patient is now getting an EKG. Former EKG had shown that there was a bundle branch block. Patient had some uncontrolled immune system reactions like anaphylaxis and shortness of breath.", False, "fall"]]
15
+
16
+ input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<p>' before it."
17
+ verb_form_inp_placeholder = "e.g. 'decide' for the nominalization 'decision', 'teach' for 'teacher', etc."
18
+ links = """<p style='text-align: center'>
19
+ <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>
20
+ </p>"""
21
+ def call(model_name, sentence, is_nominal, verb_form):
22
+ predicate_marker="<p>"
23
+ if predicate_marker not in sentence:
24
+ raise ValueError("You must highlight one word of the sentence as a predicate using preceding '<p>'.")
25
+
26
+ if not verb_form:
27
+ if is_nominal:
28
+ raise ValueError("You should provide the verbal form of the nominalization")
29
+
30
+ toks = sentence.split(" ")
31
+ pred_idx = toks.index(predicate_marker)
32
+ predicate = toks(pred_idx+1)
33
+ verb_form=predicate
34
+ pipeline = pipelines[model_name]
35
+ pipe_out = pipeline([sentence],
36
+ predicate_marker=predicate_marker,
37
+ predicate_type="nominal" if is_nominal else "verbal",
38
+ verb_form=verb_form)[0]
39
+ return pipe_out["QAs"], pipe_out["generated_text"]
40
+ iface = gr.Interface(fn=call,
41
+ inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
42
+ gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
43
+ gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
44
+ gr.inputs.Textbox(placeholder=verb_form_inp_placeholder, label="Verbal form (for nominalizations)", default='')],
45
+ outputs=[gr.outputs.JSON(label="Model Output - QASRL"), gr.outputs.Textbox(label="Raw output sequence")],
46
+ title=title,
47
+ description=description,
48
+ article=links,
49
+ examples=examples )
50
+
51
+ iface.launch()