Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,32 +8,12 @@ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
from datasets import load_dataset
|
| 10 |
from whisper import load_model, transcribe
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
-
def transcribe_audio(zip_file, progress = gr.Progress(track_tqdm= True)):
|
| 15 |
-
|
| 16 |
-
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 17 |
-
|
| 18 |
-
model_id = "distil-whisper/distil-large-v3"
|
| 19 |
-
|
| 20 |
-
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 21 |
-
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
| 22 |
-
)
|
| 23 |
-
model.to(device)
|
| 24 |
-
|
| 25 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 26 |
-
|
| 27 |
-
pipe = pipeline(
|
| 28 |
-
"automatic-speech-recognition",
|
| 29 |
-
model=model,
|
| 30 |
-
tokenizer=processor.tokenizer,
|
| 31 |
-
feature_extractor=processor.feature_extractor,
|
| 32 |
-
max_new_tokens=128,
|
| 33 |
-
torch_dtype=torch_dtype,
|
| 34 |
-
device=device,
|
| 35 |
-
generate_kwargs={"task": "transcribe"}
|
| 36 |
-
)
|
| 37 |
|
| 38 |
|
| 39 |
# Create a temporary directory to extract the ZIP file
|
|
@@ -48,7 +28,9 @@ def transcribe_audio(zip_file, progress = gr.Progress(track_tqdm= True)):
|
|
| 48 |
# Transcribe each audio file
|
| 49 |
transcriptions = {}
|
| 50 |
for audio_file in audio_files:
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
transcriptions[os.path.basename(audio_file)] = transcription
|
| 53 |
|
| 54 |
return transcriptions
|
|
|
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
from datasets import load_dataset
|
| 10 |
from whisper import load_model, transcribe
|
| 11 |
+
from faster_whisper import WhisperModel
|
| 12 |
|
| 13 |
|
| 14 |
@spaces.GPU
|
| 15 |
+
def transcribe_audio(zip_file, progress = gr.Progress(track_tqdm= True)):
|
| 16 |
+
model = WhisperModel("large-v3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
# Create a temporary directory to extract the ZIP file
|
|
|
|
| 28 |
# Transcribe each audio file
|
| 29 |
transcriptions = {}
|
| 30 |
for audio_file in audio_files:
|
| 31 |
+
segments, info = model.transcribe("audio.mp3")
|
| 32 |
+
for segment in segments:
|
| 33 |
+
return "[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text)
|
| 34 |
transcriptions[os.path.basename(audio_file)] = transcription
|
| 35 |
|
| 36 |
return transcriptions
|