Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| import time | |
| choices = ["Rock", "Paper", "Scissors"] | |
| emoji_map = {"Rock": "โ", "Paper": "โ", "Scissors": "โ๏ธ"} | |
| def play_rps_animated(user_choice): | |
| # Simulate countdown | |
| countdown = "Rock... โ\n" | |
| time.sleep(0.5) | |
| countdown += "Paper... โ\n" | |
| time.sleep(0.5) | |
| countdown += "Scissors... โ๏ธ\n" | |
| time.sleep(0.5) | |
| countdown += "Shoot!\n\n" | |
| bot_choice = random.choice(choices) | |
| if user_choice == bot_choice: | |
| result = "It's a draw!" | |
| elif ( | |
| (user_choice == "Rock" and bot_choice == "Scissors") or | |
| (user_choice == "Paper" and bot_choice == "Rock") or | |
| (user_choice == "Scissors" and bot_choice == "Paper") | |
| ): | |
| result = "You win! ๐" | |
| else: | |
| result = "You lose ๐ข" | |
| return countdown + f"You chose: {user_choice} {emoji_map[user_choice]}\n" \ | |
| f"Bot chose: {bot_choice} {emoji_map[bot_choice]}\n\n" + result | |
| iface = gr.Interface( | |
| fn=play_rps_animated, | |
| inputs=gr.Radio(choices, label="Choose your move"), | |
| outputs="text", | |
| title="๐ฎ Rock-Paper-Scissors with Animation", | |
| description="Play against a bot with animated countdown!" | |
| ) | |
| iface.launch() | |