from smolagents.tools import Tool import requests class HFSpeech2TextFromFile(Tool): name = "HFSpeech2TextFromFile" description = "This is a tool that returns text transcription from an audio file path, calling huggingface-api under the hood." inputs = {'filepath': {'type': 'string', 'description': 'Path to audio file'}, 'hf_token': {'type': 'string', 'description': 'your huggingface token to call huggingface api'}, 'model': {'type': 'string', 'description': "optional, the model to call. Optional. Defaults to 'whisper-small.en'", 'nullable': True}} output_type = "string" def forward(self, filepath: str, hf_token: str, \ model: str = "whisper-small.en") -> str: import requests with open(filepath, "rb") as f: data = f.read() response = requests.post( f"https://api-inference.huggingface.co/models/openai/{model}", headers={"Authorization": f"Bearer {hf_token}"}, data=data ) return response.json()['text'] def __init__(self, *args, **kwargs): self.is_initialized = False