Spaces:
Paused
Paused
Download routes/analyze.py from SamilG2/BACKEND-CheckScan: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/SamilG2/BACKEND-CheckScan/resolve/main/routes/analyze.py
- Command line
-
hf download hf://spaces/SamilG2/BACKEND-CheckScan/routes/analyze.py
-
curl -L -o analyze.py https://huggingface.co/spaces/SamilG2/BACKEND-CheckScan/resolve/main/routes/analyze.py
1.05 kB
| """Endpoint de análisis: recibe un PGN y devuelve evaluación jugada a jugada.""" | |
| from flask import Blueprint, request, jsonify | |
| from modules.analysis.stockfish_wrapper import analyze_pgn | |
| analyze_bp = Blueprint('analyze', __name__) | |
| def analyze(): | |
| """ | |
| Body JSON: | |
| { "pgn_en": "1. e4 e5 2. Nf3 ...", "depth": 18 (opcional) } | |
| Respuesta: | |
| { "depth": int, "total_moves": int, "moves": [...] } | |
| """ | |
| data = request.get_json(silent=True) or {} | |
| pgn = (data.get('pgn_en') or '').strip() | |
| if not pgn: | |
| return jsonify({'error': "Se esperaba {'pgn_en': '...'}"}), 400 | |
| depth = data.get('depth') | |
| if depth is not None: | |
| try: | |
| depth = int(depth) | |
| if not (1 <= depth <= 30): | |
| return jsonify({'error': 'depth debe estar entre 1 y 30'}), 400 | |
| except (TypeError, ValueError): | |
| return jsonify({'error': 'depth debe ser entero'}), 400 | |
| result = analyze_pgn(pgn, depth=depth) | |
| return jsonify(result) | |