Spaces:
Sleeping
Sleeping
Show PGN text and provide option to download
Browse files
app.py
CHANGED
|
@@ -37,9 +37,7 @@ def annotate_pgn(
|
|
| 37 |
game, analysis_time=analysis_time_per_move, llm_character=style
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
return output_path
|
| 43 |
|
| 44 |
|
| 45 |
def render_board(fen: Optional[str] = None, render_mode: str = "svg") -> str:
|
|
@@ -128,6 +126,11 @@ def play_chess(
|
|
| 128 |
|
| 129 |
|
| 130 |
with gr.Blocks(title="ThinkSquare") as app:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
with gr.Tab("Play Chess"):
|
| 132 |
gr.Markdown("### Play Chess with an engine")
|
| 133 |
move_input = gr.Textbox(
|
|
@@ -178,7 +181,12 @@ with gr.Blocks(title="ThinkSquare") as app:
|
|
| 178 |
)
|
| 179 |
analyze_btn = gr.Button("Annotate PGN")
|
| 180 |
|
| 181 |
-
annotated_pgn_file = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
analyze_btn.click(
|
| 184 |
fn=annotate_pgn,
|
|
@@ -206,4 +214,6 @@ with gr.Blocks(title="ThinkSquare") as app:
|
|
| 206 |
outputs=board_render_output,
|
| 207 |
)
|
| 208 |
|
| 209 |
-
|
|
|
|
|
|
|
|
|
| 37 |
game, analysis_time=analysis_time_per_move, llm_character=style
|
| 38 |
)
|
| 39 |
|
| 40 |
+
return str(annotated_game)
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def render_board(fen: Optional[str] = None, render_mode: str = "svg") -> str:
|
|
|
|
| 126 |
|
| 127 |
|
| 128 |
with gr.Blocks(title="ThinkSquare") as app:
|
| 129 |
+
def save_text_to_file(text):
|
| 130 |
+
with open("annotated_game.pgn", "w") as f:
|
| 131 |
+
f.write(text)
|
| 132 |
+
return "annotated_game.pgn"
|
| 133 |
+
|
| 134 |
with gr.Tab("Play Chess"):
|
| 135 |
gr.Markdown("### Play Chess with an engine")
|
| 136 |
move_input = gr.Textbox(
|
|
|
|
| 181 |
)
|
| 182 |
analyze_btn = gr.Button("Annotate PGN")
|
| 183 |
|
| 184 |
+
annotated_pgn_file = gr.Textbox(label="Annotated PGN")
|
| 185 |
+
download_button = gr.Button("Download Annotated PGN")
|
| 186 |
+
pgn_file_output = gr.File(label="Download your annotated PGN")
|
| 187 |
+
download_button.click(
|
| 188 |
+
fn=save_text_to_file, inputs=annotated_pgn_file, outputs=pgn_file_output
|
| 189 |
+
)
|
| 190 |
|
| 191 |
analyze_btn.click(
|
| 192 |
fn=annotate_pgn,
|
|
|
|
| 214 |
outputs=board_render_output,
|
| 215 |
)
|
| 216 |
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
app.launch(mcp_server=True)
|