avans06 commited on
Commit
4f4c582
1 Parent(s): b0efdc6

Enhancing the Execution of torch.hub.load(snakers4/silero-vad) in vad.py

Browse files

Occasionally, torch.hub.load may encounter an HTTP Error 500: Internal Server Error. Now, if the model already exists in the cache directory, it will utilize the cache rather than causing an interruption.

Files changed (1) hide show
  1. src/vad.py +17 -1
src/vad.py CHANGED
@@ -1,5 +1,6 @@
1
  from abc import ABC, abstractmethod
2
  from collections import Counter, deque
 
3
  import time
4
 
5
  from typing import Any, Deque, Iterator, List, Dict
@@ -449,7 +450,22 @@ class VadSileroTranscription(AbstractTranscription):
449
  print("Created Silerio model")
450
 
451
  def _create_model(self):
452
- model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
 
454
  # Silero does not benefit from multi-threading
455
  torch.set_num_threads(1) # JIT
 
1
  from abc import ABC, abstractmethod
2
  from collections import Counter, deque
3
+ import os
4
  import time
5
 
6
  from typing import Any, Deque, Iterator, List, Dict
 
450
  print("Created Silerio model")
451
 
452
  def _create_model(self):
453
+ repo_owner = "snakers4"
454
+ repo_name = "silero-vad"
455
+ ref = "master"
456
+
457
+ try:
458
+ model, utils = torch.hub.load(repo_or_dir=f'{repo_owner}/{repo_name}', model='silero_vad')
459
+ except Exception as e:
460
+ hub_dir = torch.hub.get_dir()
461
+ owner_name_branch = '_'.join([repo_owner, repo_name, ref])
462
+ repo_dir = os.path.join(hub_dir, owner_name_branch)
463
+ if os.path.exists(repo_dir):
464
+ print(f"vad.py: torch.hub.load({repo_owner}/{repo_name}) Exception: {str(e)}, Using cache found in {repo_dir}\n")
465
+ model, utils = torch.hub.load(repo_or_dir=repo_dir, model='silero_vad', source="local")
466
+ else:
467
+ raise
468
+
469
 
470
  # Silero does not benefit from multi-threading
471
  torch.set_num_threads(1) # JIT