Spaces:
Runtime error
Runtime error
Add application file
Browse files- app.py +40 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
4 |
+
|
5 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
6 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
7 |
+
|
8 |
+
model_id = "openai/whisper-large-v3"
|
9 |
+
|
10 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
11 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
12 |
+
)
|
13 |
+
model.to(device)
|
14 |
+
|
15 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
16 |
+
|
17 |
+
pipe = pipeline(
|
18 |
+
"automatic-speech-recognition",
|
19 |
+
model=model,
|
20 |
+
tokenizer=processor.tokenizer,
|
21 |
+
feature_extractor=processor.feature_extractor,
|
22 |
+
max_new_tokens=128,
|
23 |
+
torch_dtype=torch_dtype,
|
24 |
+
device=device,
|
25 |
+
)
|
26 |
+
|
27 |
+
def transcribe(audio):
|
28 |
+
result = pipe(audio)
|
29 |
+
return result["text"]
|
30 |
+
|
31 |
+
demo = gr.Interface(
|
32 |
+
fn=transcribe,
|
33 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
34 |
+
outputs="text",
|
35 |
+
title="Whisper Large-v3 ASR",
|
36 |
+
description="Transcribe audio files using the Whisper large-v3 model"
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
datasets[audio]
|
4 |
+
gradio
|