DawnC commited on
Commit
606b787
1 Parent(s): 1ce85e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -625,34 +625,39 @@ with gr.Blocks() as iface:
625
  initial_state = gr.State()
626
 
627
  def create_buttons(button_texts):
628
- with button_container:
629
- button_container.clear()
630
- buttons = [gr.Button(text) for text in button_texts]
 
 
 
 
 
 
631
  return buttons
632
 
 
 
 
 
 
633
  input_image.change(
634
  predict,
635
  inputs=input_image,
636
  outputs=[output, output_image, button_container, back_button, initial_state]
637
- )
638
-
639
- def on_button_click(button_text, output, state):
640
- return show_details(button_text, output, state)
641
-
642
- button_container.select(
643
- on_button_click,
644
- inputs=["selected", output, initial_state],
645
- outputs=[output, back_button, initial_state]
646
  )
647
 
648
  def go_back(state):
649
- buttons = create_buttons(state["buttons"])
650
- return state["explanation"], gr.update(visible=state["show_back"]), state
651
 
652
  back_button.click(
653
  go_back,
654
  inputs=[initial_state],
655
- outputs=[output, back_button, initial_state]
656
  )
657
 
658
  gr.Examples(
 
625
  initial_state = gr.State()
626
 
627
  def create_buttons(button_texts):
628
+ buttons = []
629
+ for text in button_texts:
630
+ button = gr.Button(text)
631
+ button.click(
632
+ show_details,
633
+ inputs=[button, output, initial_state],
634
+ outputs=[output, back_button, initial_state]
635
+ )
636
+ buttons.append(button)
637
  return buttons
638
 
639
+ def update_ui(explanation, image, button_texts, show_back, state):
640
+ button_container.clear()
641
+ buttons = create_buttons(button_texts)
642
+ return explanation, image, *buttons, gr.update(visible=show_back), state
643
+
644
  input_image.change(
645
  predict,
646
  inputs=input_image,
647
  outputs=[output, output_image, button_container, back_button, initial_state]
648
+ ).then(
649
+ update_ui,
650
+ inputs=[output, output_image, button_container, back_button, initial_state],
651
+ outputs=[output, output_image] + [button_container] * 9 + [back_button, initial_state]
 
 
 
 
 
652
  )
653
 
654
  def go_back(state):
655
+ return update_ui(state["explanation"], None, state["buttons"], state["show_back"], state)
 
656
 
657
  back_button.click(
658
  go_back,
659
  inputs=[initial_state],
660
+ outputs=[output, output_image] + [button_container] * 9 + [back_button, initial_state]
661
  )
662
 
663
  gr.Examples(