kleinay commited on
Commit
506a464
1 Parent(s): 676266b

Updating app to work

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -5,5 +5,39 @@ 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
- iface = gr.Interface(fn=pipeline, inputs=["text"], outputs=["text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  iface.launch()
 
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 <predicate> treatment .", True, "treat"],
9
+ ["The Veterinary student was interested in Luke 's <predicate> 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
+
12
+ links = """<p style='text-align: center'>
13
+ <a href='https://www.qasrl.org' target='_blank'>QASRL Website</a>
14
+ <a href='https://huggingface.co/spaces/kleinay/qanom-seq2seq-demo' target='_blank'>Model Repo at Huggingface Hub</a> |
15
+ </p>"""
16
+
17
+ def call(sentence, is_nominal, verb_form):
18
+ predicate_marker="<p>"
19
+ if predicate_marker not in sentence:
20
+ raise ValueError("You must highlight one word of the sentence as a predicate using preceeding '<p>'.")
21
+
22
+ if not verb_form:
23
+ if is_nominal:
24
+ raise ValueError("You should provide the verbal form of the nominalization")
25
+
26
+ toks = sentence.split(" ")
27
+ pred_idx = toks.index(predicate_marker)
28
+ predicate = toks(pred_idx+1)
29
+ verb_form=predicate
30
+ return pipeline(sentence,
31
+ predicate_marker=predicate_marker,
32
+ predicate_type="nominal" if is_nominal else "verbal",
33
+ verb_form=verb_form)
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(label="verbal form of nominalization", default='')],
38
+ outputs=gr.outputs.JSON(label="Model Output - QASRL"),
39
+ title=title,
40
+ description=description,
41
+ article=links,
42
+ examples=examples )
43
  iface.launch()