lu1ki commited on
Commit
6999349
1 Parent(s): e906938

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -1,3 +1,36 @@
1
  import gradio as gr
2
 
3
- gr.load("models/openai/whisper-large-v3").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ gr.load("models/openai/whisper-large-v3").launch()
4
+
5
+ import torch
6
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
7
+ from datasets import load_dataset
8
+
9
+
10
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
11
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
12
+
13
+ model_id = "openai/whisper-large-v3"
14
+
15
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
16
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
17
+ )
18
+ model.to(device)
19
+
20
+ processor = AutoProcessor.from_pretrained(model_id)
21
+
22
+ pipe = pipeline(
23
+ "automatic-speech-recognition",
24
+ model=model,
25
+ tokenizer=processor.tokenizer,
26
+ feature_extractor=processor.feature_extractor,
27
+ max_new_tokens=128,
28
+ torch_dtype=torch_dtype,
29
+ device=device,
30
+ )
31
+
32
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
33
+ sample = dataset[0]["audio"]
34
+
35
+ result = pipe(sample)
36
+ print(result["text"])