Spaces:
Sleeping
Sleeping
Update app.py (#11)
Browse files- Update app.py (d80627198525c13b25c2760ceeab4fdcae6206d2)
237 unmodified lines23823924024124224224324424424524624724815 unmodified lines2642652662672682692702712722732742752762772782792802812822832845 unmodified lines290291292277293294279295296281297298299300237 unmodified lines m = FEN_RX.search(text) if m: return " ".join(m.group(1).split()) # normalize whitespace
# fallback: sometimes file is just the fen line t = text.strip() t = " ".join(text.strip().split()) if "/" in t and " w " in t or " b " in t: return " ".join(t.split()) return t return None
def _solve_chess_mate_in_one(self, fen: str) -> str | None:15 unmodified lines return san # e.g., "Qg2#" return None
def _mate_in_one_san(self, fen: str) -> str | None: try: board = chess.Board(fen) except Exception: return None # enumerate legal moves; if any leads to mate, return SAN for mv in list(board.legal_moves): board.push(mv) is_mate = board.is_checkmate() san = board.san(mv) board.pop() if is_mate: return san # e.g., "Qg2#" return None
# change the template call to pass task_id as second arg def __call__(self, question: str, task_id: str | None = None) -> str: ql = question.lower()5 unmodified lines
# CHESS fast-path if ("chess" in ql or "algebraic notation" in ql or "diagram" in ql or "board" in ql) and task_id: if ("chess" in ql or "algebraic notation" in ql or "board" in ql) and task_id: file_text = self._fetch_file_text(task_id) fen = self._extract_fen(file_text or "") fen = self._extract_fen(file_text) if fen: san = self._solve_chess_mate_in_one(fen) san = self._mate_in_one_san(fen) if san: return san
app.py+21-5