Simon Clematide commited on
Commit
b3fd1bf
ยท
1 Parent(s): add3b9b

Activate Step-by-Step Trace tab when clicking Generate Trace

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -274,7 +274,7 @@ def build_visual_grammar_html():
274
  for title, label, description in samples) + '</div>'
275
 
276
 
277
- with gr.Blocks(title="Autodiff Mermaid Visualizer") as demo:
278
  gr.Markdown("# ๐Ÿงฎ Autodiff Mermaid Visualizer")
279
  gr.Markdown("Type any mathematical expression and supply numerical values to visualize the computational graph and derivative calculus.")
280
 
@@ -309,8 +309,8 @@ with gr.Blocks(title="Autodiff Mermaid Visualizer") as demo:
309
  btn_diagram = gr.Button("Generate Diagram", variant="primary")
310
  btn_trace = gr.Button("Generate Trace", variant="primary")
311
 
312
- with gr.Tabs():
313
- with gr.TabItem("๐Ÿ“Š Visual Diagram"):
314
  diagram_output = gr.HTML(label="Diagram")
315
 
316
  with gr.Accordion("๐Ÿ“ฅ Download & Export (On-Demand)", open=True):
@@ -327,12 +327,12 @@ with gr.Blocks(title="Autodiff Mermaid Visualizer") as demo:
327
  with gr.Accordion("๐Ÿ’ก Visual Grammar & Diagram Guide", open=True):
328
  gr.HTML(build_visual_grammar_html())
329
 
330
- with gr.TabItem("๐Ÿ“ Step-by-Step Trace"):
331
- trace_output = gr.HTML(label="Step-by-step trace", head=TRACE_VIEW_SCRIPT)
332
 
333
- with gr.TabItem("๐Ÿ’ป Mermaid Code"):
334
  code_output = gr.Code(label="Mermaid Syntax", language="markdown")
335
- with gr.TabItem("๐Ÿ“– Online Help"):
336
  gr.Markdown(
337
  VISUAL_LANGUAGE + r"""
338
 
@@ -491,18 +491,18 @@ All supplied variables are differentiable real inputs. Thus examples may also sh
491
  )
492
 
493
  btn_diagram.click(
494
- generate_diagram,
495
  inputs=[expr_input, vals_input, mode_input, notation_input],
496
- outputs=[diagram_output, code_output]
497
  ).then(
498
  reset_downloads,
499
  outputs=[download_pdf, download_png, download_svg]
500
  )
501
 
502
  btn_trace.click(
503
- generate_trace,
504
  inputs=[expr_input, vals_input, mode_input, notation_input],
505
- outputs=[trace_output]
506
  )
507
 
508
  def load_initial_outputs(expr, vals, mode, notation):
 
274
  for title, label, description in samples) + '</div>'
275
 
276
 
277
+ with gr.Blocks(title="Autodiff Mermaid Visualizer", head=TRACE_VIEW_SCRIPT) as demo:
278
  gr.Markdown("# ๐Ÿงฎ Autodiff Mermaid Visualizer")
279
  gr.Markdown("Type any mathematical expression and supply numerical values to visualize the computational graph and derivative calculus.")
280
 
 
309
  btn_diagram = gr.Button("Generate Diagram", variant="primary")
310
  btn_trace = gr.Button("Generate Trace", variant="primary")
311
 
312
+ with gr.Tabs(selected="tab_diagram") as main_tabs:
313
+ with gr.TabItem("๐Ÿ“Š Visual Diagram", id="tab_diagram"):
314
  diagram_output = gr.HTML(label="Diagram")
315
 
316
  with gr.Accordion("๐Ÿ“ฅ Download & Export (On-Demand)", open=True):
 
327
  with gr.Accordion("๐Ÿ’ก Visual Grammar & Diagram Guide", open=True):
328
  gr.HTML(build_visual_grammar_html())
329
 
330
+ with gr.TabItem("๐Ÿ“ Step-by-Step Trace", id="tab_trace"):
331
+ trace_output = gr.HTML(label="Step-by-step trace")
332
 
333
+ with gr.TabItem("๐Ÿ’ป Mermaid Code", id="tab_code"):
334
  code_output = gr.Code(label="Mermaid Syntax", language="markdown")
335
+ with gr.TabItem("๐Ÿ“– Online Help", id="tab_help"):
336
  gr.Markdown(
337
  VISUAL_LANGUAGE + r"""
338
 
 
491
  )
492
 
493
  btn_diagram.click(
494
+ lambda *args: (gr.update(selected="tab_diagram"), *generate_diagram(*args)),
495
  inputs=[expr_input, vals_input, mode_input, notation_input],
496
+ outputs=[main_tabs, diagram_output, code_output]
497
  ).then(
498
  reset_downloads,
499
  outputs=[download_pdf, download_png, download_svg]
500
  )
501
 
502
  btn_trace.click(
503
+ lambda *args: (gr.update(selected="tab_trace"), generate_trace(*args)),
504
  inputs=[expr_input, vals_input, mode_input, notation_input],
505
+ outputs=[main_tabs, trace_output]
506
  )
507
 
508
  def load_initial_outputs(expr, vals, mode, notation):