Spaces:
Running
Running
File size: 1,584 Bytes
343fa36 3333fb8 343fa36 5e4365f 343fa36 3333fb8 343fa36 5e4365f 343fa36 5e4365f 343fa36 3333fb8 343fa36 3333fb8 343fa36 3333fb8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
"""
Gradio interface for plotting a board.
"""
import chess
import chess.svg
import gradio as gr
from lczerolens.board import LczeroBoard
from ..utils import create_board_figure
def make_board_plot(board_fen, arrows, square):
try:
board = LczeroBoard(board_fen)
except ValueError:
board = LczeroBoard()
gr.Warning("Invalid FEN, using starting position.")
filepath = create_board_figure(board, arrows=arrows, square=square, name="board")
return filepath
with gr.Blocks() as interface:
with gr.Row():
with gr.Column():
board_fen = gr.Textbox(
label="Board starting FEN",
lines=1,
max_lines=1,
value=chess.STARTING_FEN,
)
arrows = gr.Textbox(
label="Arrows",
lines=1,
max_lines=1,
value="",
placeholder="e2e4 e7e5",
)
square = gr.Textbox(
label="Square",
lines=1,
max_lines=1,
value="",
placeholder="e4",
)
with gr.Column():
image = gr.Image(label="Board", interactive=False)
inputs = [
board_fen,
arrows,
square,
]
interface.load(make_board_plot, inputs=inputs, outputs=image)
board_fen.submit(make_board_plot, inputs=inputs, outputs=image)
arrows.submit(make_board_plot, inputs=inputs, outputs=image)
square.submit(make_board_plot, inputs=inputs, outputs=image)
|