Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,17 +8,17 @@ import numpy as np
|
|
| 8 |
|
| 9 |
model = Llama(
|
| 10 |
model_path=hf_hub_download(
|
| 11 |
-
repo_id=os.environ.get("REPO_ID", "Lyte/QuadConnect2.5-0.5B-
|
| 12 |
filename=os.environ.get("MODEL_FILE", "unsloth.Q8_0.gguf"),
|
| 13 |
)
|
| 14 |
)
|
| 15 |
|
| 16 |
-
SYSTEM_PROMPT = """You are a Connect Four player
|
| 17 |
<reasoning>
|
| 18 |
-
Explain your reasoning
|
| 19 |
</reasoning>
|
| 20 |
<move>
|
| 21 |
-
The column
|
| 22 |
</move>
|
| 23 |
"""
|
| 24 |
|
|
@@ -81,8 +81,8 @@ class ConnectFour:
|
|
| 81 |
if self.board[row][col] != 0:
|
| 82 |
col_letter = chr(ord('a') + col)
|
| 83 |
row_num = str(6 - row) # Convert to 1-based indexing
|
| 84 |
-
player = "X" if self.board[row][col] == 1 else "O"
|
| 85 |
-
moves.append(f"{col_letter}{row_num}={player}")
|
| 86 |
return ", ".join(moves)
|
| 87 |
|
| 88 |
def parse_ai_move(self, move_str):
|
|
@@ -146,7 +146,7 @@ def create_interface():
|
|
| 146 |
padding: 0 15px;
|
| 147 |
}
|
| 148 |
#column-buttons button {
|
| 149 |
-
margin: 0px
|
| 150 |
}
|
| 151 |
div.svelte-1nguped {
|
| 152 |
display: block;
|
|
@@ -163,7 +163,7 @@ def create_interface():
|
|
| 163 |
status = gr.Markdown("Your turn! Click a button to drop your piece!", elem_id="ai-status")
|
| 164 |
|
| 165 |
# Column buttons
|
| 166 |
-
with gr.Group(elem_id="column-buttons"):
|
| 167 |
col_buttons = []
|
| 168 |
for i in range(7):
|
| 169 |
btn = gr.Button(f"⬇️ {i+1}", scale=1)
|
|
@@ -211,7 +211,9 @@ def create_interface():
|
|
| 211 |
# AI move
|
| 212 |
game.current_player = 2
|
| 213 |
board_state = game.board_to_string()
|
|
|
|
| 214 |
prompt = f"Current Board: {board_state}. Make a move."
|
|
|
|
| 215 |
|
| 216 |
# Get AI response
|
| 217 |
response = model.create_chat_completion(
|
|
@@ -321,4 +323,4 @@ def render_board(board=None):
|
|
| 321 |
# Launch the interface
|
| 322 |
if __name__ == "__main__":
|
| 323 |
interface = create_interface()
|
| 324 |
-
interface.launch(
|
|
|
|
| 8 |
|
| 9 |
model = Llama(
|
| 10 |
model_path=hf_hub_download(
|
| 11 |
+
repo_id=os.environ.get("REPO_ID", "Lyte/QuadConnect2.5-0.5B-v0.0.2b"),
|
| 12 |
filename=os.environ.get("MODEL_FILE", "unsloth.Q8_0.gguf"),
|
| 13 |
)
|
| 14 |
)
|
| 15 |
|
| 16 |
+
SYSTEM_PROMPT = """You are a Connect Four player. Connect Four is played on a 6x7 grid. Given the current board state, predict the next *column* to play in. Moves are specified by the column letter (a-g). Respond in the following format:
|
| 17 |
<reasoning>
|
| 18 |
+
Explain your reasoning, considering the board state and potential future moves.
|
| 19 |
</reasoning>
|
| 20 |
<move>
|
| 21 |
+
The column letter (a-g) of your move.
|
| 22 |
</move>
|
| 23 |
"""
|
| 24 |
|
|
|
|
| 81 |
if self.board[row][col] != 0:
|
| 82 |
col_letter = chr(ord('a') + col)
|
| 83 |
row_num = str(6 - row) # Convert to 1-based indexing
|
| 84 |
+
#player = "X" if self.board[row][col] == 1 else "O"
|
| 85 |
+
moves.append(f"{col_letter}{row_num}")#={player}")
|
| 86 |
return ", ".join(moves)
|
| 87 |
|
| 88 |
def parse_ai_move(self, move_str):
|
|
|
|
| 146 |
padding: 0 15px;
|
| 147 |
}
|
| 148 |
#column-buttons button {
|
| 149 |
+
margin: 0px 7px;
|
| 150 |
}
|
| 151 |
div.svelte-1nguped {
|
| 152 |
display: block;
|
|
|
|
| 163 |
status = gr.Markdown("Your turn! Click a button to drop your piece!", elem_id="ai-status")
|
| 164 |
|
| 165 |
# Column buttons
|
| 166 |
+
with gr.Group(elem_id="column-buttons", elem_classes=["fitter"]):
|
| 167 |
col_buttons = []
|
| 168 |
for i in range(7):
|
| 169 |
btn = gr.Button(f"⬇️ {i+1}", scale=1)
|
|
|
|
| 211 |
# AI move
|
| 212 |
game.current_player = 2
|
| 213 |
board_state = game.board_to_string()
|
| 214 |
+
|
| 215 |
prompt = f"Current Board: {board_state}. Make a move."
|
| 216 |
+
#print(prompt)
|
| 217 |
|
| 218 |
# Get AI response
|
| 219 |
response = model.create_chat_completion(
|
|
|
|
| 323 |
# Launch the interface
|
| 324 |
if __name__ == "__main__":
|
| 325 |
interface = create_interface()
|
| 326 |
+
interface.launch()
|