kleinay commited on
Commit
6c9521b
1 Parent(s): 42bbdc7

Multiple models

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import gradio as gr
2
  from qasrl_model_pipeline import QASRL_Pipeline
3
- model = "kleinay/qanom-seq2seq-model-baseline"
4
- pipeline = QASRL_Pipeline(model)
5
 
6
- description = f"""This is a demo of the '{model}' model, which fine-tuned a Seq2Seq pretrained model on the QANom task."""
 
 
 
 
 
7
  title="QANom Parser Demo"
8
- examples = [["The doctor was interested in Luke 's <p> treatment .", True, "treat"],
9
- ["The Veterinary student was interested in Luke 's <p> treatment of sea animals .", True, "treat"]]
10
- input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<p>' before it."
11
- verb_form_inp_placeholder = "e.g. 'decide' for the nominalization 'decision', 'teach' for 'teacher', etc."
12
  links = """<p style='text-align: center'>
13
- <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>
 
14
  </p>"""
15
-
16
- def call(sentence, is_nominal, verb_form):
17
- predicate_marker="<p>"
18
  if predicate_marker not in sentence:
19
- raise ValueError("You must highlight one word of the sentence as a predicate using preceding '<p>'.")
20
-
21
  if not verb_form:
22
  if is_nominal:
23
  raise ValueError("You should provide the verbal form of the nominalization")
@@ -26,18 +28,18 @@ def call(sentence, is_nominal, verb_form):
26
  pred_idx = toks.index(predicate_marker)
27
  predicate = toks(pred_idx+1)
28
  verb_form=predicate
29
- pipe_out = pipeline(sentence,
 
30
  predicate_marker=predicate_marker,
31
  predicate_type="nominal" if is_nominal else "verbal",
32
  verb_form=verb_form)
33
- return pipe_out[0]["QAs"], pipe_out[0]["generated_text"]
34
  iface = gr.Interface(fn=call,
35
- inputs=[gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
 
36
  gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
37
- gr.inputs.Textbox(placeholder=verb_form_inp_placeholder, label="Verbal form (for nominalizations)", default='')],
38
- outputs=[gr.outputs.JSON(label="Model Output - QASRL"), gr.outputs.Textbox(label="Raw output sequence")],
39
  title=title,
40
  description=description,
41
  article=links,
42
- examples=examples )
43
- iface.launch()
 
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"""This is a demo of our QASRL\QANom models, which fine-tuned Seq2Seq pretrained models on the QASRL\QANom task."""
10
  title="QANom Parser Demo"
11
+ examples = [["The doctor was interested in Luke 's <predicate> treatment .", True, "treat"],
12
+ ["The Veterinary student was interested in Luke 's <predicate> treatment of sea animals .", True, "treat"]]
13
+ input_sent_box_label = "Insert sentence here. Mark the predicate by adding the token '<predicate>' before it."
 
14
  links = """<p style='text-align: center'>
15
+ <a href='https://www.qasrl.org' target='_blank'>QASRL Website</a> |
16
+ <a href='https://huggingface.co/spaces/kleinay/qanom-seq2seq-demo' target='_blank'>Model Repo at Huggingface Hub</a> |
17
  </p>"""
18
+ def call(model_name, sentence, is_nominal, verb_form):
19
+ predicate_marker="<predicate>"
 
20
  if predicate_marker not in sentence:
21
+ print("You must highlight one word of the sentence as a '<predicate>'.")
22
+ return
23
  if not verb_form:
24
  if is_nominal:
25
  raise ValueError("You should provide the verbal form of the nominalization")
 
28
  pred_idx = toks.index(predicate_marker)
29
  predicate = toks(pred_idx+1)
30
  verb_form=predicate
31
+ pipeline = pipelines[model_name]
32
+ return pipeline(sentence,
33
  predicate_marker=predicate_marker,
34
  predicate_type="nominal" if is_nominal else "verbal",
35
  verb_form=verb_form)
 
36
  iface = gr.Interface(fn=call,
37
+ inputs=[gr.inputs.Radio(choices=models, default=models[0], label="Model"),
38
+ gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
39
  gr.inputs.Checkbox(default=True, label="Is Nominalization?"),
40
+ gr.inputs.Textbox(label="verbal form of nominalization", default='')],
41
+ outputs=gr.outputs.JSON(label="Model Output - QASRL"),
42
  title=title,
43
  description=description,
44
  article=links,
45
+ examples=examples )