Spaces:
Runtime error
Runtime error
philipp-zettl
commited on
Commit
•
d41eec1
1
Parent(s):
153ec16
update app
Browse files- app.py +9 -4
- requirements.txt +3 -1
app.py
CHANGED
@@ -6,6 +6,9 @@ import torch
|
|
6 |
import chess
|
7 |
import chess.svg
|
8 |
import chess.pgn
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
vocab_size=33
|
@@ -33,10 +36,12 @@ def generate(prompt):
|
|
33 |
pgn_str = StringIO(pgn)
|
34 |
game = chess.pgn.read_game(pgn_str)
|
35 |
img = chess.svg.board(game.board())
|
36 |
-
filename = f'moves-{pgn}
|
37 |
-
with open(filename, 'w') as f:
|
38 |
f.write(img)
|
39 |
-
|
|
|
|
|
40 |
return pgn, plot
|
41 |
|
42 |
|
@@ -51,7 +56,7 @@ with gr.Blocks() as demo:
|
|
51 |
""")
|
52 |
prompt = gr.Text(label="PGN")
|
53 |
output = gr.Text(label="Next turn", interactive=False)
|
54 |
-
img = gr.
|
55 |
submit = gr.Button("Submit")
|
56 |
submit.click(generate, [prompt], [output, img])
|
57 |
|
|
|
6 |
import chess
|
7 |
import chess.svg
|
8 |
import chess.pgn
|
9 |
+
from svglib.svglib import svg2rlg
|
10 |
+
from reportlab.graphics import renderPM
|
11 |
+
from PIL import Image
|
12 |
|
13 |
|
14 |
vocab_size=33
|
|
|
36 |
pgn_str = StringIO(pgn)
|
37 |
game = chess.pgn.read_game(pgn_str)
|
38 |
img = chess.svg.board(game.board())
|
39 |
+
filename = f'./moves-{pgn}'
|
40 |
+
with open(filename + '.svg', 'w') as f:
|
41 |
f.write(img)
|
42 |
+
drawing = svg2rlg(filename + '.svg')
|
43 |
+
renderPM.drawToFile(drawing, f"{filename}.png", fmt="PNG")
|
44 |
+
plot = Image.open(f'{filename}.png')
|
45 |
return pgn, plot
|
46 |
|
47 |
|
|
|
56 |
""")
|
57 |
prompt = gr.Text(label="PGN")
|
58 |
output = gr.Text(label="Next turn", interactive=False)
|
59 |
+
img = gr.Image()
|
60 |
submit = gr.Button("Submit")
|
61 |
submit.click(generate, [prompt], [output, img])
|
62 |
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
torch
|
2 |
-
chess
|
|
|
|
|
|
1 |
torch
|
2 |
+
chess
|
3 |
+
svglib
|
4 |
+
rlPyCairo
|