|
|
import gradio as gr |
|
|
import random |
|
|
import time |
|
|
import threading |
|
|
from questions import questions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, "" |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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() |