Spaces:
Build error
Build error
File size: 1,047 Bytes
595153d 6249bc9 595153d 6249bc9 6472070 195e557 6472070 595153d 6472070 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from abc import ABC, abstractmethod
from transformers import pipeline
class Transcriber(ABC):
@abstractmethod
def transcribe(self, file_path: str) -> str:
pass
class SpanishTranscriber(Transcriber):
def __init__(self, pipe: pipeline) -> None:
self.pipe = pipe
def transcribe(self, file_path: str = "yt_audio.mp3") -> str:
print("Pipe:", self.pipe)
print("Audo file at:", file_path)
transcription = self.pipe(file_path)["text"]
return transcription
class WhisperTranscriber(Transcriber):
def __init__(self, model, without_timestamps: bool=True) -> None:
self.model = model
self.without_timestamps = without_timestamps
def transcribe(self, file_path: str = "yt_audio.mp3") -> str:
print("Model:", self.model)
print("Audo file at:", file_path)
transcription = self.model.transcribe(file_path,
without_timestamps=self.without_timestamps)["text"]
return transcription |