pratikshahp commited on
Commit
2cbfc08
·
verified ·
1 Parent(s): c07b8c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -55,11 +55,12 @@ with gr.Blocks(css=".cell-btn {height: 100px; width: 100px; font-size: 2em; text
55
  current_player = gr.State("X")
56
  game_status = gr.Textbox(value="Player 1's turn (X)", label="Game Status", interactive=False)
57
 
58
- # Create grid buttons
59
  buttons = []
60
  for i in range(3):
61
  with gr.Row():
62
  for j in range(3):
 
63
  btn = gr.Button(value="", elem_classes=["cell-btn"], elem_id=f"button_{i*3 + j}")
64
  buttons.append(btn)
65
 
@@ -67,7 +68,7 @@ with gr.Blocks(css=".cell-btn {height: 100px; width: 100px; font-size: 2em; text
67
  for idx, btn in enumerate(buttons):
68
  btn.click(
69
  handle_move,
70
- inputs=[board_state, current_player, gr.Number(idx)], # Pass the index without displaying it
71
  outputs=[board_state, current_player, game_status, *buttons],
72
  )
73
 
 
55
  current_player = gr.State("X")
56
  game_status = gr.Textbox(value="Player 1's turn (X)", label="Game Status", interactive=False)
57
 
58
+ # Create grid buttons without displaying any Number components
59
  buttons = []
60
  for i in range(3):
61
  with gr.Row():
62
  for j in range(3):
63
+ # Each button is clickable, the index is passed in hidden and used internally
64
  btn = gr.Button(value="", elem_classes=["cell-btn"], elem_id=f"button_{i*3 + j}")
65
  buttons.append(btn)
66
 
 
68
  for idx, btn in enumerate(buttons):
69
  btn.click(
70
  handle_move,
71
+ inputs=[board_state, current_player, gr.Number(idx, visible=False)], # Hide the number input
72
  outputs=[board_state, current_player, game_status, *buttons],
73
  )
74