youplala commited on
Commit
2ebf080
·
1 Parent(s): 9a89817

Add alert message when error

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -224,7 +224,7 @@ socials = dmc.Affix(
224
  dmc.ActionIcon(
225
  html.A(
226
  DashIconify(icon="mdi:github", width=25),
227
- href="https://github.com/youplala/chartgpt",
228
  style={"color": "black"},
229
  ),
230
  ),
@@ -284,6 +284,14 @@ page = [
284
  [
285
  socials,
286
  header,
 
 
 
 
 
 
 
 
287
  body,
288
  ]
289
  ),
@@ -450,6 +458,8 @@ def update_stepper_buttons(current, api_key, data):
450
  @app.callback(
451
  Output("input-text-retry", "value"),
452
  Output("output-card", "children"),
 
 
453
  Input("stepper-next", "n_clicks"),
454
  State("stepper", "active"),
455
  State("input-api-key", "value"),
@@ -460,9 +470,15 @@ def update_stepper_buttons(current, api_key, data):
460
  )
461
  def update_graph(n_clicks, active, api_key, df, prompt, prompt_retry):
462
  if n_clicks is not None and active == 2:
463
- return prompt, predict(api_key, df, prompt)
 
 
 
464
  elif n_clicks is not None and active == 3:
465
- return prompt_retry, predict(api_key, df, prompt_retry)
 
 
 
466
  return no_update
467
 
468
 
@@ -475,4 +491,4 @@ def predict(api_key, df, prompt):
475
 
476
 
477
  if __name__ == "__main__":
478
- app.run_server(debug=True)
 
224
  dmc.ActionIcon(
225
  html.A(
226
  DashIconify(icon="mdi:github", width=25),
227
+ href="https://github.com/chatgpt/chart",
228
  style={"color": "black"},
229
  ),
230
  ),
 
284
  [
285
  socials,
286
  header,
287
+ dmc.Alert(
288
+ "",
289
+ title="Error",
290
+ id="alert-error",
291
+ color="red",
292
+ withCloseButton=True,
293
+ hide=True
294
+ ),
295
  body,
296
  ]
297
  ),
 
458
  @app.callback(
459
  Output("input-text-retry", "value"),
460
  Output("output-card", "children"),
461
+ Output("alert-error", "hide"),
462
+ Output("alert-error", "children"),
463
  Input("stepper-next", "n_clicks"),
464
  State("stepper", "active"),
465
  State("input-api-key", "value"),
 
470
  )
471
  def update_graph(n_clicks, active, api_key, df, prompt, prompt_retry):
472
  if n_clicks is not None and active == 2:
473
+ try:
474
+ return prompt, predict(api_key, df, prompt), True, ""
475
+ except Exception as e:
476
+ return no_update, no_update, False, str(e)
477
  elif n_clicks is not None and active == 3:
478
+ try:
479
+ return prompt_retry, predict(api_key, df, prompt_retry), True, ""
480
+ except Exception as e:
481
+ return no_update, no_update, False, str(e)
482
  return no_update
483
 
484
 
 
491
 
492
 
493
  if __name__ == "__main__":
494
+ app.run_server()