Nioi's picture
placeholder until chess notation is figured out
70fdc68
raw
history blame
1.35 kB
from smolagents import tool
import whisper
import requests
STOCKFISH_API_URL = "https://stockfish.online/api/s/v2.php"
MODEL = whisper.load_model("tiny")
@tool
def transcribe_audio(file_path: str) -> str:
"""
Extract MP3 file content and return it as text. Supported file extensions: .mp3
Args:
file_path: the path to the mp3 file.
"""
result = None
try:
result = MODEL.transcribe(file_path)
except Exception as e:
return f"Error transcribing file: {str(e)}"
return result['text']
#@tool
def get_fen(file_path:str) -> str:
"""
Extract Chess Board Image file content and return a string representing the board in FEN notation. Supported file extensions: .png
Args:
file_path: the path to the chess board image file.
"""
fen = None
try:
fen = file_path
except Exception as e:
return f"Error decoding image file: {str(e)}"
return fen
#@tool
def get_best_chess_move(fen: str) -> str:
"""
Return the best chess move provided the FEN notation of the board.
Args:
fen: FEN string to analyze.
"""
data = None
try:
response = requests.get(STOCKFISH_API_URL, {"fen":fen, "depth":8})
response.raise_for_status()
data = response.json()
except Exception as e:
return f"Error fetching best move: {str(e)}"
return data.get('bestmove').split(' ')[1].strip()