Spaces:
Running
Running
File size: 952 Bytes
62d1307 89c95a7 62d1307 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import random
import gradio as gr
def determine_winner(player_choice, computer_choice):
if player_choice == computer_choice:
return "It's a tie!"
elif (player_choice == "rock" and computer_choice == "scissors") or \
(player_choice == "paper" and computer_choice == "rock") or \
(player_choice == "scissors" and computer_choice == "paper"):
return "You win!"
else:
return "Computer wins!"
def play_rps(player_choice):
choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)
result = determine_winner(player_choice, computer_choice)
return f"Computer chooses: {computer_choice}\n{result}"
iface = gr.Interface(
fn=play_rps,
inputs=gr.inputs.Dropdown(["rock", "paper", "scissors"]),
outputs="text",
title="Rock, Paper, Scissors!",
description="Enter your choice: rock, paper, or scissors",
theme=gr.themes.Soft(),
)
iface.launch() |