stable-diffusion-paperspace/sd-concepts-library_Exporte...

109 lines
3.0 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "269953b9-0933-4acc-b3b9-f6637d55008d",
"metadata": {},
"source": [
"# `sd-concepts-library` Exporter\n",
"\n",
"Download every Stable Diffusion textual inversion model from `sd-concepts-library`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d83832f8-2ed8-470b-826e-164befb0753c",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"# Install\n",
"%cd /notebooks/\n",
"!pip install huggingface-hub\n",
"!apt update\n",
"!apt install -y git-lfs\n",
"!mkdir -p /notebooks/sd-concepts-library\n",
"!mkdir -p /notebooks/sd-concepts-library/repositories"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6dbd2aa-56ec-4ac8-987e-848afe017a68",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"%cd /notebooks/sd-concepts-library\n",
"from huggingface_hub import HfApi\n",
"\n",
"api = HfApi()\n",
"models_list = api.list_models(author=\"sd-concepts-library\", sort=\"likes\", direction=-1)\n",
"print('Downloading', len(models_list), 'models...')\n",
"\n",
"i = 1\n",
"for model_info in models_list:\n",
" print(f'\\nCloning {model_info.modelId} | {i}/{len(models_list)}')\n",
" model_name = model_info.modelId.replace('sd-concepts-library/', '')\n",
" !git clone --depth=1 https://huggingface.co/{model_info.modelId} /notebooks/sd-concepts-library/repositories/{model_name}\n",
" !rm -rf /notebooks/sd-concepts-library/repositories/{model_name}/.git*\n",
" !mv /notebooks/sd-concepts-library/repositories/{model_name}/learned_embeds.bin /notebooks/sd-concepts-library/{model_name}.pt\n",
" i = i + 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ad2bafd-dcad-4012-a6e4-ee298715019f",
"metadata": {},
"outputs": [],
"source": [
"!apt update\n",
"!apt install -y p7zip-full\n",
"from datetime import datetime\n",
"import os\n",
"datetime_str = datetime.now().strftime('%m-%d-%Y_%H:%M:%S')\n",
"%cd /notebooks/\n",
"print('Compressing, please wait...')\n",
"os.system(f'7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on sd-concepts-library_{datetime_str}.7z sd-concepts-library/')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cb7bdb05-8a84-4184-8d4c-31404a554d53",
"metadata": {},
"outputs": [],
"source": [
"!rm -rf /notebooks/sd-concepts-library"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}