Spaces:
Runtime error
Runtime error
Sasha Rush
commited on
Commit
·
7d4b679
1
Parent(s):
23eb24d
leaderboard
Browse files
app.py
CHANGED
@@ -195,11 +195,15 @@ class Game:
|
|
195 |
return f"Game(init={self.board.player_pos}, flag={self.board.flag_pos}, walls={self.board.wall_pos}, boundary={self.boundary}, key={self.board.key_pos})"
|
196 |
|
197 |
# This is the version of move that the AI can see.
|
198 |
-
def move(game, action, old_pos):
|
|
|
199 |
# ACTIONS (must be legal)
|
|
|
|
|
200 |
game.move(Actions(action))
|
201 |
offset = change_str[action]
|
202 |
pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
|
|
|
203 |
|
204 |
assert 0 <= pos[0] < game.boundary[0], "Row position out of bounds"
|
205 |
assert 0 <= pos[1] < game.boundary[1], "Col position out of bounds"
|
@@ -237,7 +241,7 @@ def draw_board(grid, num=0):
|
|
237 |
canvas += row.translate(w * 0.5 if r%2 else 0, 1.5 * r)
|
238 |
canvas = canvas.center_xy().frame(0.5)
|
239 |
canvas = rectangle(canvas.get_envelope().width, canvas.get_envelope().height).line_width(0.5).fill_color(Color("orange")) + canvas
|
240 |
-
canvas.render_svg(f"pic{num}.svg", 256)
|
241 |
canvas.render(f"pic{num}.png", 500)
|
242 |
return canvas
|
243 |
|
@@ -375,12 +379,10 @@ def load(inp):
|
|
375 |
board = games[inp]
|
376 |
else:
|
377 |
board = eval(inp)
|
378 |
-
draw_board(board.board.grid, 0).
|
379 |
|
380 |
-
return "tmp.
|
381 |
|
382 |
-
draw_board(hard_game.board.grid, 0).render_svg("hard.svg")
|
383 |
-
draw_board(easy_game.board.grid, 0).render_svg("easy.svg")
|
384 |
with gr.Blocks() as app:
|
385 |
|
386 |
# test = gr.Code(label="test")
|
@@ -408,40 +410,35 @@ GPTWorld is a prompting game. Your goal is to get an LLM to complete a maze. You
|
|
408 |
start_btn = gr.Button("Prompt >")
|
409 |
cancel_btn = gr.Button("Cancel")
|
410 |
|
411 |
-
prompt = gr.Code(label="Prompt (
|
412 |
-
#
|
|
|
413 |
|
414 |
-
|
415 |
-
|
416 |
-
# * Give code examples that solve similar mazes.
|
417 |
-
# * Give examples to explain the reasoning process
|
418 |
|
419 |
-
# You
|
420 |
|
421 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
-
|
424 |
|
425 |
-
# Or make up a clear implementation for the move function.
|
426 |
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
offset = change_str[action]
|
431 |
-
pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
|
432 |
-
assert 0 <= pos[0] < board.boundary[0]
|
433 |
-
assert 0 <= pos[1] < board.boundary[1]
|
434 |
-
assert pos not in board.walls
|
435 |
-
if action == "Pickup":
|
436 |
-
assert pos == board.key
|
437 |
-
return pos
|
438 |
-
|
439 |
-
# You can also test your code on the right side to make few-shot examples.
|
440 |
-
|
441 |
-
# Finally use %GAME% to inject the game description above.
|
442 |
""")
|
443 |
with gr.Column():
|
444 |
-
im = gr.Image(
|
445 |
# im.style(preview=True, object_fit="scale-down", columns=1, container=True)
|
446 |
msg_box = gr.HTML(label="", show_label=False)
|
447 |
|
@@ -470,7 +467,7 @@ def move(board, action, old_pos):
|
|
470 |
q = {}
|
471 |
i = 0
|
472 |
count = 0
|
473 |
-
im_ = "tmp.
|
474 |
state_val = None
|
475 |
yield {im: im_, counter: 0, output: "", msg_box: "", state: state_val}
|
476 |
|
@@ -484,11 +481,15 @@ def move(board, action, old_pos):
|
|
484 |
exec(prefix + f"\n return b\nq['board'] = my_example({repr(board)})")
|
485 |
except AssertionError as e:
|
486 |
print("fail")
|
487 |
-
yield {im:
|
488 |
return
|
489 |
-
|
|
|
|
|
|
|
|
|
490 |
i += 1
|
491 |
-
im_ = f"pic{i-1}.
|
492 |
yield {im: im_, counter: count, output: prefix}
|
493 |
else:
|
494 |
yield {im: im_, counter: count, output: prefix}
|
@@ -541,7 +542,7 @@ The score is the number of output tokens your solution takes.
|
|
541 |
team_name = gr.Text(label="Team Name")
|
542 |
leaderboard = gr.Button(value="Submit")
|
543 |
msg = gr.Text(label="Status")
|
544 |
-
leader = gr.Dataframe(pd.read_csv(DATA_FILE)[["team", "board", "count"]])
|
545 |
def leaderfn(data):
|
546 |
if data[state] is None:
|
547 |
return {msg: "Nothing to submit"}
|
|
|
195 |
return f"Game(init={self.board.player_pos}, flag={self.board.flag_pos}, walls={self.board.wall_pos}, boundary={self.boundary}, key={self.board.key_pos})"
|
196 |
|
197 |
# This is the version of move that the AI can see.
|
198 |
+
def move(game, action, old_pos=None):
|
199 |
+
|
200 |
# ACTIONS (must be legal)
|
201 |
+
if old_pos is None:
|
202 |
+
old_pos = game.board.player_pos
|
203 |
game.move(Actions(action))
|
204 |
offset = change_str[action]
|
205 |
pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
|
206 |
+
|
207 |
|
208 |
assert 0 <= pos[0] < game.boundary[0], "Row position out of bounds"
|
209 |
assert 0 <= pos[1] < game.boundary[1], "Col position out of bounds"
|
|
|
241 |
canvas += row.translate(w * 0.5 if r%2 else 0, 1.5 * r)
|
242 |
canvas = canvas.center_xy().frame(0.5)
|
243 |
canvas = rectangle(canvas.get_envelope().width, canvas.get_envelope().height).line_width(0.5).fill_color(Color("orange")) + canvas
|
244 |
+
# canvas.render_svg(f"pic{num}.svg", 256)
|
245 |
canvas.render(f"pic{num}.png", 500)
|
246 |
return canvas
|
247 |
|
|
|
379 |
board = games[inp]
|
380 |
else:
|
381 |
board = eval(inp)
|
382 |
+
draw_board(board.board.grid, 0).render("tmp.png", 500)
|
383 |
|
384 |
+
return "tmp.png", repr(board)
|
385 |
|
|
|
|
|
386 |
with gr.Blocks() as app:
|
387 |
|
388 |
# test = gr.Code(label="test")
|
|
|
410 |
start_btn = gr.Button("Prompt >")
|
411 |
cancel_btn = gr.Button("Cancel")
|
412 |
|
413 |
+
prompt = gr.Code(label="Prompt (Simple example)", language="python", lines=40, value="""
|
414 |
+
# Let's play a game!
|
415 |
+
# Here are the moves.
|
416 |
|
417 |
+
moves = {'UR': (-1, 1), 'R': (0, 2), 'DR': (1, 1), 'DL': (1, -1),
|
418 |
+
'L': (0, -2), 'UL': (-1, -1), 'Pickup': (0, 0)}
|
|
|
|
|
419 |
|
420 |
+
# You are going to write a function like this.
|
421 |
|
422 |
+
# Game(init=(0, 0), flag=(1, 1), walls=[], boundary=(2, 3), key=(0, 2))
|
423 |
+
# (0, 4) and (1, 3) are out-of-bounds.
|
424 |
+
def example(b):
|
425 |
+
# Starts at (0, 0)
|
426 |
+
move(b, "R")
|
427 |
+
# Moves to (0, 2). This one has the key.
|
428 |
+
move(b, "Pickup")
|
429 |
+
# Moves to (1, 1)
|
430 |
+
move(b, "DL")
|
431 |
+
return b
|
432 |
|
433 |
+
# Be sure not to go out of bounds!
|
434 |
|
|
|
435 |
|
436 |
+
# Now you are going to write a function `my_example(b)`
|
437 |
+
# It will be passed b=%GAME% to inject the game description above.
|
438 |
+
# Here is the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
""")
|
440 |
with gr.Column():
|
441 |
+
im = gr.Image(show_label=False).style(height=500)
|
442 |
# im.style(preview=True, object_fit="scale-down", columns=1, container=True)
|
443 |
msg_box = gr.HTML(label="", show_label=False)
|
444 |
|
|
|
467 |
q = {}
|
468 |
i = 0
|
469 |
count = 0
|
470 |
+
im_ = "tmp.png"
|
471 |
state_val = None
|
472 |
yield {im: im_, counter: 0, output: "", msg_box: "", state: state_val}
|
473 |
|
|
|
481 |
exec(prefix + f"\n return b\nq['board'] = my_example({repr(board)})")
|
482 |
except AssertionError as e:
|
483 |
print("fail")
|
484 |
+
yield {im: f"pic{i-1}.png", counter: count, output: prefix, msg_box: f"You made an illegal move: {e}"}
|
485 |
return
|
486 |
+
|
487 |
+
except:
|
488 |
+
yield {counter: count, output: prefix, msg_box: f"Code error"}
|
489 |
+
return
|
490 |
+
draw_board(q["board"].board.grid, i).render("tmp.png", 500)
|
491 |
i += 1
|
492 |
+
im_ = f"pic{i-1}.png"
|
493 |
yield {im: im_, counter: count, output: prefix}
|
494 |
else:
|
495 |
yield {im: im_, counter: count, output: prefix}
|
|
|
542 |
team_name = gr.Text(label="Team Name")
|
543 |
leaderboard = gr.Button(value="Submit")
|
544 |
msg = gr.Text(label="Status")
|
545 |
+
leader = gr.Dataframe(pd.read_csv(DATA_FILE)[["team", "board", "count"]].sort_values(["board", "count"]))
|
546 |
def leaderfn(data):
|
547 |
if data[state] is None:
|
548 |
return {msg: "Nothing to submit"}
|