File size: 1,389 Bytes
12e583f
6126d56
12e583f
 
 
 
 
 
6126d56
e444b0c
6126d56
 
 
12e583f
6126d56
e444b0c
6126d56
12e583f
 
6126d56
 
 
 
 
 
 
 
 
 
 
 
 
 
12e583f
 
 
6126d56
 
 
 
 
 
12e583f
 
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 = "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()