Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,33 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
import gradio as gr
|
3 |
-
from unsloth import FastModel
|
4 |
-
from transformers import WhisperForConditionalGeneration
|
5 |
import torch
|
|
|
|
|
6 |
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
|
16 |
)
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
# Initialize the pipeline correctly
|
21 |
pipe = pipeline(
|
22 |
"automatic-speech-recognition",
|
23 |
model=model,
|
24 |
-
tokenizer=
|
25 |
-
feature_extractor=
|
26 |
-
|
27 |
-
|
28 |
-
torch_dtype=
|
|
|
29 |
)
|
30 |
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
text = pipe(audio)["text"]
|
35 |
-
return text
|
36 |
-
|
37 |
-
|
38 |
-
iface = gr.Interface(
|
39 |
-
fn=transcribe,
|
40 |
-
inputs=gr.Audio(type="filepath"),
|
41 |
-
outputs="text",
|
42 |
-
title="Whisper medium Creole",
|
43 |
-
description="Realtime demo for Haitian Creole speech recognition using a fine-tuned medium small model.",
|
44 |
-
)
|
45 |
-
|
46 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
3 |
+
from datasets import load_dataset
|
4 |
|
5 |
|
6 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
7 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
8 |
+
|
9 |
+
model_id = "openai/whisper-large-v3"
|
10 |
+
|
11 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
12 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
|
|
|
13 |
)
|
14 |
+
model.to(device)
|
15 |
+
|
16 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
17 |
|
|
|
18 |
pipe = pipeline(
|
19 |
"automatic-speech-recognition",
|
20 |
model=model,
|
21 |
+
tokenizer=processor.tokenizer,
|
22 |
+
feature_extractor=processor.feature_extractor,
|
23 |
+
chunk_length_s=30,
|
24 |
+
batch_size=16, # batch size for inference - set based on your device
|
25 |
+
torch_dtype=torch_dtype,
|
26 |
+
device=device,
|
27 |
)
|
28 |
|
29 |
+
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
|
30 |
+
sample = dataset[0]["audio"]
|
31 |
|
32 |
+
result = pipe(sample)
|
33 |
+
print(result["text"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|