Fix: Replace deprecated cached_path usage with hf_hub_download

#2
Files changed (1) hide show
  1. README.md +12 -5
README.md CHANGED
@@ -64,21 +64,28 @@ Usage
64
  #!pip install transformers==4.20.0
65
  #!pip install https://github.com/kpu/kenlm/archive/master.zip
66
  #!pip install pyctcdecode==0.4.0
67
- from transformers.file_utils import cached_path, hf_bucket_url
 
68
  from importlib.machinery import SourceFileLoader
69
  from transformers import Wav2Vec2ProcessorWithLM
70
- from IPython.lib.display import Audio
71
  import torchaudio
72
  import torch
 
 
73
 
74
  # Load model & processor
75
  model_name = "nguyenvulebinh/wav2vec2-base-vi-vlsp2020"
76
  # model_name = "nguyenvulebinh/wav2vec2-large-vi-vlsp2020"
77
- model = SourceFileLoader("model", cached_path(hf_bucket_url(model_name,filename="model_handling.py"))).load_module().Wav2Vec2ForCTC.from_pretrained(model_name)
78
- processor = Wav2Vec2ProcessorWithLM.from_pretrained(model_name)
 
 
 
79
 
80
  # Load an example audio (16k)
81
- audio, sample_rate = torchaudio.load(cached_path(hf_bucket_url(model_name, filename="t2_0000006682.wav")))
 
82
  input_data = processor.feature_extractor(audio[0], sampling_rate=16000, return_tensors='pt')
83
 
84
  # Infer
 
64
  #!pip install transformers==4.20.0
65
  #!pip install https://github.com/kpu/kenlm/archive/master.zip
66
  #!pip install pyctcdecode==0.4.0
67
+ #from transformers.file_utils import cached_path, hf_bucket_url
68
+ from huggingface_hub import hf_hub_download
69
  from importlib.machinery import SourceFileLoader
70
  from transformers import Wav2Vec2ProcessorWithLM
71
+ from IPython.display import Audio
72
  import torchaudio
73
  import torch
74
+ import kenlm
75
+
76
 
77
  # Load model & processor
78
  model_name = "nguyenvulebinh/wav2vec2-base-vi-vlsp2020"
79
  # model_name = "nguyenvulebinh/wav2vec2-large-vi-vlsp2020"
80
+ #model = SourceFileLoader("model", cached_path(hf_bucket_url(model_name,filename="model_handling.py"))).load_module().Wav2Vec2ForCTC.from_pretrained(model_name)
81
+ #processor = Wav2Vec2ProcessorWithLM.from_pretrained(model_name)
82
+
83
+ model_file = hf_hub_download(model_name, filename="model_handling.py")
84
+ audio_file = hf_hub_download(model_name, filename="t2_0000006682.wav")
85
 
86
  # Load an example audio (16k)
87
+ #audio, sample_rate = torchaudio.load(cached_path(hf_bucket_url(model_name, filename="t2_0000006682.wav")))
88
+ audio, sample_rate = torchaudio.load(audio_file)
89
  input_data = processor.feature_extractor(audio[0], sampling_rate=16000, return_tensors='pt')
90
 
91
  # Infer