kleinay commited on
Commit
b1f0d38
1 Parent(s): 020110f

Restore older modifications

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