Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -89,6 +89,49 @@ def create_gif(image_list, gif_path, duration):
|
|
89 |
gif_path, save_all=True, append_images=pil_images[1:], duration=duration, loop=0
|
90 |
)
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
def save_result_file(
|
93 |
pgn_id, model_id_white, model_id_black, termination, result, auth_token, gist_id
|
94 |
):
|
@@ -201,9 +244,7 @@ def update(model_id_white, model_id_black):
|
|
201 |
result = None
|
202 |
|
203 |
# Render first image
|
204 |
-
|
205 |
-
png = cairosvg.svg2png(bytestring=svg)
|
206 |
-
image = PILImage.open(io.BytesIO(png))
|
207 |
yield image
|
208 |
|
209 |
# Time budget
|
@@ -248,10 +289,7 @@ def update(model_id_white, model_id_black):
|
|
248 |
pgn_moves += move_str
|
249 |
|
250 |
# Render the board to an image
|
251 |
-
|
252 |
-
svg = chess.svg.board(board=board, arrows=[(last_move.from_square, last_move.to_square)]).encode("utf-8")
|
253 |
-
png = cairosvg.svg2png(bytestring=svg)
|
254 |
-
image = PILImage.open(io.BytesIO(png))
|
255 |
board_images.append(np.array(image))
|
256 |
|
257 |
# Deduct the time taken for the move from the model's time budget
|
|
|
89 |
gif_path, save_all=True, append_images=pil_images[1:], duration=duration, loop=0
|
90 |
)
|
91 |
|
92 |
+
def render_init(board):
|
93 |
+
svg = chess.svg.board(board=board).encode("utf-8")
|
94 |
+
png = cairosvg.svg2png(bytestring=svg)
|
95 |
+
image = PILImage.open(io.BytesIO(png))
|
96 |
+
|
97 |
+
# Calculate the size of the new image
|
98 |
+
width, height = image.size
|
99 |
+
new_width = 3 * width
|
100 |
+
|
101 |
+
# Create a new blank image with the desired dimensions
|
102 |
+
new_image = PILImage.new('RGB', (new_width, height), 'white')
|
103 |
+
|
104 |
+
# Calculate the position to paste the chess board image
|
105 |
+
left = width # One third of the width
|
106 |
+
upper = 0
|
107 |
+
|
108 |
+
# Paste the chess board image into the new image
|
109 |
+
new_image.paste(image, (left, upper))
|
110 |
+
|
111 |
+
return new_image
|
112 |
+
|
113 |
+
def render_new(board):
|
114 |
+
last_move = board.peek()
|
115 |
+
svg = chess.svg.board(board=board, arrows=[(last_move.from_square, last_move.to_square)]).encode("utf-8")
|
116 |
+
png = cairosvg.svg2png(bytestring=svg)
|
117 |
+
image = PILImage.open(io.BytesIO(png))
|
118 |
+
|
119 |
+
# Calculate the size of the new image
|
120 |
+
width, height = image.size
|
121 |
+
new_width = 3 * width
|
122 |
+
|
123 |
+
# Create a new blank image with the desired dimensions
|
124 |
+
new_image = PILImage.new('RGB', (new_width, height), 'white')
|
125 |
+
|
126 |
+
# Calculate the position to paste the chess board image
|
127 |
+
left = width # One third of the width
|
128 |
+
upper = 0
|
129 |
+
|
130 |
+
# Paste the chess board image into the new image
|
131 |
+
new_image.paste(image, (left, upper))
|
132 |
+
|
133 |
+
return new_image
|
134 |
+
|
135 |
def save_result_file(
|
136 |
pgn_id, model_id_white, model_id_black, termination, result, auth_token, gist_id
|
137 |
):
|
|
|
244 |
result = None
|
245 |
|
246 |
# Render first image
|
247 |
+
image = render_init(board)
|
|
|
|
|
248 |
yield image
|
249 |
|
250 |
# Time budget
|
|
|
289 |
pgn_moves += move_str
|
290 |
|
291 |
# Render the board to an image
|
292 |
+
image = render_new(board)
|
|
|
|
|
|
|
293 |
board_images.append(np.array(image))
|
294 |
|
295 |
# Deduct the time taken for the move from the model's time budget
|