Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
|
|
3 |
|
4 |
choices = ["Rock", "Paper", "Scissors"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def play_rps(user_choice):
|
7 |
bot_choice = random.choice(choices)
|
8 |
-
result = ""
|
9 |
|
10 |
if user_choice == bot_choice:
|
11 |
result = "It's a draw!"
|
@@ -18,15 +28,15 @@ def play_rps(user_choice):
|
|
18 |
else:
|
19 |
result = "You lose ๐ข"
|
20 |
|
21 |
-
return f"You chose: {user_choice}
|
|
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
-
fn=
|
25 |
inputs=gr.Radio(choices, label="Choose your move"),
|
26 |
outputs="text",
|
27 |
-
title="Rock-Paper-Scissors
|
28 |
-
description="Play against a bot
|
29 |
)
|
30 |
|
31 |
iface.launch()
|
32 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
+
import time
|
4 |
|
5 |
choices = ["Rock", "Paper", "Scissors"]
|
6 |
+
emoji_map = {"Rock": "โ", "Paper": "โ", "Scissors": "โ๏ธ"}
|
7 |
+
|
8 |
+
def play_rps_animated(user_choice):
|
9 |
+
# Simulate countdown
|
10 |
+
countdown = "Rock... โ\n"
|
11 |
+
time.sleep(0.5)
|
12 |
+
countdown += "Paper... โ\n"
|
13 |
+
time.sleep(0.5)
|
14 |
+
countdown += "Scissors... โ๏ธ\n"
|
15 |
+
time.sleep(0.5)
|
16 |
+
countdown += "Shoot!\n\n"
|
17 |
|
|
|
18 |
bot_choice = random.choice(choices)
|
|
|
19 |
|
20 |
if user_choice == bot_choice:
|
21 |
result = "It's a draw!"
|
|
|
28 |
else:
|
29 |
result = "You lose ๐ข"
|
30 |
|
31 |
+
return countdown + f"You chose: {user_choice} {emoji_map[user_choice]}\n" \
|
32 |
+
f"Bot chose: {bot_choice} {emoji_map[bot_choice]}\n\n" + result
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
+
fn=play_rps_animated,
|
36 |
inputs=gr.Radio(choices, label="Choose your move"),
|
37 |
outputs="text",
|
38 |
+
title="๐ฎ Rock-Paper-Scissors with Animation",
|
39 |
+
description="Play against a bot with animated countdown!"
|
40 |
)
|
41 |
|
42 |
iface.launch()
|
|