Sidharthan's picture
Update app.py
89c95a7
raw
history blame contribute delete
No virus
952 Bytes
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()