Skip to content

Commit

Permalink
Adding logic to invalidate HF id (#2992)
Browse files Browse the repository at this point in the history
* adding hf validation to the sdk

* adding comments

* reverting to main changes

* fix formatting issues

* using the model filter to filter models

* fixing the typo

* fixing formatting issues
  • Loading branch information
jpmann authored Feb 12, 2024
1 parent c24109c commit ac10f8c
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,29 @@
"TOKEN = None"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4208871d",
"metadata": {},
"outputs": [],
"source": [
"# Check if the MODEL_ID passed is a valid HuggingFace ID\n",
"from huggingface_hub import HfApi, ModelFilter\n",
"\n",
"hf_api = HfApi()\n",
"model_infos = hf_api.list_models(filter=ModelFilter(model_name=MODEL_ID))\n",
"model_info = [info for info in model_infos if info.modelId == MODEL_ID]\n",
"valid_hf_id = False\n",
"if model_info and model_info[0].modelId == MODEL_ID:\n",
" valid_hf_id = True\n",
"\n",
"if not valid_hf_id:\n",
" raise ValueError(\n",
" \"Found invalid HF ID. Please select the correct HF ID and try again.\"\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit ac10f8c

Please sign in to comment.