test1978 commited on
Commit
b9b7dad
·
verified ·
1 Parent(s): 5596bd4

create app.py

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