Liss, Alex (NYC-HUG) commited on
Commit
46cccf6
Β·
1 Parent(s): 58e0496

WIP functionality achieved on game search

Browse files
Files changed (1) hide show
  1. gradio_app.py +22 -32
gradio_app.py CHANGED
@@ -363,9 +363,9 @@ def bot_response(history):
363
  with gr.Blocks(title="49ers FanAI Hub", theme=gr.themes.Soft(), css=css) as demo:
364
  gr.Markdown("# 🏈 49ers FanAI Hub")
365
 
366
- # Game Recap Component (use a container with HTML inside)
367
- with gr.Column(visible=False) as game_recap_container:
368
- game_recap = gr.HTML("")
369
 
370
  # Chat interface
371
  chatbot = gr.Chatbot(
@@ -373,7 +373,8 @@ with gr.Blocks(title="49ers FanAI Hub", theme=gr.themes.Soft(), css=css) as demo
373
  height=500,
374
  show_label=False,
375
  elem_id="chatbot",
376
- type="messages"
 
377
  )
378
 
379
  # Input components
@@ -395,49 +396,38 @@ with gr.Blocks(title="49ers FanAI Hub", theme=gr.themes.Soft(), css=css) as demo
395
 
396
  # Now handle the actual user message
397
  history.append({"role": "user", "content": message})
 
 
398
  response = await process_message(message)
 
 
399
  history.append({"role": "assistant", "content": response})
400
-
401
- # Update game recap component visibility based on current_game
402
- has_game_data = state.current_game is not None
403
 
404
- # Create the game recap HTML content if we have game data
405
- if has_game_data:
406
- # Print game data for debugging
407
- print(f"Creating game recap component with data: {state.current_game}")
408
-
409
- # Create game recap component and add debugging
410
  game_recap_html = create_game_recap_component(state.current_game)
411
 
412
- # Debug the HTML content
413
- print(f"Game recap component created: {type(game_recap_html)}")
414
-
415
- # Make sure the container is visible
416
- container_update = gr.update(visible=True)
417
-
418
- return "", history, game_recap_html, container_update
419
  else:
420
- # Create an empty HTML component
421
- print("No game data available, hiding game recap component")
422
- game_recap_html = gr.HTML("")
423
- # Hide the container
424
- container_update = gr.update(visible=False)
425
-
426
- return "", history, game_recap_html, container_update
427
 
428
- # Set up event handlers with the combined function - explicitly disable queue
429
- msg.submit(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container], queue=False)
430
- submit.click(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container], queue=False)
431
 
432
  # Add a clear button
433
  clear = gr.Button("Clear Conversation")
434
 
435
- # Clear function that also hides the game recap
436
  def clear_chat():
437
  state.set_current_game(None)
438
  return [], gr.HTML(""), gr.update(visible=False)
439
 
440
- clear.click(clear_chat, None, [chatbot, game_recap, game_recap_container], queue=False)
441
 
442
  # Launch the app
443
  if __name__ == "__main__":
 
363
  with gr.Blocks(title="49ers FanAI Hub", theme=gr.themes.Soft(), css=css) as demo:
364
  gr.Markdown("# 🏈 49ers FanAI Hub")
365
 
366
+ # Game recap container at the top that appears only when needed
367
+ with gr.Row(visible=False) as game_recap_container:
368
+ game_recap = gr.HTML()
369
 
370
  # Chat interface
371
  chatbot = gr.Chatbot(
 
373
  height=500,
374
  show_label=False,
375
  elem_id="chatbot",
376
+ type="messages",
377
+ render_markdown=True
378
  )
379
 
380
  # Input components
 
396
 
397
  # Now handle the actual user message
398
  history.append({"role": "user", "content": message})
399
+
400
+ # Process the message
401
  response = await process_message(message)
402
+
403
+ # Add text response to history
404
  history.append({"role": "assistant", "content": response})
 
 
 
405
 
406
+ # Check if we have game data to display
407
+ if state.current_game:
408
+ # Use the create_game_recap_component function to get proper HTML
409
+ game_data = state.current_game
 
 
410
  game_recap_html = create_game_recap_component(state.current_game)
411
 
412
+ # Show the game recap container with the HTML content
413
+ return "", history, game_recap_html, gr.update(visible=True)
 
 
 
 
 
414
  else:
415
+ # Hide the game recap container
416
+ return "", history, gr.HTML(""), gr.update(visible=False)
 
 
 
 
 
417
 
418
+ # Set up event handlers with the combined function
419
+ msg.submit(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container])
420
+ submit.click(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container])
421
 
422
  # Add a clear button
423
  clear = gr.Button("Clear Conversation")
424
 
425
+ # Clear function
426
  def clear_chat():
427
  state.set_current_game(None)
428
  return [], gr.HTML(""), gr.update(visible=False)
429
 
430
+ clear.click(clear_chat, None, [chatbot, game_recap, game_recap_container])
431
 
432
  # Launch the app
433
  if __name__ == "__main__":