WWTM / app.py
0Learn's picture
Update app.py
4cfad64 verified
import gradio as gr
import random
import time
import threading
from questions import questions
# (Keep all the previous code for game_state, money_levels, timer_prompts, and game logic functions)
# ...
# Modify the chat function to handle empty messages
def chat(message, history):
if message.strip() == "":
return history, ""
history = history or []
bot_message = get_bot_response(message)
history.append((message, bot_message))
return history, ""
# Create the Gradio interface
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
with gr.Row():
msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
submit = gr.Button("Submit")
clear = gr.Button("Clear")
timer = gr.Number(value=60, label="Time Remaining", every=1)
# Set up event handlers
submit_click = submit.click(chat, inputs=[msg, chatbot], outputs=[chatbot, msg], queue=False)
msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, msg], queue=False)
clear.click(lambda: None, None, chatbot, queue=False)
timer.change(timer_update, inputs=[chatbot], outputs=[chatbot])
demo.load(lambda: game_state["timer"], None, timer, every=1)
demo.launch()