Spaces:
Sleeping
Sleeping
File size: 1,399 Bytes
7c56311 49fde22 ffa185b 7c56311 a186b64 144f0ae 268b13e 7946a6c 268b13e 414175d 49fde22 b122407 268b13e 49fde22 7946a6c b122407 ffa185b 49fde22 144f0ae ffa185b 144f0ae b122407 144f0ae 604589b ce2af8c 49fde22 7c56311 7946a6c 268b13e 7946a6c | 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 | 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 = "typical-cyber/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 = "typical-cyber/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() |