Spaces:
Running
Running
import gradio as gr | |
import random | |
choices = ["Rock", "Paper", "Scissors"] | |
def play_rps(user_choice): | |
bot_choice = random.choice(choices) | |
result = "" | |
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 f"You chose: {user_choice}\nBot chose: {bot_choice}\n\n{result}" | |
iface = gr.Interface( | |
fn=play_rps, | |
inputs=gr.Radio(choices, label="Choose your move"), | |
outputs="text", | |
title="Rock-Paper-Scissors Game", | |
description="Play against a bot. Make your move!" | |
) | |
iface.launch() | |