import gradio as gr import chess.pgn from io import StringIO from chess_puzzler import Generator, open_engine from chess_puzzler.tagger import cook def find_puzzles(pgn_text): game = chess.pgn.read_game(StringIO(pgn_text)) if not game: return None engine = open_engine("/usr/games/stockfish", threads=2) try: puzzle = Generator(engine).analyze_game(game, tier=10) if not puzzle: return None puzzle.tags = cook(puzzle) return puzzle.to_dict() finally: engine.close() gr.Interface( fn=find_puzzles, inputs=gr.Textbox(label="Paste PGN", lines=10), outputs=gr.JSON(label="Puzzle"), ).launch()