Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
|
|
|
|
|
|
|
4 |
# Load the ASR model using the Hugging Face pipeline
|
5 |
model_id = "riteshkr/quantized-whisper-large-v3" # Update with your model path or ID
|
6 |
-
pipe = pipeline("automatic-speech-recognition", model=model_id)
|
7 |
|
8 |
-
# Define the transcription function
|
9 |
def transcribe_speech(filepath):
|
|
|
|
|
|
|
10 |
output = pipe(
|
11 |
filepath,
|
12 |
max_new_tokens=256,
|
13 |
generate_kwargs={
|
14 |
"task": "transcribe",
|
15 |
"language": "english",
|
16 |
-
},
|
17 |
chunk_length_s=30,
|
18 |
-
batch_size=
|
19 |
)
|
20 |
return output["text"]
|
21 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# Check if a GPU is available and set the device
|
6 |
+
device = 0 if torch.cuda.is_available() else -1
|
7 |
+
|
8 |
# Load the ASR model using the Hugging Face pipeline
|
9 |
model_id = "riteshkr/quantized-whisper-large-v3" # Update with your model path or ID
|
10 |
+
pipe = pipeline("automatic-speech-recognition", model=model_id, device=device)
|
11 |
|
12 |
+
# Define the transcription function with batching support
|
13 |
def transcribe_speech(filepath):
|
14 |
+
# Adjust batch size based on device (smaller batch for CPU)
|
15 |
+
batch_size = 16 if torch.cuda.is_available() else 4
|
16 |
+
|
17 |
output = pipe(
|
18 |
filepath,
|
19 |
max_new_tokens=256,
|
20 |
generate_kwargs={
|
21 |
"task": "transcribe",
|
22 |
"language": "english",
|
23 |
+
},
|
24 |
chunk_length_s=30,
|
25 |
+
batch_size=batch_size, # Dynamic batch size
|
26 |
)
|
27 |
return output["text"]
|
28 |
|