Spaces:
Build error
Build error
Kaushik Rajan
commited on
Commit
Β·
a530f7b
1
Parent(s):
021423f
Fix tic-tac-toe board rendering by replacing CSS Grid with Gradio-compatible layout
Browse files
app.py
CHANGED
|
@@ -105,20 +105,24 @@ def create_interface():
|
|
| 105 |
|
| 106 |
# Custom CSS to style the TicTacToe board
|
| 107 |
css = """
|
| 108 |
-
|
| 109 |
-
display: grid;
|
| 110 |
-
grid-template-columns: repeat(3, 1fr);
|
| 111 |
-
grid-template-rows: repeat(3, 1fr);
|
| 112 |
-
gap: 5px;
|
| 113 |
max-width: 300px;
|
| 114 |
margin: auto;
|
| 115 |
}
|
| 116 |
-
|
| 117 |
aspect-ratio: 1 / 1;
|
| 118 |
font-size: 24px !important;
|
| 119 |
font-weight: bold;
|
| 120 |
-
height:
|
| 121 |
-
min-width:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
"""
|
| 124 |
|
|
@@ -241,18 +245,20 @@ def create_interface():
|
|
| 241 |
tictactoe_env.reset()
|
| 242 |
return *update_board_buttons(), "New game started! You are β (X). Click a square to play.", "AI will show its reasoning here...", stats
|
| 243 |
|
|
|
|
|
|
|
|
|
|
| 244 |
# Simplified layout focusing only on TicTacToe
|
| 245 |
gr.Markdown("### Play TicTacToe against AI\nYou are β (X) and go first. Click on a square to make your move.")
|
| 246 |
|
| 247 |
-
with gr.Column():
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
board_buttons.append(button)
|
| 256 |
|
| 257 |
with gr.Row():
|
| 258 |
ttt_reset_btn = gr.Button("New Game", variant="secondary")
|
|
@@ -294,6 +300,13 @@ def create_interface():
|
|
| 294 |
inputs=ttt_stats,
|
| 295 |
outputs=ttt_stats_display
|
| 296 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
gr.Markdown("---")
|
| 298 |
gr.Markdown("π§ **This is a development preview.** Full SPIRAL training and reasoning capabilities will be added in the next update!")
|
| 299 |
|
|
|
|
| 105 |
|
| 106 |
# Custom CSS to style the TicTacToe board
|
| 107 |
css = """
|
| 108 |
+
.ttt-board {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
max-width: 300px;
|
| 110 |
margin: auto;
|
| 111 |
}
|
| 112 |
+
.ttt-board .gr-button {
|
| 113 |
aspect-ratio: 1 / 1;
|
| 114 |
font-size: 24px !important;
|
| 115 |
font-weight: bold;
|
| 116 |
+
height: 80px !important;
|
| 117 |
+
min-width: 80px !important;
|
| 118 |
+
margin: 2px !important;
|
| 119 |
+
}
|
| 120 |
+
.ttt-board .gr-row {
|
| 121 |
+
justify-content: center;
|
| 122 |
+
gap: 0px;
|
| 123 |
+
}
|
| 124 |
+
.ttt-board .gr-column {
|
| 125 |
+
align-items: center;
|
| 126 |
}
|
| 127 |
"""
|
| 128 |
|
|
|
|
| 245 |
tictactoe_env.reset()
|
| 246 |
return *update_board_buttons(), "New game started! You are β (X). Click a square to play.", "AI will show its reasoning here...", stats
|
| 247 |
|
| 248 |
+
# Initialize the board on startup
|
| 249 |
+
tictactoe_env.reset()
|
| 250 |
+
|
| 251 |
# Simplified layout focusing only on TicTacToe
|
| 252 |
gr.Markdown("### Play TicTacToe against AI\nYou are β (X) and go first. Click on a square to make your move.")
|
| 253 |
|
| 254 |
+
with gr.Column(elem_classes=["ttt-board"]):
|
| 255 |
+
board_buttons = []
|
| 256 |
+
for i in range(3):
|
| 257 |
+
with gr.Row(elem_classes=["ttt-row"]):
|
| 258 |
+
for j in range(3):
|
| 259 |
+
pos = i * 3 + j
|
| 260 |
+
button = gr.Button("", elem_id=f"ttt-cell-{pos}", size="lg", value="")
|
| 261 |
+
board_buttons.append(button)
|
|
|
|
| 262 |
|
| 263 |
with gr.Row():
|
| 264 |
ttt_reset_btn = gr.Button("New Game", variant="secondary")
|
|
|
|
| 300 |
inputs=ttt_stats,
|
| 301 |
outputs=ttt_stats_display
|
| 302 |
)
|
| 303 |
+
|
| 304 |
+
# Initialize board display on load
|
| 305 |
+
demo.load(
|
| 306 |
+
fn=lambda stats: (*update_board_buttons(), "Game ready! You are β (X). Click a square to play.", "AI will show its reasoning here...", stats),
|
| 307 |
+
inputs=[ttt_stats],
|
| 308 |
+
outputs=[*board_buttons, ttt_message, ttt_reasoning, ttt_stats]
|
| 309 |
+
)
|
| 310 |
gr.Markdown("---")
|
| 311 |
gr.Markdown("π§ **This is a development preview.** Full SPIRAL training and reasoning capabilities will be added in the next update!")
|
| 312 |
|