Inkcap commited on
Commit
0108cbe
β€’
1 Parent(s): 6ed1bf3

Testing early streamlit display in game_database

Browse files
app.py CHANGED
@@ -1,8 +1,12 @@
 
1
  import chess
2
  import random
3
  import streamlit as st
4
  from transformers import pipeline
5
 
 
 
 
6
  generator2 = pipeline('text-generation', model='BlueSunflower/gpt2-medium-chess')
7
  generator = pipeline('text-generation', model='gpt2')
8
 
@@ -77,7 +81,7 @@ class AInstance:
77
  def check_if_end(self):
78
  return self.game_end
79
 
80
- def verify_move(string):
81
  board = chess.Board()
82
  st.write("Board: " + string)
83
  for move in string.split():
@@ -92,7 +96,7 @@ def verify_move(string):
92
  return True
93
  return False
94
 
95
- def check_mate(string):
96
  #simulates mate idk
97
  if(random.randrange(0,100) == 4):
98
  st.write("H")
@@ -117,24 +121,40 @@ def make_move(instance, game_state):
117
 
118
 
119
  def main():
 
 
 
 
120
  if(random.randrange(0,1)):
121
- white = AInstance("gpt2", generator)
122
- black = AInstance("gpt2-medium-chess", generator2)
123
  st.write("Gpt2 is White and Gpt2 Optimized is Black")
124
  else:
125
- white = AInstance("gpt2-medium-chess", generator2)
126
- black = AInstance("gpt2", generator)
127
  st.write("Gpt2 is Black and Gpt2 Optimized is White")
128
 
 
 
129
  game_state = "e4 e5"
130
  game_ongoing = True
131
  while game_ongoing:
132
  game_state, game_ongoing = make_move(white, game_state)
 
133
  if not game_ongoing:
134
- print_game(game_state)
135
  break
136
  game_state, game_ongoing = make_move(black, game_state)
 
137
  if not game_ongoing:
138
- print_game(game_state)
139
  break
140
- main()
 
 
 
 
 
 
 
 
 
1
+
2
  import chess
3
  import random
4
  import streamlit as st
5
  from transformers import pipeline
6
 
7
+ from game_database import GameDatabase
8
+ from logger import Logger
9
+
10
  generator2 = pipeline('text-generation', model='BlueSunflower/gpt2-medium-chess')
11
  generator = pipeline('text-generation', model='gpt2')
12
 
 
81
  def check_if_end(self):
82
  return self.game_end
83
 
84
+ def verify_move(string): #Given all moves so far, this checks if any moves are illegal.
85
  board = chess.Board()
86
  st.write("Board: " + string)
87
  for move in string.split():
 
96
  return True
97
  return False
98
 
99
+ def check_mate(string): #Am confusion
100
  #simulates mate idk
101
  if(random.randrange(0,100) == 4):
102
  st.write("H")
 
121
 
122
 
123
  def main():
124
+
125
+ player_1 = "gpt2"
126
+ player_2 = "gpt2-medium-chess"
127
+
128
  if(random.randrange(0,1)):
129
+ white = AInstance(player_1, generator)
130
+ black = AInstance(player_2, generator2)
131
  st.write("Gpt2 is White and Gpt2 Optimized is Black")
132
  else:
133
+ white = AInstance(player_2, generator2)
134
+ black = AInstance(player_1, generator)
135
  st.write("Gpt2 is Black and Gpt2 Optimized is White")
136
 
137
+ onetime_logger = Logger(white.type, black.type) #Logger.model_1 should be white and vice versa
138
+
139
  game_state = "e4 e5"
140
  game_ongoing = True
141
  while game_ongoing:
142
  game_state, game_ongoing = make_move(white, game_state)
143
+ onetime_logger.add_legal_move(game_state)
144
  if not game_ongoing:
145
+ #print_game(game_state)
146
  break
147
  game_state, game_ongoing = make_move(black, game_state)
148
+ onetime_logger.add_legal_move(game_state)
149
  if not game_ongoing:
150
+ #print_game(game_state)
151
  break
152
+
153
+ finished_game = onetime_logger.return_formatted_game()
154
+ onetime_db = GameDatabase()
155
+ onetime_db.add_game(finished_game)
156
+ onetime_db.display_tournament
157
+
158
+ onetime_db.display_tournament()
159
+ if __name__ == "__main__":
160
+ main()
src/game_database.py β†’ game_database.py RENAMED
@@ -1,6 +1,7 @@
1
  import chess
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
 
4
  from typing import Dict
5
  from logger import Logger
6
 
@@ -23,9 +24,16 @@ class GameDatabase:
23
  #bar chart of tournament winrates
24
  win_results = df["Winner"].value_counts()
25
  print(win_results.rank())
26
- win_results.plot.bar()
27
- plt.show()
28
- pass
 
 
 
 
 
 
 
29
 
30
  if __name__ == "__main__":
31
  test_logger = Logger("ChessGPT", "ChatGPT")
 
1
  import chess
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
4
+ import streamlit as st
5
  from typing import Dict
6
  from logger import Logger
7
 
 
24
  #bar chart of tournament winrates
25
  win_results = df["Winner"].value_counts()
26
  print(win_results.rank())
27
+
28
+ names = ["steve", "bob", "emily"]
29
+ nums = [1,2,3]
30
+
31
+ fig, axs = plt.subplots(2,1)
32
+ axs[0].plot(names, nums)
33
+ axs[1].bar(names, nums)
34
+ st.pyplot(fig)
35
+
36
+
37
 
38
  if __name__ == "__main__":
39
  test_logger = Logger("ChessGPT", "ChatGPT")
src/interface.py β†’ interface.py RENAMED
File without changes
src/interface_experiment.py β†’ interface_experiment.py RENAMED
File without changes
src/logger.py β†’ logger.py RENAMED
File without changes