File size: 2,426 Bytes
b1d7433
 
67e5d1d
29c9f6c
67e5d1d
29c9f6c
67e5d1d
b1d7433
29c9f6c
 
b1d7433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e32478e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29c9f6c
 
 
74f6b10
 
29c9f6c
 
74f6b10
 
29c9f6c
 
 
e32478e
 
 
29c9f6c
b1d7433
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamlit as st
import random
import google.generativeai as genai
import os

GOOGLE_API_KEY = os.getenv("Gemini")
genai.configure(api_key=GOOGLE_API_KEY)

model = genai.GenerativeModel('gemini-pro')

# Define the moves
moves = ["Rock", "Paper", "Scissors"]

# Function to determine the winner
def determine_winner(player_move, computer_move):
    if player_move == computer_move:
        return "It's a tie!"
    elif (player_move == "Rock" and computer_move == "Scissors") or \
         (player_move == "Paper" and computer_move == "Rock") or \
         (player_move == "Scissors" and computer_move == "Paper"):
        return "You win!"
    else:
        return "You lose!"

# Streamlit app
st.title("Rock, Paper, Scissors")

st.write("Choose your move:")

# Create three horizontal buttons
col1, col2, col3 = st.columns(3)

with col1:
    if st.button("Rock"):
        player_move = "Rock"
with col2:
    if st.button("Paper"):
        player_move = "Paper"
with col3:
    if st.button("Scissors"):
        player_move = "Scissors"

# Ensure player_move is defined
if 'player_move' not in st.session_state:
    st.session_state.player_move = None

# Assign player move to session state if a move is made
if 'player_move' in locals():
    st.session_state.player_move = player_move

if "chat" not in st.session_state:
    st.session_state.chat = model.start_chat(history = [
        {
            role: 'user',
            parts: 'You are playing a random rock paper scissor game. For rock will say "Rock", for paper will say "Paper" and for scissor will say "Scissor".  Pick a random word out of three and reply once I do my move.'
        },
        {
            role: 'model',
            parts: 'Alright, let's play a random Rock-Paper-Scissors game. Make your first move!''
        }
    ])
    
# If a move is selected, randomly choose a move for the computer and determine the result
if st.session_state.player_move:
    player_move = st.session_state.player_move
    computer_move = st.session_state.chat.send_message(player_move)
    
    # Display player and computer moves
    col1, col2 = st.columns(2)
    with col1:
        st.write("Your move:")
        st.subheader(player_move)
    with col2:
        st.write("Computer's move:")
        st.subheader(computer_move)
    
    # Display result
    result = determine_winner(player_move, computer_move)
    st.write("Result:")
    st.subheader(result)