valentin urena commited on
Commit
afaee35
·
verified ·
1 Parent(s): e6ecbb2

Update chess_board.py

Browse files
Files changed (1) hide show
  1. chess_board.py +8 -5
chess_board.py CHANGED
@@ -8,8 +8,11 @@ class Game:
8
  self.board = chess.Board()
9
  self.sequence = []
10
  self.counter = 0
 
 
 
11
 
12
- def call_gemma(self, model):
13
  template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
14
 
15
 
@@ -17,7 +20,7 @@ class Game:
17
  instruction=f"Predict the next chess move in the sequence {str(self.sequence)}",
18
  response="",)
19
 
20
- output = model.generate(prompt, max_length=max_output_len)
21
 
22
  gemma_move = output.split(' ')[-1].strip("'")
23
 
@@ -35,10 +38,10 @@ class Game:
35
  print("Gemma quit...")
36
  return None
37
 
38
- def gemma_moves(self, model):
39
  print(f"Gemma is thinking...(Current Sequence: {self.sequence} {len(self.sequence)})")
40
  time.sleep(3)
41
- return self.call_gemma(model)
42
 
43
  def player_moves(self, move):
44
  return self.make_move(move)
@@ -68,7 +71,7 @@ class Game:
68
  # self.board.reset
69
  return self.display_board()
70
 
71
- def generate_moves(self, move, model):
72
  yield self.player_moves(move)
73
  yield self.gemma_moves(model)
74
 
 
8
  self.board = chess.Board()
9
  self.sequence = []
10
  self.counter = 0
11
+ self.model_id = 'kaggle://valentinbaltazar/gemma-chess/keras/gemma_2b_en_chess'
12
+ self.model = keras_nlp.models.GemmaCausalLM.from_preset(self.model_id)
13
+
14
 
15
+ def call_gemma(self):
16
  template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
17
 
18
 
 
20
  instruction=f"Predict the next chess move in the sequence {str(self.sequence)}",
21
  response="",)
22
 
23
+ output = self.model.generate(prompt, max_length=max_output_len)
24
 
25
  gemma_move = output.split(' ')[-1].strip("'")
26
 
 
38
  print("Gemma quit...")
39
  return None
40
 
41
+ def gemma_moves(self):
42
  print(f"Gemma is thinking...(Current Sequence: {self.sequence} {len(self.sequence)})")
43
  time.sleep(3)
44
+ return self.call_gemma()
45
 
46
  def player_moves(self, move):
47
  return self.make_move(move)
 
71
  # self.board.reset
72
  return self.display_board()
73
 
74
+ def generate_moves(self, move):
75
  yield self.player_moves(move)
76
  yield self.gemma_moves(model)
77