Spaces:
Running
Running
| import gradio as gr | |
| import chess | |
| import numpy as np | |
| from huggingface_hub import hf_hub_download | |
| import os | |
| TOKEN = os.environ.get("HF_TOKEN") | |
| # MODEL repo (model type) | |
| model_repo = "test1978/chess-model" | |
| model_path = hf_hub_download(model_repo, "chess_mcvs.py", repo_type="model", token=TOKEN) | |
| with open(model_path, 'r', encoding='utf-8-sig') as f: | |
| exec(f.read()) | |
| # DB dataset (dataset type!) | |
| db_repo = "test1978/chess-data" | |
| db_path = hf_hub_download(db_repo, "chess_zone_db.npz", repo_type="dataset", token=TOKEN) | |
| zonedb_data = np.load(db_path, allow_pickle=True) | |
| # Init YOUR zone DB | |
| zonedb = HilbertOrderedZoneDatabase() | |
| zonedb.winningmatrices = list(zonedb_data.get('winning', [])) | |
| zonedb.losingmatrices = list(zonedb_data.get('losing', [])) | |
| zonedb.drawmatrices = list(zonedb_data.get('draw', [])) | |
| def get_move(fen, player): | |
| board = chess.Board(fen) | |
| game = Chess() | |
| game.board = board | |
| searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5) | |
| visits, _ = searcher.search_with_time_budget(game, 1.0) | |
| best_move = max(visits, key=visits.get) | |
| return best_move.uci() | |
| demo = gr.Interface( | |
| fn=get_move, | |
| inputs=gr.Textbox( | |
| label="FEN", | |
| value="rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1" | |
| ), | |
| outputs=gr.Textbox(label="UCI Move"), | |
| title="🎯 ChessMCVS Secure (Model + Dataset)" | |
| ) | |
| demo.launch() |