Download app.py from 0Learn/WWTM: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/0Learn/WWTM/resolve/main/app.py
- Command line
-
hf download hf://spaces/0Learn/WWTM/app.py
-
curl -L -o app.py https://huggingface.co/spaces/0Learn/WWTM/resolve/main/app.py
1.25 kB
| 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() |