Spaces:
Sleeping
Sleeping
updated app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,36 @@
|
|
1 |
-
import
|
2 |
-
from transformers import pipeline
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Function to process audio input and transcribe it
|
10 |
@spaces.GPU
|
11 |
def transcribe(audio):
|
12 |
# Load and preprocess the audio
|
13 |
-
|
14 |
-
return
|
15 |
-
|
16 |
|
17 |
# Gradio interface
|
18 |
interface = gr.Interface(
|
|
|
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 = "distil-whisper/distil-large-v3"
|
10 |
+
|
11 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
12 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=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 |
+
max_new_tokens=128,
|
24 |
+
torch_dtype=torch_dtype,
|
25 |
+
device=device,
|
26 |
+
)
|
27 |
|
28 |
# Function to process audio input and transcribe it
|
29 |
@spaces.GPU
|
30 |
def transcribe(audio):
|
31 |
# Load and preprocess the audio
|
32 |
+
result = pipe(sample)
|
33 |
+
return result["text"]
|
|
|
34 |
|
35 |
# Gradio interface
|
36 |
interface = gr.Interface(
|