Narendra9009 commited on
Commit
e647ee0
·
verified ·
1 Parent(s): bf3c282

instead of reversing the array, the indices are changed in the get coordinate funciton

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -11,8 +11,8 @@ FEN_MAPPING = {
11
  "black-pawn": "p", "black-rook": "r", "black-knight": "n", "black-bishop": "b", "black-queen": "q", "black-king": "k",
12
  "white-pawn": "P", "white-rook": "R", "white-knight": "N", "white-bishop": "B", "white-queen": "Q", "white-king": "K"
13
  }
14
- GRID_BORDER = 10 # Border size in pixels
15
- GRID_SIZE = 204 # Effective grid size (10px to 214px)
16
  BLOCK_SIZE = GRID_SIZE // 8 # Each block is ~25px
17
  X_LABELS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # Labels for x-axis (a to h)
18
  Y_LABELS = [8, 7, 6, 5, 4, 3, 2, 1] # Reversed labels for y-axis (8 to 1)
@@ -25,8 +25,8 @@ def get_grid_coordinate(pixel_x, pixel_y, perspective):
25
  The perspective argument can adjust for white ('w') or black ('b') viewpoint.
26
  """
27
  # Grid settings
28
- border = 10 # 10px border
29
- grid_size = 204 # Effective grid size (10px to 214px)
30
  block_size = grid_size // 8 # Each block is ~25px
31
 
32
  x_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # Labels for x-axis (a to h)
@@ -49,13 +49,13 @@ def get_grid_coordinate(pixel_x, pixel_y, perspective):
49
 
50
  # Adjust labels based on perspective
51
  if perspective == "b":
52
- x_labels = x_labels[::-1] # Flip x-axis for black's perspective
53
- y_labels = y_labels[::-1] # Flip y-axis for black's perspective
54
 
55
- x_label = x_labels[x_index]
56
- y_label = y_labels[y_index]
57
 
58
- return f"{x_label}{y_label}"
59
 
60
 
61
  def predict_next_move(fen, stockfish):
@@ -72,11 +72,6 @@ def predict_next_move(fen, stockfish):
72
 
73
 
74
 
75
-
76
-
77
-
78
-
79
-
80
  def main():
81
  st.title("Chessboard Position Detection and Move Prediction")
82
 
@@ -117,7 +112,7 @@ def main():
117
  board = [["8"] * 8 for _ in range(8)]
118
 
119
  # Run detection
120
- results = model.predict(source=image, save=False, save_txt=False, conf=0.6)
121
 
122
  # Extract predictions and map to FEN board
123
  for result in results[0].boxes:
 
11
  "black-pawn": "p", "black-rook": "r", "black-knight": "n", "black-bishop": "b", "black-queen": "q", "black-king": "k",
12
  "white-pawn": "P", "white-rook": "R", "white-knight": "N", "white-bishop": "B", "white-queen": "Q", "white-king": "K"
13
  }
14
+ GRID_BORDER = 5 # Border size in pixels
15
+ GRID_SIZE = 214 # Effective grid size (10px to 214px)
16
  BLOCK_SIZE = GRID_SIZE // 8 # Each block is ~25px
17
  X_LABELS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # Labels for x-axis (a to h)
18
  Y_LABELS = [8, 7, 6, 5, 4, 3, 2, 1] # Reversed labels for y-axis (8 to 1)
 
25
  The perspective argument can adjust for white ('w') or black ('b') viewpoint.
26
  """
27
  # Grid settings
28
+ border = 5 # 10px border
29
+ grid_size = 214 # Effective grid size (10px to 214px)
30
  block_size = grid_size // 8 # Each block is ~25px
31
 
32
  x_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # Labels for x-axis (a to h)
 
49
 
50
  # Adjust labels based on perspective
51
  if perspective == "b":
52
+ x_index = 7 - x_index # Flip x-axis for black's perspective
53
+ y_index = 7- y_index # Flip y-axis for black's perspective
54
 
55
+ file = x_labels[x_index]
56
+ rank = y_labels[y_index]
57
 
58
+ return f"{file}{rank}"
59
 
60
 
61
  def predict_next_move(fen, stockfish):
 
72
 
73
 
74
 
 
 
 
 
 
75
  def main():
76
  st.title("Chessboard Position Detection and Move Prediction")
77
 
 
112
  board = [["8"] * 8 for _ in range(8)]
113
 
114
  # Run detection
115
+ results = model.predict(source=image, save=False, save_txt=False, conf=0.7)
116
 
117
  # Extract predictions and map to FEN board
118
  for result in results[0].boxes: