Spaces:
Sleeping
Sleeping
Download video_translation.py from Synnove/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 628 Bytes
-
https://huggingface.co/spaces/Synnove/Final_Assignment_Template/resolve/main/video_translation.py
- Command line
-
hf download hf://spaces/Synnove/Final_Assignment_Template/video_translation.py
-
curl -L -o video_translation.py https://huggingface.co/spaces/Synnove/Final_Assignment_Template/resolve/main/video_translation.py
628 Bytes
| from smolagents.tools import Tool | |
| from huggingface_hub import InferenceClient | |
| class AudioTranscriptionTool(Tool): | |
| name = "audio_transcription" | |
| description = "Transcribes speech from an audio file (e.g., MP3)" | |
| inputs = {"audio_path": {"type": "string", "description": "Path to the audio file"}} | |
| output_type = "string" | |
| def __init__(self): | |
| super().__init__() | |
| self.client = InferenceClient("openai/whisper-large-v3") | |
| def forward(self, audio_path: str) -> str: | |
| with open(audio_path, "rb") as f: | |
| transcript = self.client.audio_to_text(f) | |
| return transcript["text"] |