brian-yu-nexusflow commited on
Commit
ca9dc96
Β·
1 Parent(s): c885ea9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -258,6 +258,7 @@ class RavenDemo(gr.Blocks):
258
  lines=20,
259
  )
260
 
 
261
  user_input.submit(
262
  fn=self.on_submit,
263
  inputs=[user_input],
@@ -270,9 +271,14 @@ class RavenDemo(gr.Blocks):
270
  gmaps_html,
271
  steps_accordion,
272
  *steps,
 
273
  ],
274
  concurrency_limit=20, # not a hyperparameter
275
  api_name=False,
 
 
 
 
276
  )
277
 
278
  for i, button in enumerate(examples):
@@ -300,10 +306,12 @@ class RavenDemo(gr.Blocks):
300
  gmaps_html,
301
  steps_accordion,
302
  *steps,
 
303
  )
304
 
305
  def on_error():
306
  initial_return[0] = gr.Textbox(interactive=True, autofocus=False)
 
307
  return initial_return
308
 
309
  user_input = gr.Textbox(interactive=False)
@@ -314,6 +322,7 @@ class RavenDemo(gr.Blocks):
314
  gmaps_html = ""
315
  steps_accordion = gr.Accordion(open=True)
316
  steps = [gr.Textbox(value="", visible=False) for _ in range(self.max_num_steps)]
 
317
  initial_return = list(get_returns())
318
  yield initial_return
319
 
@@ -340,12 +349,10 @@ class RavenDemo(gr.Blocks):
340
  f_r_call = format_str(r_c.strip(), mode=Mode())
341
  except:
342
  yield on_error()
343
- gr.Warning(ERROR_MESSAGE)
344
  return
345
 
346
  if not self.whitelist_function_names(f_r_call):
347
  yield on_error()
348
- gr.Warning(ERROR_MESSAGE)
349
  return
350
 
351
  f_r_calls.append(f_r_call)
@@ -443,6 +450,10 @@ class RavenDemo(gr.Blocks):
443
  user_input = gr.Textbox(interactive=True, autofocus=False)
444
  yield get_returns()
445
 
 
 
 
 
446
  def whitelist_function_names(self, function_call_str: str) -> bool:
447
  """
448
  Defensive function name whitelisting inspired by @evan-nexusflow
 
258
  lines=20,
259
  )
260
 
261
+ has_error = gr.State(False)
262
  user_input.submit(
263
  fn=self.on_submit,
264
  inputs=[user_input],
 
271
  gmaps_html,
272
  steps_accordion,
273
  *steps,
274
+ has_error,
275
  ],
276
  concurrency_limit=20, # not a hyperparameter
277
  api_name=False,
278
+ ).then(
279
+ self.check_for_error,
280
+ inputs=has_error,
281
+ outputs=[],
282
  )
283
 
284
  for i, button in enumerate(examples):
 
306
  gmaps_html,
307
  steps_accordion,
308
  *steps,
309
+ has_error,
310
  )
311
 
312
  def on_error():
313
  initial_return[0] = gr.Textbox(interactive=True, autofocus=False)
314
+ initial_return[-1] = True
315
  return initial_return
316
 
317
  user_input = gr.Textbox(interactive=False)
 
322
  gmaps_html = ""
323
  steps_accordion = gr.Accordion(open=True)
324
  steps = [gr.Textbox(value="", visible=False) for _ in range(self.max_num_steps)]
325
+ has_error = False
326
  initial_return = list(get_returns())
327
  yield initial_return
328
 
 
349
  f_r_call = format_str(r_c.strip(), mode=Mode())
350
  except:
351
  yield on_error()
 
352
  return
353
 
354
  if not self.whitelist_function_names(f_r_call):
355
  yield on_error()
 
356
  return
357
 
358
  f_r_calls.append(f_r_call)
 
450
  user_input = gr.Textbox(interactive=True, autofocus=False)
451
  yield get_returns()
452
 
453
+ def check_for_error(self, has_error: bool) -> None:
454
+ if has_error:
455
+ raise gr.Error(ERROR_MESSAGE)
456
+
457
  def whitelist_function_names(self, function_call_str: str) -> bool:
458
  """
459
  Defensive function name whitelisting inspired by @evan-nexusflow