Spaces:
Running
Running
removed chess.Board
Browse files- app/attention_interface.py +3 -2
- app/backend_interface.py +4 -3
- app/board_interface.py +3 -2
- app/crp_interface.py +5 -3
- app/encoding_interface.py +4 -3
- app/lrp_interface.py +4 -3
- app/policy_interface.py +3 -1
app/attention_interface.py
CHANGED
@@ -7,6 +7,7 @@ import copy
|
|
7 |
import chess
|
8 |
import gradio as gr
|
9 |
|
|
|
10 |
from demo import constants, utils, visualisation
|
11 |
|
12 |
|
@@ -43,9 +44,9 @@ def compute_cache(
|
|
43 |
return None, None, None, state_boards, state_cache
|
44 |
|
45 |
try:
|
46 |
-
board =
|
47 |
except ValueError:
|
48 |
-
board =
|
49 |
gr.Warning("Invalid FEN, using starting position.")
|
50 |
state_boards = [board.copy()]
|
51 |
if action_seq:
|
|
|
7 |
import chess
|
8 |
import gradio as gr
|
9 |
|
10 |
+
from lczerolens.board import LczeroBoard
|
11 |
from demo import constants, utils, visualisation
|
12 |
|
13 |
|
|
|
44 |
return None, None, None, state_boards, state_cache
|
45 |
|
46 |
try:
|
47 |
+
board = LczeroBoard(board_fen)
|
48 |
except ValueError:
|
49 |
+
board = LczeroBoard()
|
50 |
gr.Warning("Invalid FEN, using starting position.")
|
51 |
state_boards = [board.copy()]
|
52 |
if action_seq:
|
app/backend_interface.py
CHANGED
@@ -12,6 +12,7 @@ from demo import constants, utils, visualisation
|
|
12 |
from lczerolens import move_encodings
|
13 |
from lczerolens.model import lczero as lczero_utils
|
14 |
from lczerolens.xai import PolicyLens
|
|
|
15 |
|
16 |
|
17 |
def list_models():
|
@@ -52,9 +53,9 @@ def make_policy_plot(
|
|
52 |
"",
|
53 |
)
|
54 |
try:
|
55 |
-
board =
|
56 |
except ValueError:
|
57 |
-
board =
|
58 |
gr.Warning("Invalid FEN, using starting position.")
|
59 |
if action_seq:
|
60 |
try:
|
@@ -62,7 +63,7 @@ def make_policy_plot(
|
|
62 |
board.push_uci(action)
|
63 |
except ValueError:
|
64 |
gr.Warning("Invalid action sequence, using starting position.")
|
65 |
-
board =
|
66 |
lczero_weights = Weights(f"{constants.LEELA_MODEL_DIRECTORY}/{model_name}")
|
67 |
lczero_backend = Backend(lczero_weights)
|
68 |
uci_moves = [move.uci() for move in board.move_stack]
|
|
|
12 |
from lczerolens import move_encodings
|
13 |
from lczerolens.model import lczero as lczero_utils
|
14 |
from lczerolens.xai import PolicyLens
|
15 |
+
from lczerolens.board import LczeroBoard
|
16 |
|
17 |
|
18 |
def list_models():
|
|
|
53 |
"",
|
54 |
)
|
55 |
try:
|
56 |
+
board = LczeroBoard(board_fen)
|
57 |
except ValueError:
|
58 |
+
board = LczeroBoard()
|
59 |
gr.Warning("Invalid FEN, using starting position.")
|
60 |
if action_seq:
|
61 |
try:
|
|
|
63 |
board.push_uci(action)
|
64 |
except ValueError:
|
65 |
gr.Warning("Invalid action sequence, using starting position.")
|
66 |
+
board = LczeroBoard()
|
67 |
lczero_weights = Weights(f"{constants.LEELA_MODEL_DIRECTORY}/{model_name}")
|
68 |
lczero_backend = Backend(lczero_weights)
|
69 |
uci_moves = [move.uci() for move in board.move_stack]
|
app/board_interface.py
CHANGED
@@ -6,13 +6,14 @@ import chess
|
|
6 |
import gradio as gr
|
7 |
|
8 |
from demo import constants
|
|
|
9 |
|
10 |
|
11 |
def make_board_plot(board_fen, arrows, square):
|
12 |
try:
|
13 |
-
board =
|
14 |
except ValueError:
|
15 |
-
board =
|
16 |
gr.Warning("Invalid FEN, using starting position.")
|
17 |
try:
|
18 |
if arrows:
|
|
|
6 |
import gradio as gr
|
7 |
|
8 |
from demo import constants
|
9 |
+
from lczerolens.board import LczeroBoard
|
10 |
|
11 |
|
12 |
def make_board_plot(board_fen, arrows, square):
|
13 |
try:
|
14 |
+
board = LczeroBoard(board_fen)
|
15 |
except ValueError:
|
16 |
+
board = LczeroBoard()
|
17 |
gr.Warning("Invalid FEN, using starting position.")
|
18 |
try:
|
19 |
if arrows:
|
app/crp_interface.py
CHANGED
@@ -8,6 +8,8 @@ import chess
|
|
8 |
import gradio as gr
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
|
|
|
|
11 |
|
12 |
cache = None
|
13 |
boards = None
|
@@ -44,9 +46,9 @@ def compute_cache(
|
|
44 |
gr.Warning("No model selected.")
|
45 |
return None, None, None, None, None
|
46 |
try:
|
47 |
-
board =
|
48 |
except ValueError:
|
49 |
-
board =
|
50 |
gr.Warning("Invalid FEN, using starting position.")
|
51 |
boards = [board.copy()]
|
52 |
if action_seq:
|
@@ -127,7 +129,7 @@ def make_history_plot(
|
|
127 |
if board.turn == chess.BLACK:
|
128 |
heatmap = heatmap.view(8, 8).flip(0).view(64)
|
129 |
if board_index - history_index + 1 < 0:
|
130 |
-
history_board =
|
131 |
else:
|
132 |
history_board = boards[board_index - history_index + 1]
|
133 |
svg_board, fig = visualisation.render_heatmap(history_board, heatmap, vmin=vmin, vmax=vmax)
|
|
|
8 |
import gradio as gr
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
11 |
+
from lczerolens.board import LczeroBoard
|
12 |
+
|
13 |
|
14 |
cache = None
|
15 |
boards = None
|
|
|
46 |
gr.Warning("No model selected.")
|
47 |
return None, None, None, None, None
|
48 |
try:
|
49 |
+
board = LczeroBoard(board_fen)
|
50 |
except ValueError:
|
51 |
+
board = LczeroBoard()
|
52 |
gr.Warning("Invalid FEN, using starting position.")
|
53 |
boards = [board.copy()]
|
54 |
if action_seq:
|
|
|
129 |
if board.turn == chess.BLACK:
|
130 |
heatmap = heatmap.view(8, 8).flip(0).view(64)
|
131 |
if board_index - history_index + 1 < 0:
|
132 |
+
history_board = LczeroBoard(fen=None)
|
133 |
else:
|
134 |
history_board = boards[board_index - history_index + 1]
|
135 |
svg_board, fig = visualisation.render_heatmap(history_board, heatmap, vmin=vmin, vmax=vmax)
|
app/encoding_interface.py
CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
|
|
7 |
|
8 |
from demo import constants, visualisation
|
9 |
from lczerolens import board_encodings
|
|
|
10 |
|
11 |
|
12 |
def make_encoding_plot(
|
@@ -16,9 +17,9 @@ def make_encoding_plot(
|
|
16 |
color_flip,
|
17 |
):
|
18 |
try:
|
19 |
-
board =
|
20 |
except ValueError:
|
21 |
-
board =
|
22 |
gr.Warning("Invalid FEN, using starting position.")
|
23 |
if action_seq:
|
24 |
try:
|
@@ -26,7 +27,7 @@ def make_encoding_plot(
|
|
26 |
board.push_uci(action)
|
27 |
except ValueError:
|
28 |
gr.Warning("Invalid action sequence, using starting position.")
|
29 |
-
board =
|
30 |
board_tensor = board_encodings.board_to_input_tensor(board)
|
31 |
heatmap = board_tensor[plane_index]
|
32 |
if color_flip and board.turn == chess.BLACK:
|
|
|
7 |
|
8 |
from demo import constants, visualisation
|
9 |
from lczerolens import board_encodings
|
10 |
+
from lczerolens.board import LczeroBoard
|
11 |
|
12 |
|
13 |
def make_encoding_plot(
|
|
|
17 |
color_flip,
|
18 |
):
|
19 |
try:
|
20 |
+
board = LczeroBoard(board_fen)
|
21 |
except ValueError:
|
22 |
+
board = LczeroBoard()
|
23 |
gr.Warning("Invalid FEN, using starting position.")
|
24 |
if action_seq:
|
25 |
try:
|
|
|
27 |
board.push_uci(action)
|
28 |
except ValueError:
|
29 |
gr.Warning("Invalid action sequence, using starting position.")
|
30 |
+
board = LczeroBoard()
|
31 |
board_tensor = board_encodings.board_to_input_tensor(board)
|
32 |
heatmap = board_tensor[plane_index]
|
33 |
if color_flip and board.turn == chess.BLACK:
|
app/lrp_interface.py
CHANGED
@@ -8,6 +8,7 @@ import chess
|
|
8 |
import gradio as gr
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
|
|
11 |
|
12 |
cache = None
|
13 |
boards = None
|
@@ -44,9 +45,9 @@ def compute_cache(
|
|
44 |
gr.Warning("No model selected.")
|
45 |
return None, None, None, None, None
|
46 |
try:
|
47 |
-
board =
|
48 |
except ValueError:
|
49 |
-
board =
|
50 |
gr.Warning("Invalid FEN, using starting position.")
|
51 |
boards = [board.copy()]
|
52 |
if action_seq:
|
@@ -127,7 +128,7 @@ def make_history_plot(
|
|
127 |
if board.turn == chess.BLACK:
|
128 |
heatmap = heatmap.view(8, 8).flip(0).view(64)
|
129 |
if board_index - history_index + 1 < 0:
|
130 |
-
history_board =
|
131 |
else:
|
132 |
history_board = boards[board_index - history_index + 1]
|
133 |
svg_board, fig = visualisation.render_heatmap(history_board, heatmap, vmin=vmin, vmax=vmax)
|
|
|
8 |
import gradio as gr
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
11 |
+
from lczerolens.board import LczeroBoard
|
12 |
|
13 |
cache = None
|
14 |
boards = None
|
|
|
45 |
gr.Warning("No model selected.")
|
46 |
return None, None, None, None, None
|
47 |
try:
|
48 |
+
board = LczeroBoard(board_fen)
|
49 |
except ValueError:
|
50 |
+
board = LczeroBoard()
|
51 |
gr.Warning("Invalid FEN, using starting position.")
|
52 |
boards = [board.copy()]
|
53 |
if action_seq:
|
|
|
128 |
if board.turn == chess.BLACK:
|
129 |
heatmap = heatmap.view(8, 8).flip(0).view(64)
|
130 |
if board_index - history_index + 1 < 0:
|
131 |
+
history_board = LczeroBoard(fen=None)
|
132 |
else:
|
133 |
history_board = boards[board_index - history_index + 1]
|
134 |
svg_board, fig = visualisation.render_heatmap(history_board, heatmap, vmin=vmin, vmax=vmax)
|
app/policy_interface.py
CHANGED
@@ -9,8 +9,10 @@ import torch
|
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
11 |
from lczerolens import move_encodings
|
|
|
12 |
from lczerolens.xai import PolicyLens
|
13 |
|
|
|
14 |
current_board = None
|
15 |
current_raw_policy = None
|
16 |
current_policy = None
|
@@ -55,7 +57,7 @@ def compute_policy(
|
|
55 |
"",
|
56 |
)
|
57 |
try:
|
58 |
-
board =
|
59 |
except ValueError:
|
60 |
gr.Warning("Invalid FEN.")
|
61 |
return (None, None, "", None)
|
|
|
9 |
|
10 |
from demo import constants, utils, visualisation
|
11 |
from lczerolens import move_encodings
|
12 |
+
from lczerolens.board import LczeroBoard
|
13 |
from lczerolens.xai import PolicyLens
|
14 |
|
15 |
+
|
16 |
current_board = None
|
17 |
current_raw_policy = None
|
18 |
current_policy = None
|
|
|
57 |
"",
|
58 |
)
|
59 |
try:
|
60 |
+
board = LczeroBoard(board_fen)
|
61 |
except ValueError:
|
62 |
gr.Warning("Invalid FEN.")
|
63 |
return (None, None, "", None)
|