Spaces:
Running
Running
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 | |