0Learn commited on
Commit
614f34a
·
verified ·
1 Parent(s): 534059b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -394
app.py CHANGED
@@ -3,414 +3,37 @@ import random
3
  import time
4
  import threading
5
 
6
- # Game state
7
- game_state = {
8
- "game_started": False,
9
- "current_question": 0,
10
- "money": 0,
11
- "lifelines": {"fifty_fifty": True, "skip": True, "clue": True},
12
- "safe_levels": [5, 10],
13
- "timer": 60,
14
- "timer_active": False
15
- }
16
 
17
- # Money levels
18
- money_levels = [100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 250000, 500000, 1000000]
19
-
20
- # Timer prompts
21
- timer_prompts = [
22
- "Tick tock! 50 seconds left. No pressure, but also... lots of pressure!",
23
- "40 seconds remaining. Is that your final answer? (No, seriously, is it?)",
24
- "30 seconds on the clock! Time flies when you're trying to be a millionaire!",
25
- "20 seconds left! Don't let the clock psyche you out!",
26
- "Only 10 seconds remaining! Quick, phone a fr... oh wait, wrong lifeline!",
27
- ]
28
-
29
- # Updated Question bank
30
- questions = [
31
- {
32
- "question": "What does the Gen Z term 'No cap' mean?",
33
- "options": ["A. No lie", "B. No truth", "C. No joke", "D. No fun"],
34
- "correct": "A",
35
- "generation": "Gen Z"
36
- },
37
- {
38
- "question": "What does the 80's term 'Rad' mean?",
39
- "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"],
40
- "correct": "A",
41
- "generation": "80s"
42
- },
43
- {
44
- "question": "What does the Millennial term 'Adulting' mean?",
45
- "options": ["A. Acting like an adult", "B. Acting like a kid", "C. Being responsible", "D. Being irresponsible"],
46
- "correct": "A",
47
- "generation": "Millennial"
48
- },
49
- {
50
- "question": "What does the Gen Z term 'Simp' mean?",
51
- "options": ["A. A simple person", "B. A smart person", "C. A kind person", "D. A foolish person"],
52
- "correct": "D",
53
- "generation": "Gen Z"
54
- },
55
- {
56
- "question": "What does the 90's term 'Talk to the hand' mean?",
57
- "options": ["A. I'm not listening", "B. I'm listening", "C. I'm busy", "D. I'm available"],
58
- "correct": "A",
59
- "generation": "90s"
60
- },
61
- {
62
- "question": "What does the Millennial term 'Slay' mean?",
63
- "options": ["A. To do poorly", "B. To do well", "C. To try hard", "D. To give up"],
64
- "correct": "B",
65
- "generation": "Millennial"
66
- },
67
- {
68
- "question": "What does the Gen Z term 'Ghost' mean?",
69
- "options": ["A. To leave suddenly", "B. To stay forever", "C. To come back", "D. To never leave"],
70
- "correct": "A",
71
- "generation": "Gen Z"
72
- },
73
- {
74
- "question": "What does the 70's term 'Freak out' mean?",
75
- "options": ["A. To dance wildly", "B. To sing loudly", "C. To lose control", "D. To stay calm"],
76
- "correct": "C",
77
- "generation": "70s"
78
- },
79
- {
80
- "question": "What does the Millennial term 'Lowkey' mean?",
81
- "options": ["A. Secretly", "B. Openly", "C. Quietly", "D. Loudly"],
82
- "correct": "A",
83
- "generation": "Millennial"
84
- },
85
- {
86
- "question": "What does the Gen Z term 'Highkey' mean?",
87
- "options": ["A. Obviously", "B. Secretly", "C. Quietly", "D. Loudly"],
88
- "correct": "A",
89
- "generation": "Gen Z"
90
- },
91
- {
92
- "question": "What does the 60's term 'Groovy' mean?",
93
- "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"],
94
- "correct": "A",
95
- "generation": "60s"
96
- },
97
- {
98
- "question": "What does the Millennial term 'Shook' mean?",
99
- "options": ["A. Surprised", "B. Unimpressed", "C. Excited", "D. Bored"],
100
- "correct": "A",
101
- "generation": "Millennial"
102
- },
103
- {
104
- "question": "What does the Gen Z term 'Savage' mean?",
105
- "options": ["A. Cruel", "B. Kind", "C. Funny", "D. Sad"],
106
- "correct": "A",
107
- "generation": "Gen Z"
108
- },
109
- {
110
- "question": "What does the 50's term 'Cool cat' mean?",
111
- "options": ["A. A cool person", "B. A mean person", "C. A happy person", "D. A sad person"],
112
- "correct": "A",
113
- "generation": "50s"
114
- },
115
- {
116
- "question": "What does the Gen Z term 'Lit' mean?",
117
- "options": ["A. Exciting", "B. Boring", "C. Happy", "D. Sad"],
118
- "correct": "A",
119
- "generation": "Gen Z"
120
- },
121
- {
122
- "question": "What does the Millennial term 'Yaaas' mean?",
123
- "options": ["A. Yes", "B. No", "C. Maybe", "D. I don't know"],
124
- "correct": "A",
125
- "generation": "Millennial"
126
- },
127
- {
128
- "question": "What does the Gen Z term 'No tea, no shade' mean?",
129
- "options": ["A. No gossip, no insult", "B. No news, no rumors", "C. No secrets, no lies", "D. No fun, no joke"],
130
- "correct": "A",
131
- "generation": "Gen Z"
132
- },
133
- {
134
- "question": "What does the 90's term 'As if!' mean?",
135
- "options": ["A. I don't believe you", "B. I believe you", "C. I'm joking", "D. I'm serious"],
136
- "correct": "A",
137
- "generation": "90s"
138
- },
139
- {
140
- "question": "What does the Gen Z term 'Shooketh' mean?",
141
- "options": ["A. Surprised", "B. Unimpressed", "C. Excited", "D. Bored"],
142
- "correct": "A",
143
- "generation": "Gen Z"
144
- },
145
- {
146
- "question": "What does the 80's term 'Gag me with a spoon' mean?",
147
- "options": ["A. I'm disgusted", "B. I'm happy", "C. I'm sad", "D. I'm angry"],
148
- "correct": "A",
149
- "generation": "80s"
150
- },
151
- {
152
- "question": "What does the 50's term 'Cruisin' for a bruisin'' mean?",
153
- "options": ["A. Looking for trouble", "B. Looking for fun", "C. Looking for love", "D. Looking for friendship"],
154
- "correct": "A",
155
- "generation": "50s"
156
- },
157
- {
158
- "question": "What does the 80's term 'Gnarly' mean?",
159
- "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"],
160
- "correct": "A",
161
- "generation": "80s"
162
- },
163
- {
164
- "question": "What does the 70's term 'Freaky' mean?",
165
- "options": ["A. Weird", "B. Normal", "C. Happy", "D. Sad"],
166
- "correct": "A",
167
- "generation": "70s"
168
- },
169
- {
170
- "question": "What does the Millennial term 'Turn up' mean?",
171
- "options": ["A. To have fun", "B. To be quiet", "C. To go home", "D. To stay in"],
172
- "correct": "A",
173
- "generation": "Millennial"
174
- },
175
- {
176
- "question": "What does the 60's term 'Vibes' mean?",
177
- "options": ["A. Good atmosphere", "B. Bad atmosphere", "C. Happy feelings", "D. Sad feelings"],
178
- "correct": "A",
179
- "generation": "60s"
180
- },
181
- {
182
- "question": "What does the Gen Z term 'Bet' mean?",
183
- "options": ["A. Okay", "B. Not okay", "C. Maybe", "D. I don't know"],
184
- "correct": "A",
185
- "generation": "Gen Z"
186
- },
187
- {
188
- "question": "What does the 80's term 'Bogus' mean?",
189
- "options": ["A. Bad", "B. Good", "C. Happy", "D. Sad"],
190
- "correct": "A",
191
- "generation": "80s"
192
- },
193
- {
194
- "question": "What does the Gen Z term 'Tea' mean?",
195
- "options": ["A. Gossip", "B. News", "C. Rumors", "D. Secrets"],
196
- "correct": "A",
197
- "generation": "Gen Z"
198
- },
199
- {
200
- "question": "What does the 70's term 'Stay cool' mean?",
201
- "options": ["A. Stay calm", "B. Stay happy", "C. Stay sad", "D. Stay angry"],
202
- "correct": "A",
203
- "generation": "70s"
204
- },
205
- {
206
- "question": "What does the Millennial term 'Turnt' mean?",
207
- "options": ["A. Exciting", "B. Boring", "C. Happy", "D. Sad"],
208
- "correct": "A",
209
- "generation": "Millennial"
210
- },
211
- {
212
- "question": "What does the 60's term 'Far out' mean?",
213
- "options": ["A. Cool", "B. Uncool", "C. Happy", "D. Sad"],
214
- "correct": "A",
215
- "generation": "60s"
216
- },
217
- {
218
- "question": "What does the Millennial term 'Lowkey/Highkey' mean?",
219
- "options": ["A. Secretly/Openly", "B. Quietly/Loudly", "C. Happy/Sad", "D. Angry/Calm"],
220
- "correct": "A",
221
- "generation": "Millennial"
222
- },
223
- {
224
- "question": "What does the 50's term 'Square' mean?",
225
- "options": ["A. A cool person", "B. A mean person", "C. A happy person", "D. An uncool person"],
226
- "correct": "D",
227
- "generation": "50s"
228
- },
229
- {
230
- "question": "What does the Gen Z term 'Cap' mean?",
231
- "options": ["A. To lie", "B. To tell the truth", "C. To joke", "D. To be serious"],
232
- "correct": "A",
233
- "generation": "Gen Z"
234
- },
235
- {
236
- "question": "What does the Millennial term 'Sis' mean?",
237
- "options": ["A. A friend", "B. A family member", "C. A stranger", "D. An enemy"],
238
- "correct": "A",
239
- "generation": "Millennial"
240
- },
241
- {
242
- "question": "What does the 90's term 'Word' mean?",
243
- "options": ["A. True", "B. False", "C. Maybe", "D. I don't know"],
244
- "correct": "A",
245
- "generation": "90s"
246
- },
247
- {
248
- "question": "What does the Gen Z term 'Mid' mean?",
249
- "options": ["A. Good", "B. Bad", "C. Okay", "D. Awful"],
250
- "correct": "B",
251
- "generation": "Gen Z"
252
- },
253
- {
254
- "question": "What does the 80's term 'Psyche' mean?",
255
- "options": ["A. To trick", "B. To help", "C. To joke", "D. To be serious"],
256
- "correct": "A",
257
- "generation": "80s"
258
- },
259
- {
260
- "question": "What does the Millennial term 'Tea time' mean?",
261
- "options": ["A. Time for gossip", "B. Time for news", "C. Time for rumors", "D. Time for secrets"],
262
- "correct": "A",
263
- "generation": "Millennial"
264
- },
265
- {
266
- "question": "What does the 70's term 'Dig it' mean?",
267
- "options": ["A. To understand", "B. To not understand", "C. To like", "D. To dislike"],
268
- "correct": "A",
269
- "generation": "70s"
270
- },
271
- {
272
- "question": "What does the Gen Z term 'No drama' mean?",
273
- "options": ["A. No conflict", "B. No fun", "C. No friends", "D. No life"],
274
- "correct": "A",
275
- "generation": "Gen Z"
276
- },
277
- {
278
- "question": "What does the 60's term 'Hang loose' mean?",
279
- "options": ["A. To relax", "B. To worry", "C. To be happy", "D. To be sad"],
280
- "correct": "A",
281
- "generation": "60s"
282
- },
283
- {
284
- "question": "What does the Millennial term 'Shade' mean?",
285
- "options": ["A. To insult", "B. To compliment", "C. To joke", "D. To be serious"],
286
- "correct": "A",
287
- "generation": "Millennial"
288
- },
289
- {
290
- "question": "What does the 50's term 'Righteous' mean?",
291
- "options": ["A. Good", "B. Bad", "C. Happy", "D. Sad"],
292
- "correct": "A",
293
- "generation": "50s"
294
- },
295
- {
296
- "question": "What does the 80's term 'Harshing the mellow' mean?",
297
- "options": ["A. To ruin the fun", "B. To enhance the fun", "C. To not affect the fun", "D. To leave the fun"],
298
- "correct": "A",
299
- "generation": "80s"
300
- },
301
- {
302
- "question": "What does the 70's term 'Freak flag' mean?",
303
- "options": ["A. To express oneself", "B. To hide oneself", "C. To be different", "D. To be normal"],
304
- "correct": "A",
305
- "generation": "70s"
306
- }
307
- ]
308
-
309
- def start_timer():
310
- game_state["timer"] = 60
311
- game_state["timer_active"] = True
312
- while game_state["timer"] > 0 and game_state["timer_active"]:
313
- time.sleep(1)
314
- game_state["timer"] -= 1
315
-
316
- def get_bot_response(message):
317
- message = message.lower().strip()
318
-
319
- if not game_state["game_started"]:
320
- if "start game" in message or "play game" in message:
321
- game_state["game_started"] = True
322
- game_state["current_question"] = 0
323
- game_state["money"] = 0
324
- game_state["lifelines"] = {"fifty_fifty": True, "skip": True, "clue": True}
325
- 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!"
326
- else:
327
- return "I'm a Who Wants to Be a Millionaire: Slang Edition game bot. Type 'start game' to begin playing!"
328
-
329
- if message == "ready":
330
- question = questions[game_state["current_question"]]
331
- options = "\n".join(question["options"])
332
- threading.Thread(target=start_timer).start()
333
- 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!"
334
-
335
- if message in ["a", "b", "c", "d"]:
336
- game_state["timer_active"] = False
337
- question = questions[game_state["current_question"]]
338
- if message.upper() == question["correct"]:
339
- game_state["money"] = money_levels[game_state["current_question"]]
340
- game_state["current_question"] += 1
341
- if game_state["current_question"] == len(questions):
342
- game_state["game_started"] = False
343
- return f"Congratulations! You've won the grand prize of $1,000,000! Game over. Type 'start game' to play again."
344
- elif game_state["current_question"] in game_state["safe_levels"]:
345
- return f"Correct! You've reached a safe level of ${game_state['money']}. Type 'ready' for the next question."
346
- else:
347
- return f"Correct! You've won ${game_state['money']}. Type 'ready' for the next question or 'quit' to leave with your winnings."
348
- else:
349
- game_state["game_started"] = False
350
- safe_money = max([money_levels[level - 1] for level in game_state["safe_levels"] if level <= game_state["current_question"]], default=0)
351
- 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."
352
-
353
- if message == "quit":
354
- game_state["timer_active"] = False
355
- game_state["game_started"] = False
356
- return f"You've decided to quit. You leave with ${game_state['money']}. Thanks for playing! Type 'start game' to play again."
357
-
358
- if message == "fifty_fifty" and game_state["lifelines"]["fifty_fifty"]:
359
- game_state["lifelines"]["fifty_fifty"] = False
360
- question = questions[game_state["current_question"]]
361
- correct = question["correct"]
362
- options = [opt[0].upper() for opt in question["options"]]
363
- options.remove(correct)
364
- remove = random.sample(options, 2)
365
- new_options = [opt for opt in question["options"] if opt[0].upper() not in remove]
366
- return f"Fifty-Fifty used. Remaining options:\n" + "\n".join(new_options)
367
-
368
- if message == "skip" and game_state["lifelines"]["skip"]:
369
- game_state["lifelines"]["skip"] = False
370
- game_state["current_question"] += 1
371
- game_state["timer_active"] = False
372
- return "Skip used. Moving to the next question. Type 'ready' to see it."
373
-
374
- if message == "clue" and game_state["lifelines"]["clue"]:
375
- game_state["lifelines"]["clue"] = False
376
- question = questions[game_state["current_question"]]
377
- correct = question["correct"]
378
- options = [opt[0].upper() for opt in question["options"]]
379
- options.remove(correct)
380
- remove = random.choice(options)
381
- new_options = [opt for opt in question["options"] if opt[0].upper() != remove]
382
- return f"Clue used. One wrong option removed. Remaining options:\n" + "\n".join(new_options)
383
-
384
- 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)."
385
 
 
386
  def chat(message, history):
387
  history = history or []
388
- history.append((message, ""))
389
  bot_message = get_bot_response(message)
390
  history.append((message, bot_message))
391
  return history, ""
392
 
393
- def timer_update(history):
394
- if game_state["timer_active"]:
395
- if game_state["timer"] == 0:
396
- game_state["timer_active"] = False
397
- game_state["game_started"] = False
398
- safe_money = max([money_levels[level - 1] for level in game_state["safe_levels"] if level <= game_state["current_question"]], default=0)
399
- 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.")]
400
- elif game_state["timer"] % 10 == 0:
401
- prompt_index = 5 - (game_state["timer"] // 10)
402
- return history + [("System", timer_prompts[prompt_index])]
403
- return history
404
-
405
  with gr.Blocks() as demo:
406
  chatbot = gr.Chatbot()
407
- msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
 
 
 
 
408
  clear = gr.Button("Clear")
 
 
409
 
410
- msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, msg])
 
 
 
 
 
411
  clear.click(lambda: None, None, chatbot, queue=False)
412
 
413
- timer = gr.Number(value=60, label="Time Remaining", every=1)
414
  timer.change(timer_update, inputs=[chatbot], outputs=[chatbot])
415
  demo.load(lambda: game_state["timer"], None, timer, every=1)
416
 
 
3
  import time
4
  import threading
5
 
6
+ # (Keep all the previous code for game_state, money_levels, timer_prompts, questions, and game logic functions)
 
 
 
 
 
 
 
 
 
7
 
8
+ # ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Modify the chat function to clear the input
11
  def chat(message, history):
12
  history = history or []
 
13
  bot_message = get_bot_response(message)
14
  history.append((message, bot_message))
15
  return history, ""
16
 
17
+ # Create the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
18
  with gr.Blocks() as demo:
19
  chatbot = gr.Chatbot()
20
+
21
+ with gr.Row():
22
+ msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
23
+ submit = gr.Button("Submit")
24
+
25
  clear = gr.Button("Clear")
26
+
27
+ timer = gr.Number(value=60, label="Time Remaining", every=1)
28
 
29
+ # Set up event handlers
30
+ submit_click = submit.click(chat, inputs=[msg, chatbot], outputs=[chatbot, msg], queue=False)
31
+ msg.submit(lambda x: "", inputs=[msg], outputs=[msg], queue=False)
32
+ msg.submit(lambda: gr.update(interactive=True), None, submit, queue=False)
33
+ submit.click(lambda: gr.update(interactive=True), None, submit, queue=False)
34
+
35
  clear.click(lambda: None, None, chatbot, queue=False)
36
 
 
37
  timer.change(timer_update, inputs=[chatbot], outputs=[chatbot])
38
  demo.load(lambda: game_state["timer"], None, timer, every=1)
39