ChancesYuan commited on
Commit
2db20c0
1 Parent(s): c32018d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -195,7 +195,10 @@ def get_logits_orig_params_dict(inputs, cond_inputs, alter_label, ex_model, lear
195
  return params_dict
196
 
197
  def edit_process(edit_input, alter_label):
198
- _, cond_inputs, edit_inputs, origin_top3 = solve(edit_input, alter_label, edit_task=True)
 
 
 
199
 
200
  ### edit output
201
  fmodel = make_functional(edit_ex_model).eval()
@@ -219,7 +222,10 @@ def edit_process(edit_input, alter_label):
219
  return "\n".join(origin_top3), "\n".join(edit_top3)
220
 
221
  def add_process(edit_input, alter_label):
222
- _, cond_inputs, add_inputs, origin_top3 = solve(edit_input, alter_label, edit_task=False)
 
 
 
223
 
224
  ### add output
225
  fmodel = make_functional(add_ex_model).eval()
@@ -252,7 +258,7 @@ with gr.Blocks() as demo:
252
  with gr.TabItem("E-FB15k237"):
253
  with gr.Row():
254
  with gr.Column():
255
- edit_input = gr.Textbox(label="Input", lines=1, placeholder="Mask triple input")
256
 
257
  alter_label = gr.Textbox(label="Alter Entity", lines=1, placeholder="Entity Name")
258
  edit_button = gr.Button("Edit")
@@ -277,7 +283,7 @@ with gr.Blocks() as demo:
277
  with gr.TabItem("A-FB15k237"):
278
  with gr.Row():
279
  with gr.Column():
280
- add_input = gr.Textbox(label="Input", lines=1, placeholder="New triple input")
281
 
282
  inductive_entity = gr.Textbox(label="Inductive Entity", lines=1, placeholder="Entity Name")
283
  add_button = gr.Button("Add")
 
195
  return params_dict
196
 
197
  def edit_process(edit_input, alter_label):
198
+ try:
199
+ _, cond_inputs, edit_inputs, origin_top3 = solve(edit_input, alter_label, edit_task=True)
200
+ except KeyError:
201
+ return "The entity or relationship you entered is not in the vocabulary. Please check it carefully.", ""
202
 
203
  ### edit output
204
  fmodel = make_functional(edit_ex_model).eval()
 
222
  return "\n".join(origin_top3), "\n".join(edit_top3)
223
 
224
  def add_process(edit_input, alter_label):
225
+ try:
226
+ _, cond_inputs, add_inputs, origin_top3 = solve(edit_input, alter_label, edit_task=False)
227
+ except:
228
+ return "The entity or relationship you entered is not in the vocabulary. Please check it carefully.", ""
229
 
230
  ### add output
231
  fmodel = make_functional(add_ex_model).eval()
 
258
  with gr.TabItem("E-FB15k237"):
259
  with gr.Row():
260
  with gr.Column():
261
+ edit_input = gr.Textbox(label="Input", lines=1, placeholder=" Please enter in the format of: [MASK]|rel|tail or head|rel|[MASK].")
262
 
263
  alter_label = gr.Textbox(label="Alter Entity", lines=1, placeholder="Entity Name")
264
  edit_button = gr.Button("Edit")
 
283
  with gr.TabItem("A-FB15k237"):
284
  with gr.Row():
285
  with gr.Column():
286
+ add_input = gr.Textbox(label="Input", lines=1, placeholder="Brand new triple input")
287
 
288
  inductive_entity = gr.Textbox(label="Inductive Entity", lines=1, placeholder="Entity Name")
289
  add_button = gr.Button("Add")