Spaces:
Sleeping
Sleeping
Create video_translation.py
Browse files- video_translation.py +17 -0
video_translation.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents.tools import Tool
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
class AudioTranscriptionTool(Tool):
|
5 |
+
name = "audio_transcription"
|
6 |
+
description = "Transcribes speech from an audio file (e.g., MP3)"
|
7 |
+
inputs = {"audio_path": {"type": "string", "description": "Path to the audio file"}}
|
8 |
+
output_type = "string"
|
9 |
+
|
10 |
+
def __init__(self):
|
11 |
+
super().__init__()
|
12 |
+
self.client = InferenceClient("openai/whisper-large-v3")
|
13 |
+
|
14 |
+
def forward(self, audio_path: str) -> str:
|
15 |
+
with open(audio_path, "rb") as f:
|
16 |
+
transcript = self.client.audio_to_text(f)
|
17 |
+
return transcript["text"]
|