Spaces:
Runtime error
Runtime error
Michael Falk commited on
Commit ·
6c19c91
1
Parent(s): 617960c
Changed gradio container to full width
Browse filesFiles changed (3)
- README.md+60-9
- app.py+11-7
- requirements.txt-1
1234561 unmodified line89101112131415161718192021222324252 unmodified lines2829303132333435363738---title: ChessCoachemoji: 🏢colorFrom: graycolorTo: indigosdk: gradio1 unmodified lineapp_file: app.pypinned: falselicense: mitshort_description: Your personal chess coach to learn from your chess games.tags:- mcp-in-action-track-creative- mcp-in-action-track-consumer---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference# Chess Coach## Introduction## Tech Stack- Gradio 62 unmodified lines- stockfish engine- chess-openings database## Get started### AuthorMichael Falk### Credits- https://github.com/lichess-org/chess-openings1234561 unmodified line891011121314151617181920212223242526272 unmodified lines303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889---title: ChessCoachemoji: ♟️colorFrom: graycolorTo: indigosdk: gradio1 unmodified lineapp_file: app.pypinned: falselicense: mitshort_description: Your personal AI Chess Coach to learn from your chess games.tags:- mcp-in-action-track-creative- mcp-in-action-track-consumer---# Chess Coach## IntroductionEntry for the MCP 1st birthday challenge. Chess Coach is a Gradio app that pairs a Stockfish-backed analyzer with AI to coach you through your own games. Paste or upload a PGN to get opening recognition, critical moments, and actionable insight written by the agent.LinkedIn announcement: [Link](https://www.linkedin.com/posts/michael-falk-info_mcp-1st-birthday-mcp-1st-birthday-activity-7400967536747614209-RWmA?utm_source=share&utm_medium=member_desktop&rcm=ACoAABZfhJwBaC4ODwt0XaZAEH0ayzDYyP5Hhhc)## Tech Stack- Gradio 62 unmodified lines- stockfish engine- chess-openings database## Features- Import PGN text or file, or pick one of the bundled examples.- Detect the opening from the Lichess ECO database and render the key position.- Run fast Stockfish evaluations for each move to surface blunders and critical moments.- Navigate the game move by move on an interactive SVG board.- Get key insights from AI tailored to the game.## Quickstart1. Python 3.10+ recommended. Optional: create a venv with `python -m venv venv` and activate it.2. Install dependencies: `pip install -r requirements.txt`.3. Create a `.env` file with your model endpoint settings (see below).4. Ensure Stockfish is available. Binaries are included under `stockfish/`.5. Start the app: `python app.py` and open the Gradio link printed in the console.### Environment variables- `API_KEY` – API key for your model provider.- `BASE_API_URL` – Base URL if OpenAI-compatible model provider are used.- `MODEL_NAME` – Model name (e.g., `gpt-5-mini`).### MCP usage (optional)The repository includes a minimal FastMCP server in `src/mcp_server.py`. To experiment with MCP locally:```bashpython -m src.mcp_server # starts the server on streamable HTTP```The agent code in `src/ai.py` includes a helper to connect to this MCP endpoint if you want to extend the toolset.## How to use the UI- Upload a `.pgn` file or paste PGN text in Step 1, then click **Analyze Game**.- Use the sidebar log to follow the analysis steps.- Step through moves with the arrow buttons and review critical moments flagged by Stockfish.- Read the opening summary and the agent-generated key insight to guide your next games.## Repository layout- `app.py` – Gradio walkthrough UI and entry point.- `src/` – Analysis logic (`chess_engine.py`), AI integration (`ai.py`) etc.- `examples/` – Sample PGN files for quick testing.- `data/openings/` – ECO opening database from Lichess.- `stockfish/` – Pre-bundled Stockfish binaries for common platforms.### Ressources- Lichess ECO opening database- https://github.com/lichess-org/chess-openings- Python Chess Library- https://github.com/niklasf/python-chess### Authortravelhawk
8 unmodified lines910111213141511 unmodified lines2728293031323345 unmodified lines79808182838485869 unmodified lines9697989910010110210310410510613 unmodified lines1201211221231241254 unmodified lines1301311321331341351368 unmodified linesfrom chess import STARTING_BOARD_FENimport subprocess# --- Start of new code to set Stockfish path ---stockfish_folder = os.path.join(os.path.dirname(__file__), 'stockfish')stockfish_path = None11 unmodified linesprint(f"Set CHESS_ENGINE_PATH to: {stockfish_path}")else:print(f"Warning: Stockfish binary not found at '{stockfish_path}'. Please ensure it's in the correct location or in system PATH.")# --- End of new code ---def on_load(log_msgs):log_msgs.append("🔒 Waiting for input")45 unmodified lineslog_msgs.append(log_msg)return gr.update(selected=2), fens, svg, 0, "", log_msgsdef analyze_game(pgn, log_msgs):"""Analyze the chess game"""# Analyze openingopening = chess_engine.get_opening(pgn)9 unmodified lines{opening["pgn"]}"""svg = chess_engine.render_board(opening["fen"], 150)log_msgs.append("⏳ Start chess engine")yield opening_text, svg, {}, "", "", log_msgs# evaluate chess game with stockfishanalysis, critical = asyncio.run(chess_engine.analyze_pgn(pgn))13 unmodified linesreturn opening_text, svg, analysis, critical_moments_str, gr.update(value=key_insights), log_msgsdef go_back(log_msgs):"""Go back to import game page"""log_msgs = ["🔒 Waiting for input"]4 unmodified linesgame_examples = load_examples()# UI Componentswith gr.Blocks() as demo:move_index = gr.State(0)fen_list = gr.State([])log_msgs = gr.State([])8 unmodified lines9101112131411 unmodified lines26272829303145 unmodified lines77787980818283849 unmodified lines94959697989910010110210310413 unmodified lines1181191201211221231241251261271281294 unmodified lines1341351361371381391408 unmodified linesfrom chess import STARTING_BOARD_FENimport subprocessstockfish_folder = os.path.join(os.path.dirname(__file__), 'stockfish')stockfish_path = None11 unmodified linesprint(f"Set CHESS_ENGINE_PATH to: {stockfish_path}")else:print(f"Warning: Stockfish binary not found at '{stockfish_path}'. Please ensure it's in the correct location or in system PATH.")def on_load(log_msgs):log_msgs.append("🔒 Waiting for input")45 unmodified lineslog_msgs.append(log_msg)return gr.update(selected=2), fens, svg, 0, "", log_msgsdef analyze_opening(pgn, log_msgs):"""Analyze the chess game opening"""# Analyze openingopening = chess_engine.get_opening(pgn)9 unmodified lines{opening["pgn"]}"""svg_opening = chess_engine.render_board(opening["fen"], 150)log_msgs.append("⏳ Start chess engine")yield opening_text, svg_opening, {}, "", "", log_msgs# evaluate chess game with stockfishanalysis, critical = asyncio.run(chess_engine.analyze_pgn(pgn))13 unmodified linesreturn opening_text, svg, analysis, critical_moments_str, gr.update(value=key_insights), log_msgsdef get_key_insights(pgn):passdef get_lessons(pgn):passdef go_back(log_msgs):"""Go back to import game page"""log_msgs = ["🔒 Waiting for input"]4 unmodified linesgame_examples = load_examples()# UI Componentswith gr.Blocks(theme=gr.themes.Default(), css=".gradio-container { max-width: 100% !important; }") as demo:move_index = gr.State(0)fen_list = gr.State([])log_msgs = gr.State([])
3 unmodified lines45673 unmodified linesdotenvchessfastmcpredis3 unmodified lines4563 unmodified linesdotenvchessfastmcp
README.md+60-9
app.py+11-7
requirements.txt-1