Xmaster6y's picture
new working demo
3333fb8
"""
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)