Spaces:
Sleeping
Sleeping
Update app.py
Browse files237 unmodified lines23823924024124224324424524624715 unmodified lines2632642652662672685 unmodified lines274275276277278279280281282283284237 unmodified linesm = FEN_RX.search(text)if m:return " ".join(m.group(1).split()) # normalize whitespace# fallback: sometimes file is just the fen linet = text.strip()if "/" in t and " w " in t or " b " in t:return " ".join(t.split())return Nonedef _solve_chess_mate_in_one(self, fen: str) -> str | None:15 unmodified linesreturn san # e.g., "Qg2#"return None# change the template call to pass task_id as second argdef __call__(self, question: str, task_id: str | None = None) -> str:ql = question.lower()5 unmodified lines# CHESS fast-pathif ("chess" in ql or "algebraic notation" in ql or "diagram" in ql or "board" in ql) and task_id:file_text = self._fetch_file_text(task_id)fen = self._extract_fen(file_text or "")if fen:san = self._solve_chess_mate_in_one(fen)if san:return san237 unmodified lines23823924024124224324424524624724815 unmodified lines2642652662672682692702712722732742752762772782792802812822832845 unmodified lines290291292293294295296297298299300237 unmodified linesm = FEN_RX.search(text)if m:return " ".join(m.group(1).split()) # normalize whitespace# fallback: sometimes file is just the fen linet = " ".join(text.strip().split())if "/" in t and " w " in t or " b " in t:return treturn Nonedef _solve_chess_mate_in_one(self, fen: str) -> str | None:15 unmodified linesreturn san # e.g., "Qg2#"return Nonedef _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 SANfor 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 argdef __call__(self, question: str, task_id: str | None = None) -> str:ql = question.lower()5 unmodified lines# CHESS fast-pathif ("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)if fen:san = self._mate_in_one_san(fen)if san:return san
app.py+21-5