rafaaa2105 commited on
Commit
2b9af99
·
verified ·
1 Parent(s): e3aba0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -23
app.py CHANGED
@@ -5,35 +5,17 @@ import tempfile
5
  import spaces
6
  import torch
7
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
 
8
  from datasets import load_dataset
 
9
 
10
 
11
  @spaces.GPU
12
  def transcribe_audio(zip_file):
13
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
14
- torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
15
-
16
- model_id = "distil-whisper/distil-large-v3"
17
-
18
- model = AutoModelForSpeechSeq2Seq.from_pretrained(
19
- model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
20
- )
21
- model.to(device)
22
-
23
- processor = AutoProcessor.from_pretrained(model_id)
24
-
25
- transcribe = pipeline(
26
- "automatic-speech-recognition",
27
- model=model,
28
- tokenizer=processor.tokenizer,
29
- feature_extractor=processor.feature_extractor,
30
- max_new_tokens=128,
31
- torch_dtype=torch_dtype,
32
- device=device,
33
- )
34
-
35
- dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
36
 
 
37
 
38
  # Create a temporary directory to extract the ZIP file
39
  with tempfile.TemporaryDirectory() as temp_dir:
 
5
  import spaces
6
  import torch
7
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
8
+ from huggingface_hub import hf_hub_download
9
  from datasets import load_dataset
10
+ from whisper import load_model, transcribe
11
 
12
 
13
  @spaces.GPU
14
  def transcribe_audio(zip_file):
15
+ model_path = hf_hub_download(repo_id="distil-whisper/distil-large-v3-openai", filename="model.bin")
16
+ model = load_model(model_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
19
 
20
  # Create a temporary directory to extract the ZIP file
21
  with tempfile.TemporaryDirectory() as temp_dir: