Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,6 @@ board_split = ' | '
|
|
16 |
nums = {str(n): empty_field * n for n in range(1, 9)}
|
17 |
nums_rev = {v:k for k,v in reversed(nums.items())}
|
18 |
|
19 |
-
board = chess.Board()
|
20 |
|
21 |
def encode_fen(fen):
|
22 |
# decompress fen representation
|
@@ -45,19 +44,17 @@ def predict_move(fen, top_k=3):
|
|
45 |
return p['label']
|
46 |
|
47 |
def btn_load(inp_fen):
|
48 |
-
global board
|
49 |
-
|
50 |
if inp_fen:
|
51 |
board = chess.Board(inp_fen)
|
52 |
else:
|
53 |
-
board.
|
54 |
|
55 |
with open('board.svg', 'w') as f:
|
56 |
f.write(str(chess.svg.board(board)))
|
57 |
return 'board.svg', board.fen()
|
58 |
|
59 |
-
def btn_play(inp_move, inp_notation):
|
60 |
-
|
61 |
|
62 |
if inp_move:
|
63 |
if inp_notation == 'UCI': mv = chess.Move.from_uci(inp_move) #board.push_uci(inp_move)
|
@@ -73,12 +70,17 @@ def btn_play(inp_move, inp_notation):
|
|
73 |
return 'board.svg', board.fen(), ''
|
74 |
|
75 |
with gr.Blocks() as block:
|
76 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
77 |
with gr.Row() as row:
|
78 |
with gr.Column():
|
79 |
move = gr.Textbox(label='human player move')
|
80 |
notation = gr.Radio(["SAN", "UCI"], value="SAN", label='move notation')
|
81 |
-
fen = gr.Textbox(
|
82 |
with gr.Row():
|
83 |
load_btn = gr.Button("Load")
|
84 |
play_btn = gr.Button("Play")
|
@@ -86,7 +88,7 @@ with gr.Blocks() as block:
|
|
86 |
position_output = gr.Image(label='board')
|
87 |
|
88 |
load_btn.click(fn=btn_load, inputs=fen, outputs=[position_output, fen])
|
89 |
-
play_btn.click(fn=btn_play, inputs=[move, notation], outputs=[position_output, fen, move])
|
90 |
|
91 |
gr.Markdown(
|
92 |
'''
|
|
|
16 |
nums = {str(n): empty_field * n for n in range(1, 9)}
|
17 |
nums_rev = {v:k for k,v in reversed(nums.items())}
|
18 |
|
|
|
19 |
|
20 |
def encode_fen(fen):
|
21 |
# decompress fen representation
|
|
|
44 |
return p['label']
|
45 |
|
46 |
def btn_load(inp_fen):
|
|
|
|
|
47 |
if inp_fen:
|
48 |
board = chess.Board(inp_fen)
|
49 |
else:
|
50 |
+
board = chess.Board()
|
51 |
|
52 |
with open('board.svg', 'w') as f:
|
53 |
f.write(str(chess.svg.board(board)))
|
54 |
return 'board.svg', board.fen()
|
55 |
|
56 |
+
def btn_play(inp_fen, inp_move, inp_notation):
|
57 |
+
board = chess.Board(inp_fen)
|
58 |
|
59 |
if inp_move:
|
60 |
if inp_notation == 'UCI': mv = chess.Move.from_uci(inp_move) #board.push_uci(inp_move)
|
|
|
70 |
return 'board.svg', board.fen(), ''
|
71 |
|
72 |
with gr.Blocks() as block:
|
73 |
+
gr.Markdown(
|
74 |
+
'''
|
75 |
+
# Play YoloChess - Policy Network v0.3
|
76 |
+
110M Parameter Transformer (BERT-base architecture) trained for text classification from scratch on expert games in FEN notation.
|
77 |
+
'''
|
78 |
+
)
|
79 |
with gr.Row() as row:
|
80 |
with gr.Column():
|
81 |
move = gr.Textbox(label='human player move')
|
82 |
notation = gr.Radio(["SAN", "UCI"], value="SAN", label='move notation')
|
83 |
+
fen = gr.Textbox(value=chess.Board().fen(), label='FEN')
|
84 |
with gr.Row():
|
85 |
load_btn = gr.Button("Load")
|
86 |
play_btn = gr.Button("Play")
|
|
|
88 |
position_output = gr.Image(label='board')
|
89 |
|
90 |
load_btn.click(fn=btn_load, inputs=fen, outputs=[position_output, fen])
|
91 |
+
play_btn.click(fn=btn_play, inputs=[fen, move, notation], outputs=[position_output, fen, move])
|
92 |
|
93 |
gr.Markdown(
|
94 |
'''
|