File size: 2,100 Bytes
733503a 8c04be1 f32fa0d 5a0aa97 f32fa0d 0b736b3 8c04be1 733503a 0b736b3 8c04be1 733503a 8c04be1 733503a 8c04be1 9766013 0b736b3 8c04be1 0b736b3 bff82b2 f32fa0d bff82b2 0b736b3 9766013 733503a 0b736b3 5a0aa97 8c04be1 0b736b3 5a0aa97 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import gradio as gr
import random
# 🌟 Initialize scores globally
player_score = 0
computer_score = 0
def reset_scores():
global player_score, computer_score
player_score = 0
computer_score = 0
return "🔄 Scores have been reset to 0-0."
def play(user_choice):
global player_score, computer_score
choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)
# Determine result
if user_choice == computer_choice:
result = "It's a tie!"
elif (user_choice == "rock" and computer_choice == "scissors") or \
(user_choice == "paper" and computer_choice == "rock") or \
(user_choice == "scissors" and computer_choice == "paper"):
result = "You Win!"
player_score += 1
else:
result = "You Lose!"
computer_score += 1
return (f"✊ You chose: {user_choice}\n"
f"💻 Computer chose: {computer_choice}\n"
f"🎯 Result: {result}\n\n"
f"📊 Scores => Player: {player_score} | Computer: {computer_score}")
with gr.Blocks(css="""
body {
background: url('https://img.freepik.com/free-vector/children-playing-rock-paper-scissors_1308-33220.jpg') no-repeat center center fixed;
background-size: cover;
}
.gradio-container {
background-color: rgba(255, 255, 255, 0.85);
border-radius: 15px;
padding: 20px;
max-width: 400px;
margin: auto;
margin-top: 50px;
}
h1, h2, h3 {
color: black;
text-align: center;
}
""") as demo:
gr.Markdown("## ✊ ✋ ✌️ Rock Paper Scissors Game")
with gr.Row():
with gr.Column():
user_choice = gr.Radio(["rock", "paper", "scissors"], label="Choose Rock, Paper, or Scissors")
play_button = gr.Button("Submit")
reset_button = gr.Button("Reset Scores", variant="stop")
output = gr.Textbox(label="output", lines=6)
play_button.click(fn=play, inputs=user_choice, outputs=output)
reset_button.click(fn=reset_scores, inputs=None, outputs=output)
demo.launch(share=True) |