Claude commited on
Commit
a1f9ec2
·
unverified ·
1 Parent(s): f80d3e0

fix: Remove OAuth from demo.load to prevent auth loops

Browse files

The visibility toggling with OAuth profile in demo.load was causing
"Max challenge attempts exceeded" errors. Simplified to always show
the chat interface with login button visible.

Files changed (1) hide show
  1. app.py +41 -61
app.py CHANGED
@@ -866,79 +866,59 @@ def create_demo() -> gr.Blocks:
866
  """
867
  )
868
 
869
- # Login prompt (shown when not logged in)
870
- with gr.Column(visible=True) as login_prompt:
871
- gr.HTML(
872
- """
873
- <div style="text-align: center; padding: 40px 20px;">
874
- <p style="color: #666; margin-bottom: 20px;">
875
- Please sign in with HuggingFace to use the Video Analyzer.
876
- </p>
877
- </div>
878
- """
879
- )
880
- with gr.Row(elem_classes="center-row"):
881
- gr.LoginButton()
882
-
883
- # Chat interface (hidden until login)
884
- with gr.Column(visible=False) as chat_interface:
885
- chatbot = gr.Chatbot(
886
- label="Video Analyzer",
887
- height=400,
888
- type="messages",
889
  )
 
890
 
891
- # Text input row
 
 
892
  with gr.Row():
893
- msg_input = gr.Textbox(
894
- label="Message",
895
- placeholder="Paste a YouTube URL or ask a question...",
896
- scale=5,
897
- lines=1,
898
- )
899
- send_btn = gr.Button("Send", variant="primary", scale=1)
900
-
901
- # Voice input/output row
902
- with gr.Accordion("Voice Mode", open=False):
903
- gr.Markdown("*Speak to ask questions and hear responses*")
904
- with gr.Row():
905
- voice_input = gr.Audio(
906
- sources=["microphone"],
907
- type="filepath",
908
- label="Click to record your question",
909
- scale=3,
910
- )
911
- voice_btn = gr.Button("Send Voice", variant="secondary", scale=1)
912
-
913
- audio_output = gr.Audio(
914
- label="Response",
915
  type="filepath",
916
- autoplay=True,
 
917
  )
 
918
 
919
- with gr.Row():
920
- kb_status = gr.Markdown()
921
- clear_btn = gr.Button("Clear Chat", size="sm")
 
 
 
 
 
 
922
 
923
  # Initialize session on load
924
  def init_session(
925
  current_state: SessionState | None,
926
- profile: gr.OAuthProfile | None = None,
927
- ) -> tuple[list[dict], str, SessionState, gr.Column, gr.Column]:
928
  """Initialize session state and welcome message."""
929
  if current_state is None:
930
- current_state = create_session_state(profile)
931
- welcome = get_welcome_message(profile)
932
  stats = get_knowledge_stats(current_state)
933
- # Show chat interface only if logged in
934
- is_logged_in = profile is not None
935
- return (
936
- welcome,
937
- stats,
938
- current_state,
939
- gr.Column(visible=not is_logged_in), # login_prompt
940
- gr.Column(visible=is_logged_in), # chat_interface
941
- )
942
 
943
  def handle_voice_chat(
944
  audio_path: str,
@@ -1013,7 +993,7 @@ def create_demo() -> gr.Blocks:
1013
  demo.load(
1014
  fn=init_session,
1015
  inputs=[session_state],
1016
- outputs=[chatbot, kb_status, session_state, login_prompt, chat_interface],
1017
  )
1018
 
1019
  return demo
 
866
  """
867
  )
868
 
869
+ # Login button row
870
+ with gr.Row():
871
+ gr.LoginButton()
872
+
873
+ # Chat interface
874
+ chatbot = gr.Chatbot(
875
+ label="Video Analyzer",
876
+ height=400,
877
+ type="messages",
878
+ )
879
+
880
+ # Text input row
881
+ with gr.Row():
882
+ msg_input = gr.Textbox(
883
+ label="Message",
884
+ placeholder="Paste a YouTube URL or ask a question...",
885
+ scale=5,
886
+ lines=1,
 
 
887
  )
888
+ send_btn = gr.Button("Send", variant="primary", scale=1)
889
 
890
+ # Voice input/output row
891
+ with gr.Accordion("Voice Mode", open=False):
892
+ gr.Markdown("*Speak to ask questions and hear responses*")
893
  with gr.Row():
894
+ voice_input = gr.Audio(
895
+ sources=["microphone"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
  type="filepath",
897
+ label="Click to record your question",
898
+ scale=3,
899
  )
900
+ voice_btn = gr.Button("Send Voice", variant="secondary", scale=1)
901
 
902
+ audio_output = gr.Audio(
903
+ label="Response",
904
+ type="filepath",
905
+ autoplay=True,
906
+ )
907
+
908
+ with gr.Row():
909
+ kb_status = gr.Markdown()
910
+ clear_btn = gr.Button("Clear Chat", size="sm")
911
 
912
  # Initialize session on load
913
  def init_session(
914
  current_state: SessionState | None,
915
+ ) -> tuple[list[dict], str, SessionState]:
 
916
  """Initialize session state and welcome message."""
917
  if current_state is None:
918
+ current_state = create_session_state(None)
919
+ welcome = get_welcome_message(None)
920
  stats = get_knowledge_stats(current_state)
921
+ return welcome, stats, current_state
 
 
 
 
 
 
 
 
922
 
923
  def handle_voice_chat(
924
  audio_path: str,
 
993
  demo.load(
994
  fn=init_session,
995
  inputs=[session_state],
996
+ outputs=[chatbot, kb_status, session_state],
997
  )
998
 
999
  return demo