test1978 commited on
Commit
1f37b1b
·
verified ·
1 Parent(s): 5caeb77

update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -2,12 +2,13 @@ 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
 
9
  # MODEL repo (model type)
10
- model_repo = "test1978/breakthrough-model"
11
  model_path = hf_hub_download(
12
  model_repo,
13
  "breakthrough_mcvs.py",
@@ -19,7 +20,7 @@ with open(model_path, "r", encoding="utf-8-sig") as f:
19
 
20
 
21
  # DB dataset (dataset type!)
22
- db_repo = "test1978/breakthrough-data"
23
  db_path = hf_hub_download(
24
  db_repo,
25
  "breakthrough_zone_db.npz",
@@ -60,14 +61,26 @@ def move_to_uci(move):
60
 
61
 
62
  def get_move(board_text, player):
63
- game = Breakthrough()
64
- game.board = parse_board(board_text)
65
- game.move_count = 0 if str(player) == "1" else 1
66
- game._cached_matrix = None
67
- searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5)
68
- visits, _ = searcher.search_with_time_budget(game, 1.0)
69
- best_move = max(visits, key=visits.get)
70
- return move_to_uci(best_move)
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  demo = gr.Interface(
73
  fn=get_move,
 
2
  import numpy as np
3
  from huggingface_hub import hf_hub_download
4
  import os
5
+ import traceback
6
 
7
  TOKEN = os.environ.get("HF_TOKEN")
8
 
9
 
10
  # MODEL repo (model type)
11
+ model_repo = "typical-cyber/breakthrough-model"
12
  model_path = hf_hub_download(
13
  model_repo,
14
  "breakthrough_mcvs.py",
 
20
 
21
 
22
  # DB dataset (dataset type!)
23
+ db_repo = "typical-cyber/breakthrough-data"
24
  db_path = hf_hub_download(
25
  db_repo,
26
  "breakthrough_zone_db.npz",
 
61
 
62
 
63
  def get_move(board_text, player):
64
+ try:
65
+ game = Breakthrough()
66
+ game.board = parse_board(board_text)
67
+ game.move_count = 0 if str(player) == "1" else 1
68
+ game._cached_matrix = None
69
+
70
+ searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5)
71
+ visits, _ = searcher.search_with_time_budget(game, 1.0)
72
+
73
+ best_move = max(visits, key=visits.get)
74
+ result = move_to_uci(best_move)
75
+
76
+ print(f"[DEBUG] get_move OK: board={board_text} player={player} -> {result}")
77
+ return result
78
+
79
+ except Exception as exc:
80
+ print(f"[ERROR] get_move failed: {exc}")
81
+ traceback.print_exc()
82
+ # Return a dummy move so Gradio at least sends something
83
+ return "a1a2"
84
 
85
  demo = gr.Interface(
86
  fn=get_move,