test1978 commited on
Commit
12e583f
·
verified ·
1 Parent(s): 7393e61

create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import chess
3
+ import numpy as np
4
+ from huggingface_hub import hf_hub_download
5
+ import os
6
+
7
+ TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ # MODEL repo (model type)
10
+ model_repo = "test1978/chess-model"
11
+ model_path = hf_hub_download(model_repo, "chess_mcvs.py", repo_type="model", token=TOKEN)
12
+ with open(model_path, 'r', encoding='utf-8-sig') as f:
13
+ exec(f.read())
14
+
15
+ # DB dataset (dataset type!)
16
+ db_repo = "test1978/chess-data"
17
+ db_path = hf_hub_download(db_repo, "chess_zone_db.npz", repo_type="dataset", token=TOKEN)
18
+ zonedb_data = np.load(db_path, allow_pickle=True)
19
+
20
+ # Init YOUR zone DB
21
+ zonedb = HilbertOrderedZoneDatabase()
22
+ zonedb.winningmatrices = list(zonedb_data.get('winning', []))
23
+ zonedb.losingmatrices = list(zonedb_data.get('losing', []))
24
+ zonedb.drawmatrices = list(zonedb_data.get('draw', []))
25
+
26
+ def get_move(fen, player):
27
+ board = chess.Board(fen)
28
+ game = Chess()
29
+ game.board = board
30
+ searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5)
31
+ visits, _ = searcher.search_with_time_budget(game, 1.0)
32
+ best_move = max(visits, key=visits.get)
33
+ return best_move.uci()
34
+
35
+ demo = gr.Interface(
36
+ fn=get_move,
37
+ inputs=gr.Textbox(
38
+ label="FEN",
39
+ value="rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"
40
+ ),
41
+ outputs=gr.Textbox(label="UCI Move"),
42
+ title="🎯 ChessMCVS Secure (Model + Dataset)"
43
+ )
44
+ demo.launch()