| import gradio as gr |
| import random |
| import time |
| import threading |
|
|
| |
| game_state = { |
| "game_started": False, |
| "current_question": 0, |
| "money": 0, |
| "lifelines": {"fifty_fifty": True, "skip": True, "clue": True}, |
| "safe_levels": [5, 10], |
| "timer": 60, |
| "timer_active": False |
| } |
|
|
| |
| questions = [ |
| { |
| "question": "What does the Gen Z term 'No cap' mean?", |
| "options": ["A. No lie", "B. No truth", "C. No joke", "D. No fun"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 80's term 'Rad' mean?", |
| "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the Millennial term 'Adulting' mean?", |
| "options": ["A. Acting like an adult", "B. Acting like a kid", "C. Being responsible", "D. Being irresponsible"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the Gen Z term 'Simp' mean?", |
| "options": ["A. A simple person", "B. A smart person", "C. A kind person", "D. A foolish person"], |
| "correct": "D", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 90's term 'Talk to the hand' mean?", |
| "options": ["A. I'm not listening", "B. I'm listening", "C. I'm busy", "D. I'm available"], |
| "correct": "A", |
| "generation": "90s" |
| }, |
| { |
| "question": "What does the Millennial term 'Slay' mean?", |
| "options": ["A. To do poorly", "B. To do well", "C. To try hard", "D. To give up"], |
| "correct": "B", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the Gen Z term 'Ghost' mean?", |
| "options": ["A. To leave suddenly", "B. To stay forever", "C. To come back", "D. To never leave"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 70's term 'Freak out' mean?", |
| "options": ["A. To dance wildly", "B. To sing loudly", "C. To lose control", "D. To stay calm"], |
| "correct": "C", |
| "generation": "70s" |
| }, |
| { |
| "question": "What does the Millennial term 'Lowkey' mean?", |
| "options": ["A. Secretly", "B. Openly", "C. Quietly", "D. Loudly"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the Gen Z term 'Highkey' mean?", |
| "options": ["A. Obviously", "B. Secretly", "C. Quietly", "D. Loudly"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 60's term 'Groovy' mean?", |
| "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "60s" |
| }, |
| { |
| "question": "What does the Millennial term 'Shook' mean?", |
| "options": ["A. Surprised", "B. Unimpressed", "C. Excited", "D. Bored"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the Gen Z term 'Savage' mean?", |
| "options": ["A. Cruel", "B. Kind", "C. Funny", "D. Sad"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 50's term 'Cool cat' mean?", |
| "options": ["A. A cool person", "B. A mean person", "C. A happy person", "D. A sad person"], |
| "correct": "A", |
| "generation": "50s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Lit' mean?", |
| "options": ["A. Exciting", "B. Boring", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the Millennial term 'Yaaas' mean?", |
| "options": ["A. Yes", "B. No", "C. Maybe", "D. I don't know"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the Gen Z term 'No tea, no shade' mean?", |
| "options": ["A. No gossip, no insult", "B. No news, no rumors", "C. No secrets, no lies", "D. No fun, no joke"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 90's term 'As if!' mean?", |
| "options": ["A. I don't believe you", "B. I believe you", "C. I'm joking", "D. I'm serious"], |
| "correct": "A", |
| "generation": "90s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Shooketh' mean?", |
| "options": ["A. Surprised", "B. Unimpressed", "C. Excited", "D. Bored"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 80's term 'Gag me with a spoon' mean?", |
| "options": ["A. I'm disgusted", "B. I'm happy", "C. I'm sad", "D. I'm angry"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the 50's term 'Cruisin' for a bruisin'' mean?", |
| "options": ["A. Looking for trouble", "B. Looking for fun", "C. Looking for love", "D. Looking for friendship"], |
| "correct": "A", |
| "generation": "50s" |
| }, |
| { |
| "question": "What does the 80's term 'Gnarly' mean?", |
| "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the 70's term 'Freaky' mean?", |
| "options": ["A. Weird", "B. Normal", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "70s" |
| }, |
| { |
| "question": "What does the Millennial term 'Turn up' mean?", |
| "options": ["A. To have fun", "B. To be quiet", "C. To go home", "D. To stay in"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 60's term 'Vibes' mean?", |
| "options": ["A. Good atmosphere", "B. Bad atmosphere", "C. Happy feelings", "D. Sad feelings"], |
| "correct": "A", |
| "generation": "60s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Bet' mean?", |
| "options": ["A. Okay", "B. Not okay", "C. Maybe", "D. I don't know"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 80's term 'Bogus' mean?", |
| "options": ["A. Bad", "B. Good", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Tea' mean?", |
| "options": ["A. Gossip", "B. News", "C. Rumors", "D. Secrets"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 70's term 'Stay cool' mean?", |
| "options": ["A. Stay calm", "B. Stay happy", "C. Stay sad", "D. Stay angry"], |
| "correct": "A", |
| "generation": "70s" |
| }, |
| { |
| "question": "What does the Millennial term 'Turnt' mean?", |
| "options": ["A. Exciting", "B. Boring", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 60's term 'Far out' mean?", |
| "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "60s" |
| }, |
| { |
| "question": "What does the Millennial term 'Lowkey/Highkey' mean?", |
| "options": ["A. Secretly/Openly", "B. Quietly/Loudly", "C. Happy/Sad", "D. Angry/Calm"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 50's term 'Square' mean?", |
| "options": ["A. A cool person", "B. A mean person", "C. A happy person", "D. An uncool person"], |
| "correct": "D", |
| "generation": "50s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Cap' mean?", |
| "options": ["A. To lie", "B. To tell the truth", "C. To joke", "D. To be serious"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the Millennial term 'Sis' mean?", |
| "options": ["A. A friend", "B. A family member", "C. A stranger", "D. An enemy"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 90's term 'Word' mean?", |
| "options": ["A. True", "B. False", "C. Maybe", "D. I don't know"], |
| "correct": "A", |
| "generation": "90s" |
| }, |
| { |
| "question": "What does the Gen Z term 'Mid' mean?", |
| "options": ["A. Good", "B. Bad", "C. Okay", "D. Awful"], |
| "correct": "B", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 80's term 'Psyche' mean?", |
| "options": ["A. To trick", "B. To help", "C. To joke", "D. To be serious"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the Millennial term 'Tea time' mean?", |
| "options": ["A. Time for gossip", "B. Time for news", "C. Time for rumors", "D. Time for secrets"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 70's term 'Dig it' mean?", |
| "options": ["A. To understand", "B. To not understand", "C. To like", "D. To dislike"], |
| "correct": "A", |
| "generation": "70s" |
| }, |
| { |
| "question": "What does the Gen Z term 'No drama' mean?", |
| "options": ["A. No conflict", "B. No fun", "C. No friends", "D. No life"], |
| "correct": "A", |
| "generation": "Gen Z" |
| }, |
| { |
| "question": "What does the 60's term 'Hang loose' mean?", |
| "options": ["A. To relax", "B. To worry", "C. To be happy", "D. To be sad"], |
| "correct": "A", |
| "generation": "60s" |
| }, |
| { |
| "question": "What does the Millennial term 'Shade' mean?", |
| "options": ["A. To insult", "B. To compliment", "C. To joke", "D. To be serious"], |
| "correct": "A", |
| "generation": "Millennial" |
| }, |
| { |
| "question": "What does the 50's term 'Righteous' mean?", |
| "options": ["A. Good", "B. Bad", "C. Happy", "D. Sad"], |
| "correct": "A", |
| "generation": "50s" |
| }, |
| { |
| "question": "What does the 80's term 'Harshing the mellow' mean?", |
| "options": ["A. To ruin the fun", "B. To enhance the fun", "C. To not affect the fun", "D. To leave the fun"], |
| "correct": "A", |
| "generation": "80s" |
| }, |
| { |
| "question": "What does the 70's term 'Freak flag' mean?", |
| "options": ["A. To express oneself", "B. To hide oneself", "C. To be different", "D. To be normal"], |
| "correct": "A", |
| "generation": "70s" |
| } |
| ] |
|
|
| |
|
|
| |
|
|
| demo.launch() |
|
|
| |
| money_levels = [100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 250000, 500000, 1000000] |
|
|
| |
| timer_prompts = [ |
| "Tick tock! 50 seconds left. No pressure, but also... lots of pressure!", |
| "40 seconds remaining. Is that your final answer? (No, seriously, is it?)", |
| "30 seconds on the clock! Time flies when you're trying to be a millionaire!", |
| "20 seconds left! Don't let the clock psyche you out!", |
| "Only 10 seconds remaining! Quick, phone a fr... oh wait, wrong lifeline!", |
| ] |
|
|
| def start_timer(): |
| game_state["timer"] = 60 |
| game_state["timer_active"] = True |
| while game_state["timer"] > 0 and game_state["timer_active"]: |
| time.sleep(1) |
| game_state["timer"] -= 1 |
|
|
| def get_bot_response(message): |
| message = message.lower().strip() |
| |
| if not game_state["game_started"]: |
| if "start game" in message or "play game" in message: |
| game_state["game_started"] = True |
| game_state["current_question"] = 0 |
| game_state["money"] = 0 |
| game_state["lifelines"] = {"fifty_fifty": True, "skip": True, "clue": True} |
| return "Welcome to Who Wants to Be a Millionaire: Slang Edition! Let's start with the first question. Type 'ready' when you're set to go!" |
| else: |
| return "I'm a Who Wants to Be a Millionaire: Slang Edition game bot. Type 'start game' to begin playing!" |
|
|
| if message == "ready": |
| question = questions[game_state["current_question"]] |
| options = "\n".join(question["options"]) |
| threading.Thread(target=start_timer).start() |
| return f"Question {game_state['current_question'] + 1} for ${money_levels[game_state['current_question']]}:\n{question['question']}\n{options}\nLifelines available: {', '.join([k for k, v in game_state['lifelines'].items() if v])}\nYou have 60 seconds. Go!" |
|
|
| if message in ["a", "b", "c", "d"]: |
| game_state["timer_active"] = False |
| question = questions[game_state["current_question"]] |
| if message.upper() == question["correct"]: |
| game_state["money"] = money_levels[game_state["current_question"]] |
| game_state["current_question"] += 1 |
| if game_state["current_question"] == len(questions): |
| game_state["game_started"] = False |
| return f"Congratulations! You've won the grand prize of $1,000,000! Game over. Type 'start game' to play again." |
| elif game_state["current_question"] in game_state["safe_levels"]: |
| return f"Correct! You've reached a safe level of ${game_state['money']}. Type 'ready' for the next question." |
| else: |
| return f"Correct! You've won ${game_state['money']}. Type 'ready' for the next question or 'quit' to leave with your winnings." |
| else: |
| game_state["game_started"] = False |
| safe_money = max([money_levels[level - 1] for level in game_state["safe_levels"] if level <= game_state["current_question"]], default=0) |
| return f"I'm sorry, that's incorrect. The correct answer was {question['correct']}. You leave with ${safe_money}. Game over. Type 'start game' to play again." |
|
|
| if message == "quit": |
| game_state["timer_active"] = False |
| game_state["game_started"] = False |
| return f"You've decided to quit. You leave with ${game_state['money']}. Thanks for playing! Type 'start game' to play again." |
|
|
| if message == "fifty_fifty" and game_state["lifelines"]["fifty_fifty"]: |
| game_state["lifelines"]["fifty_fifty"] = False |
| question = questions[game_state["current_question"]] |
| correct = question["correct"] |
| options = [opt[0].upper() for opt in question["options"]] |
| options.remove(correct) |
| remove = random.sample(options, 2) |
| new_options = [opt for opt in question["options"] if opt[0].upper() not in remove] |
| return f"Fifty-Fifty used. Remaining options:\n" + "\n".join(new_options) |
|
|
| if message == "skip" and game_state["lifelines"]["skip"]: |
| game_state["lifelines"]["skip"] = False |
| game_state["current_question"] += 1 |
| game_state["timer_active"] = False |
| return "Skip used. Moving to the next question. Type 'ready' to see it." |
|
|
| if message == "clue" and game_state["lifelines"]["clue"]: |
| game_state["lifelines"]["clue"] = False |
| question = questions[game_state["current_question"]] |
| correct = question["correct"] |
| options = [opt[0].upper() for opt in question["options"]] |
| options.remove(correct) |
| remove = random.choice(options) |
| new_options = [opt for opt in question["options"] if opt[0].upper() != remove] |
| return f"Clue used. One wrong option removed. Remaining options:\n" + "\n".join(new_options) |
|
|
| return "I don't understand that command. Type 'ready' for the question, A/B/C/D to answer, or use a lifeline (fifty_fifty/skip/clue)." |
|
|
| def chat(message, history): |
| history = history or [] |
| history.append((message, "")) |
| bot_message = get_bot_response(message) |
| history.append((message, bot_message)) |
| return history, "" |
|
|
| def timer_update(history): |
| if game_state["timer_active"]: |
| if game_state["timer"] == 0: |
| game_state["timer_active"] = False |
| game_state["game_started"] = False |
| safe_money = max([money_levels[level - 1] for level in game_state["safe_levels"] if level <= game_state["current_question"]], default=0) |
| return history + [("System", f"Time's up! You've run out of time. You leave with ${safe_money}. Game over. Type 'start game' to play again.")] |
| elif game_state["timer"] % 10 == 0: |
| prompt_index = 5 - (game_state["timer"] // 10) |
| return history + [("System", timer_prompts[prompt_index])] |
| return history |
|
|
| with gr.Blocks() as demo: |
| chatbot = gr.Chatbot() |
| msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...") |
| clear = gr.Button("Clear") |
|
|
| msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, msg]) |
| clear.click(lambda: None, None, chatbot, queue=False) |
| |
| timer = gr.Number(value=60, label="Time Remaining", every=1) |
| timer.change(timer_update, inputs=[chatbot], outputs=[chatbot]) |
| demo.load(lambda: game_state["timer"], None, timer, every=1) |
|
|
| demo.launch() |