Spaces:
No application file
No application file
Liss, Alex (NYC-HUG)
commited on
Commit
Β·
46cccf6
1
Parent(s):
58e0496
WIP functionality achieved on game search
Browse files- 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
|
367 |
-
with gr.
|
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 |
-
#
|
405 |
-
if
|
406 |
-
#
|
407 |
-
|
408 |
-
|
409 |
-
# Create game recap component and add debugging
|
410 |
game_recap_html = create_game_recap_component(state.current_game)
|
411 |
|
412 |
-
#
|
413 |
-
|
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 |
-
#
|
421 |
-
|
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
|
429 |
-
msg.submit(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container]
|
430 |
-
submit.click(process_and_respond, [msg, chatbot], [msg, chatbot, game_recap, game_recap_container]
|
431 |
|
432 |
# Add a clear button
|
433 |
clear = gr.Button("Clear Conversation")
|
434 |
|
435 |
-
# Clear function
|
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]
|
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__":
|