File size: 1,248 Bytes
c9f8348 433ba72 39ed164 c9f8348 4cfad64 433ba72 4cfad64 433ba72 4cfad64 433ba72 4cfad64 433ba72 614f34a c9f8348 433ba72 614f34a 433ba72 614f34a c57d876 614f34a 4cfad64 614f34a 433ba72 c57d876 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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() |