Spaces:
Runtime error
Runtime error
Sasha Rush commited on
Commit ·
7d4b679
1
Parent(s): 23eb24d
leaderboard
Browse files194 unmodified lines19519619719819920020120220320420531 unmodified lines237238239240241242243131 unmodified lines37537637737837938038138238338438538621 unmodified lines40840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644722 unmodified lines4704714724734744754767 unmodified lines48448548648748848949049149249349446 unmodified lines541542543544545546547194 unmodified linesreturn 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})"# This is the version of move that the AI can see.def move(game, action, old_pos):# ACTIONS (must be legal)game.move(Actions(action))offset = change_str[action]pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])assert 0 <= pos[0] < game.boundary[0], "Row position out of bounds"assert 0 <= pos[1] < game.boundary[1], "Col position out of bounds"31 unmodified linescanvas += row.translate(w * 0.5 if r%2 else 0, 1.5 * r)canvas = canvas.center_xy().frame(0.5)canvas = rectangle(canvas.get_envelope().width, canvas.get_envelope().height).line_width(0.5).fill_color(Color("orange")) + canvascanvas.render_svg(f"pic{num}.svg", 256)canvas.render(f"pic{num}.png", 500)return canvas131 unmodified linesboard = games[inp]else:board = eval(inp)draw_board(board.board.grid, 0).render_svg("tmp.svg")return "tmp.svg", repr(board)draw_board(hard_game.board.grid, 0).render_svg("hard.svg")draw_board(easy_game.board.grid, 0).render_svg("easy.svg")with gr.Blocks() as app:# test = gr.Code(label="test")21 unmodified linesstart_btn = gr.Button("Prompt >")cancel_btn = gr.Button("Cancel")prompt = gr.Code(label="Prompt (This is for you to fill out)", language="python", lines=40, value=f"""# A prompt to describe this game to the GPT model.# Ideas:# * Describe how the game works# * Give code examples that solve similar mazes.# * Give examples to explain the reasoning process# You might want to do this in a separate editor and paset in.# For example you might want to tell it how the moves workchange_str = {change_str}# Or make up a clear implementation for the move function.def move(board, action, old_pos):# ACTIONS (must be legal)board.move(action)offset = change_str[action]pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])assert 0 <= pos[0] < board.boundary[0]assert 0 <= pos[1] < board.boundary[1]assert pos not in board.wallsif action == "Pickup":assert pos == board.keyreturn pos# You can also test your code on the right side to make few-shot examples.# Finally use %GAME% to inject the game description above.""")with gr.Column():im = gr.Image(label="Gallery of the Game")# im.style(preview=True, object_fit="scale-down", columns=1, container=True)msg_box = gr.HTML(label="", show_label=False)22 unmodified linesq = {}i = 0count = 0im_ = "tmp.svg"state_val = Noneyield {im: im_, counter: 0, output: "", msg_box: "", state: state_val}7 unmodified linesexec(prefix + f"\n return b\nq['board'] = my_example({repr(board)})")except AssertionError as e:print("fail")yield {im: [f"pic{j}.svg" for j in range(i)], counter: count, output: prefix, msg_box: f"You made an illegal move: {e}"}returndraw_board(q["board"].board.grid, i).render_svg("tmp.svg")i += 1im_ = f"pic{i-1}.svg"yield {im: im_, counter: count, output: prefix}else:yield {im: im_, counter: count, output: prefix}46 unmodified linesteam_name = gr.Text(label="Team Name")leaderboard = gr.Button(value="Submit")msg = gr.Text(label="Status")leader = gr.Dataframe(pd.read_csv(DATA_FILE)[["team", "board", "count"]])def leaderfn(data):if data[state] is None:return {msg: "Nothing to submit"}194 unmodified lines19519619719819920020120220320420520620720820931 unmodified lines241242243244245246247131 unmodified lines37938038138238338438538638738821 unmodified lines41041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344422 unmodified lines4674684694704714724737 unmodified lines48148248348448548648748848949049149249349449546 unmodified lines542543544545546547548194 unmodified linesreturn 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})"# This is the version of move that the AI can see.def move(game, action, old_pos=None):# ACTIONS (must be legal)if old_pos is None:old_pos = game.board.player_posgame.move(Actions(action))offset = change_str[action]pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])assert 0 <= pos[0] < game.boundary[0], "Row position out of bounds"assert 0 <= pos[1] < game.boundary[1], "Col position out of bounds"31 unmodified linescanvas += row.translate(w * 0.5 if r%2 else 0, 1.5 * r)canvas = canvas.center_xy().frame(0.5)canvas = rectangle(canvas.get_envelope().width, canvas.get_envelope().height).line_width(0.5).fill_color(Color("orange")) + canvas# canvas.render_svg(f"pic{num}.svg", 256)canvas.render(f"pic{num}.png", 500)return canvas131 unmodified linesboard = games[inp]else:board = eval(inp)draw_board(board.board.grid, 0).render("tmp.png", 500)return "tmp.png", repr(board)with gr.Blocks() as app:# test = gr.Code(label="test")21 unmodified linesstart_btn = gr.Button("Prompt >")cancel_btn = gr.Button("Cancel")prompt = gr.Code(label="Prompt (Simple example)", language="python", lines=40, value="""# Let's play a game!# Here are the moves.moves = {'UR': (-1, 1), 'R': (0, 2), 'DR': (1, 1), 'DL': (1, -1),'L': (0, -2), 'UL': (-1, -1), 'Pickup': (0, 0)}# You are going to write a function like this.# Game(init=(0, 0), flag=(1, 1), walls=[], boundary=(2, 3), key=(0, 2))# (0, 4) and (1, 3) are out-of-bounds.def example(b):# Starts at (0, 0)move(b, "R")# Moves to (0, 2). This one has the key.move(b, "Pickup")# Moves to (1, 1)move(b, "DL")return b# Be sure not to go out of bounds!# Now you are going to write a function `my_example(b)`# It will be passed b=%GAME% to inject the game description above.# Here is the code.""")with gr.Column():im = gr.Image(show_label=False).style(height=500)# im.style(preview=True, object_fit="scale-down", columns=1, container=True)msg_box = gr.HTML(label="", show_label=False)22 unmodified linesq = {}i = 0count = 0im_ = "tmp.png"state_val = Noneyield {im: im_, counter: 0, output: "", msg_box: "", state: state_val}7 unmodified linesexec(prefix + f"\n return b\nq['board'] = my_example({repr(board)})")except AssertionError as e:print("fail")yield {im: f"pic{i-1}.png", counter: count, output: prefix, msg_box: f"You made an illegal move: {e}"}returnexcept:yield {counter: count, output: prefix, msg_box: f"Code error"}returndraw_board(q["board"].board.grid, i).render("tmp.png", 500)i += 1im_ = f"pic{i-1}.png"yield {im: im_, counter: count, output: prefix}else:yield {im: im_, counter: count, output: prefix}46 unmodified linesteam_name = gr.Text(label="Team Name")leaderboard = gr.Button(value="Submit")msg = gr.Text(label="Status")leader = gr.Dataframe(pd.read_csv(DATA_FILE)[["team", "board", "count"]].sort_values(["board", "count"]))def leaderfn(data):if data[state] is None:return {msg: "Nothing to submit"}
app.py+38-37