superlazycoder commited on
Commit
29c9f6c
·
verified ·
1 Parent(s): 67e5d1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -1,10 +1,13 @@
1
  import streamlit as st
2
  import random
3
  import google.generativeai as genai
 
4
 
5
- GOOGLE_API_KEY = "api"
6
  genai.configure(api_key=GOOGLE_API_KEY)
7
 
 
 
8
  # Define the moves
9
  moves = ["Rock", "Paper", "Scissors"]
10
 
@@ -45,10 +48,22 @@ if 'player_move' not in st.session_state:
45
  if 'player_move' in locals():
46
  st.session_state.player_move = player_move
47
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # If a move is selected, randomly choose a move for the computer and determine the result
49
  if st.session_state.player_move:
50
  player_move = st.session_state.player_move
51
- computer_move = random.choice(moves)
52
 
53
  # Display player and computer moves
54
  col1, col2 = st.columns(2)
 
1
  import streamlit as st
2
  import random
3
  import google.generativeai as genai
4
+ import os
5
 
6
+ GOOGLE_API_KEY = os.getenv("Gemini")
7
  genai.configure(api_key=GOOGLE_API_KEY)
8
 
9
+ model = genai.GenerativeModel('gemini-pro')
10
+
11
  # Define the moves
12
  moves = ["Rock", "Paper", "Scissors"]
13
 
 
48
  if 'player_move' in locals():
49
  st.session_state.player_move = player_move
50
 
51
+ if "chat" not in st.session_state:
52
+ st.session_state.chat = model.start_chat(history = [
53
+ {
54
+ role: "user",
55
+ 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."
56
+ },
57
+ {
58
+ role: "model",
59
+ parts: "Alright, let's play a random Rock-Paper-Scissors game. Make your first move!"
60
+ }
61
+ ])
62
+
63
  # If a move is selected, randomly choose a move for the computer and determine the result
64
  if st.session_state.player_move:
65
  player_move = st.session_state.player_move
66
+ computer_move = st.session_state.chat.send_message(player_move)
67
 
68
  # Display player and computer moves
69
  col1, col2 = st.columns(2)