Add model downloader

This commit is contained in:
Cyberes 2022-11-21 02:07:10 -07:00
parent 0a90822768
commit 01009cc156
No known key found for this signature in database
GPG Key ID: 194A1C358AACFC39
1 changed files with 59 additions and 4 deletions

View File

@ -209,10 +209,12 @@
" !git clone https://github.com/crowsonkb/k-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/k-diffusion\"\n",
" !git clone https://github.com/Hafiidz/latent-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion\"\n",
"\n",
"# For things in this notebook\n",
"!pip install requests\n",
" \n",
"# Download popular custom scripts. This is basically remote code execution so be careful.\n",
"# See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts\n",
"if download_scripts:\n",
" !pip install requests\n",
" import shutil\n",
" import requests\n",
" !pip install moviepy==1.0.3\n",
@ -319,7 +321,6 @@
"cell_type": "markdown",
"metadata": {
"id": "F0EINk5M0s-w",
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@ -830,7 +831,7 @@
"%store -r model_storage_dir repo_storage_dir activate_xformers activate_deepdanbooru activate_medvram disable_pickle_check gradio_port gradio_auth ui_theme\n",
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"\n",
"# Enable optional args automatically based on settings\n",
"# Code to set the options you want as defined in the very first block\n",
"x_arg = '--xformers' if activate_xformers else ''\n",
"dd_arg = '--deepdanbooru' if activate_deepdanbooru else ''\n",
"mvram_arg = '--medvram' if activate_medvram else ''\n",
@ -1050,6 +1051,60 @@
"# !bash /notebooks/build-xformers.sh [your cuda arch]\n",
"!echo \"COMPLETED!\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Automated Model Downloader\n",
"\n",
"Here's a tool to download a model from a torrent magnet link, web link, or HuggingFace."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r symlink_to_notebooks model_storage_dir repo_storage_dir\n",
"model_uri = input('URI of model to download: ')\n",
"import re\n",
"import requests\n",
"\n",
"def pretty_exit(str):\n",
" print(str)\n",
" raise\n",
"magnet_match = re.search(r'magnet:\\?xt=urn:btih:[A-Za-z0-9&=%.]*', model_uri)\n",
"web_match = re.search(r'(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})', model_uri)\n",
"web_dl_file = None\n",
"if magnet_match:\n",
" !apt update\n",
" !apt install -y aria2\n",
" %cd \"{model_storage_dir}\"\n",
" bash_var = magnet_match[0]\n",
" !aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"{bash_var}\"\n",
" exit\n",
"elif 'https://huggingface.co/' in model_uri:\n",
" response = requests.head(web_match[0], allow_redirects=True)\n",
" if 'octet-stream' not in response.headers['content-type']:\n",
" response = requests.head(web_match[0].replace('/blob/', '/resolve/'), allow_redirects=True)\n",
" if 'octet-stream' not in response.headers['content-type']:\n",
" pretty_exit(f'Wrong content-type: {response.headers[\"content-type\"].split(\";\")[0]}') if 'octet-stream' not in response.headers['content-type'] else None\n",
" else:\n",
" web_dl_file = web_match[0].replace('/blob/', '/resolve/')\n",
" else:\n",
" web_dl_file = web_match[0]\n",
"elif web_match:\n",
" response = requests.head(web_match[0], allow_redirects=True)\n",
" pretty_exit(f'Wrong content-type: {response.headers[\"content-type\"].split(\";\")[0]}') if 'octet-stream' not in response.headers['content-type'] else None\n",
" web_dl_file = web_match[0]\n",
"if web_dl_file is not None:\n",
" %cd \"{model_storage_dir}\"\n",
" !wget \"{web_dl_file}\" \n",
"else:\n",
" print('Could not parse your URI')"
]
}
],
"metadata": {
@ -1075,7 +1130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.9.13"
}
},
"nbformat": 4,