Papajams commited on
Commit
6935f45
·
verified ·
1 Parent(s): 8342229

fix: remove invalid Accordion outputs, add None check in _poll

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -2011,13 +2011,13 @@ setupInteractions();
2011
  checkin_btn.click(
2012
  fn=lambda w, n, s: (_render_awaiting(s), s.to_dict(), s) if (setattr(s, 'check_in_word', w.strip()[:40]), setattr(s, 'check_in_note', n.strip() if n.strip() else ''), setattr(s, 'checked_in', True)) else (None, None, None),
2013
  inputs=[word, note, state], outputs=[content, browser_state, state],
2014
- ).then(fn=lambda: (gr.Accordion(open=False), gr.Accordion(open=True)), outputs=[checkin_acc, receive_acc])
2015
 
2016
  # Wire generate
2017
  generate_btn.click(
2018
  fn=lambda s: (_render_generating(s.today_cast or "future_self"), s.to_dict(), s) if (setattr(s, 'generating', True), setattr(s, 'generation_done', False), setattr(s, 'today_audio', ''), setattr(s, 'today_cast', _choose_cast(s)), threading.Thread(target=_gen_async, args=(s, s.to_context(), s.today_cast, date.today().strftime("%Y-%m-%d %H:%M")), daemon=True).start()) else (None, None, None),
2019
  inputs=[state], outputs=[content, browser_state, state],
2020
- ).then(fn=lambda: gr.Accordion(open=False), outputs=[receive_acc])
2021
 
2022
  # Poll for generation.
2023
  # gr.Timer in Gradio 5 fires `tick` at the given interval. We keep
@@ -2029,16 +2029,18 @@ setupInteractions();
2029
  # when idle, at the cost of one tiny /queue/join call every 2s.
2030
  poll_timer = gr.Timer(value=2, active=True)
2031
  def _poll(s: AppState):
 
 
2032
  if s.generation_done and s.today_transmission:
2033
  # Clear the generating flag so we don't keep rendering
2034
  # the tuning display on subsequent ticks.
2035
  s.generating = False
2036
- return _render_transmission(s), s.to_dict(), s, gr.Accordion(visible=True)
2037
  if s.generating:
2038
- return _render_generating(s.today_cast or "future_self"), s.to_dict(), s, gr.Accordion(visible=False)
2039
  # Idle: no-op. Returning Nones leaves the components unchanged.
2040
- return None, None, None, None
2041
- poll_timer.tick(fn=_poll, inputs=[state], outputs=[content, browser_state, state, choice_acc])
2042
 
2043
  # Wire choice
2044
  choice_btn.click(
@@ -2050,7 +2052,7 @@ setupInteractions();
2050
  setattr(s, 'today_choice', c),
2051
  ) else (None, None, None),
2052
  inputs=[choice, state], outputs=[content, browser_state, state],
2053
- ).then(fn=lambda: (gr.Accordion(open=False), gr.Accordion(open=True)), outputs=[choice_acc, reaction_acc])
2054
 
2055
  # Wire reaction
2056
  react_btn.click(
@@ -2061,16 +2063,11 @@ setupInteractions();
2061
  setattr(s, 'check_in_word', ""), setattr(s, 'check_in_note', ""),
2062
  ) else (None, None, None),
2063
  inputs=[reaction, reply_note, state], outputs=[content, browser_state, state],
2064
- ).then(fn=lambda: (gr.Accordion(open=False), gr.Accordion(open=True)), outputs=[reaction_acc, checkin_acc])
2065
 
2066
  # Maya demo button: skip onboarding, go straight to the transmission.
2067
- # Wired here (after the accordions) so the lambda can close them.
2068
  demo_btn.click(fn=_load_maya_demo, inputs=[state], outputs=[content, browser_state, state]).then(
2069
- fn=lambda: gr.Column(visible=False), outputs=[onboard_col]).then(
2070
- # Close receive + check-in accordions; open the "your move" one
2071
- # so the judge can immediately pick toward/steady/release/repair
2072
- fn=lambda: (gr.Accordion(open=False), gr.Accordion(open=False), gr.Accordion(open=True, visible=True)),
2073
- outputs=[receive_acc, checkin_acc, choice_acc],
2074
  )
2075
 
2076
  # ── History tab ────────────────────────────────────────────
 
2011
  checkin_btn.click(
2012
  fn=lambda w, n, s: (_render_awaiting(s), s.to_dict(), s) if (setattr(s, 'check_in_word', w.strip()[:40]), setattr(s, 'check_in_note', n.strip() if n.strip() else ''), setattr(s, 'checked_in', True)) else (None, None, None),
2013
  inputs=[word, note, state], outputs=[content, browser_state, state],
2014
+ )
2015
 
2016
  # Wire generate
2017
  generate_btn.click(
2018
  fn=lambda s: (_render_generating(s.today_cast or "future_self"), s.to_dict(), s) if (setattr(s, 'generating', True), setattr(s, 'generation_done', False), setattr(s, 'today_audio', ''), setattr(s, 'today_cast', _choose_cast(s)), threading.Thread(target=_gen_async, args=(s, s.to_context(), s.today_cast, date.today().strftime("%Y-%m-%d %H:%M")), daemon=True).start()) else (None, None, None),
2019
  inputs=[state], outputs=[content, browser_state, state],
2020
+ )
2021
 
2022
  # Poll for generation.
2023
  # gr.Timer in Gradio 5 fires `tick` at the given interval. We keep
 
2029
  # when idle, at the cost of one tiny /queue/join call every 2s.
2030
  poll_timer = gr.Timer(value=2, active=True)
2031
  def _poll(s: AppState):
2032
+ if s is None:
2033
+ return None, None, None
2034
  if s.generation_done and s.today_transmission:
2035
  # Clear the generating flag so we don't keep rendering
2036
  # the tuning display on subsequent ticks.
2037
  s.generating = False
2038
+ return _render_transmission(s), s.to_dict(), s
2039
  if s.generating:
2040
+ return _render_generating(s.today_cast or "future_self"), s.to_dict(), s
2041
  # Idle: no-op. Returning Nones leaves the components unchanged.
2042
+ return None, None, None
2043
+ poll_timer.tick(fn=_poll, inputs=[state], outputs=[content, browser_state, state])
2044
 
2045
  # Wire choice
2046
  choice_btn.click(
 
2052
  setattr(s, 'today_choice', c),
2053
  ) else (None, None, None),
2054
  inputs=[choice, state], outputs=[content, browser_state, state],
2055
+ ).then(fn=lambda: None, outputs=[]) # Accordion state handled via JS
2056
 
2057
  # Wire reaction
2058
  react_btn.click(
 
2063
  setattr(s, 'check_in_word', ""), setattr(s, 'check_in_note', ""),
2064
  ) else (None, None, None),
2065
  inputs=[reaction, reply_note, state], outputs=[content, browser_state, state],
2066
+ ).then(fn=lambda: None, outputs=[])
2067
 
2068
  # Maya demo button: skip onboarding, go straight to the transmission.
 
2069
  demo_btn.click(fn=_load_maya_demo, inputs=[state], outputs=[content, browser_state, state]).then(
2070
+ fn=lambda: gr.Column(visible=False), outputs=[onboard_col]
 
 
 
 
2071
  )
2072
 
2073
  # ── History tab ────────────────────────────────────────────