Spaces:
Sleeping
Sleeping
from langchain_core.tools import tool | |
from image_to_text_tool import image_to_text | |
from utils import get_base64 | |
from typing import Literal | |
def convert_chessboard_image_to_fen(chessboard_image_base64_path: str, current_player: Literal["black", "white"]) -> str: | |
""" | |
Given the path to a file with a chessboard image in base64, returns the FEN description of the chessboard. | |
Args: | |
image_path: Path to the image file with the chessboard. | |
current_player: Whose turn it is to play. Must be either 'black' or 'white'. | |
Returns: | |
JSON with FEN (Forsyth-Edwards Notation) string representing the current board position. | |
""" | |
chessboard_image_base64_str = get_base64(chessboard_image_base64_path) | |
print("Calling chessboard description") | |
fen = image_to_text.invoke( | |
{ | |
"image_base64_str": chessboard_image_base64_str, | |
"instructions": f'Return the fen notation of this chessboard. Assume {current_player} will play.' | |
} | |
) | |
print("FEN returned: " + fen) | |
#gabarito do FEN: 3r2k1/pp3pp1/4b2p/7Q/3n4/PqBBR2P/5PP1/6K1 b - - 0 1 | |