ASR-FairBench-Server / utils /model_validity.py
satyamr196's picture
1) added model id sanitization i.e. removing invaid character as per hugging face \
fdc104d
raw
history blame
666 Bytes
from huggingface_hub import model_info
from huggingface_hub.utils import RepositoryNotFoundError
import re
def is_valid_asr_model(model_id: str) -> bool:
try:
model_id = re.sub(r"[^a-zA-Z0-9/_\-.]", "", model_id) # Sanitize the model ID
info = model_info(model_id)
# Optionally check if it's an ASR model (i.e., "automatic-speech-recognition" in the tags)
return "automatic-speech-recognition" in info.tags
except RepositoryNotFoundError:
return False
# Test examples
# print(is_valid_asr_model("facebook/hubert-large-ls960-ft")) # True
# print(is_valid_asr_model("facebook/hubert-largeXX-ls960-ft")) # False