Spaces:
Sleeping
Sleeping
Sidharthan
commited on
Commit
•
62d1307
1
Parent(s):
caf40f4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def determine_winner(player_choice, computer_choice):
|
6 |
+
if player_choice == computer_choice:
|
7 |
+
return "It's a tie!"
|
8 |
+
elif (player_choice == "rock" and computer_choice == "scissors") or \
|
9 |
+
(player_choice == "paper" and computer_choice == "rock") or \
|
10 |
+
(player_choice == "scissors" and computer_choice == "paper"):
|
11 |
+
return "You win!"
|
12 |
+
else:
|
13 |
+
return "Computer wins!"
|
14 |
+
|
15 |
+
def play_rps(player_choice):
|
16 |
+
choices = ["rock", "paper", "scissors"]
|
17 |
+
computer_choice = random.choice(choices)
|
18 |
+
result = determine_winner(player_choice, computer_choice)
|
19 |
+
return f"Computer chooses: {computer_choice}\n{result}"
|
20 |
+
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=play_rps,
|
24 |
+
inputs=gr.inputs.Dropdown(["rock", "paper", "scissors"]),
|
25 |
+
outputs="text",
|
26 |
+
title="Rock, Paper, Scissors!",
|
27 |
+
description="Enter your choice: rock, paper, or scissors",
|
28 |
+
theme=gr.themes.Monochrome(),
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|