Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
fix: add --no-half-vae back
Browse files Browse the repository at this point in the history
  • Loading branch information
Linaqruf committed Jun 28, 2023
1 parent 81e3b2c commit f819013
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 additions & 37 deletions cagliostro-colab-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"cell_type": "markdown",
"source": [
"[![visitor][visitor-badge]][visitor-stats] \n",
"[![visitor][visitor-badge]][visitor-stats]\n",
"[![ko-fi][ko-fi-badge]][ko-fi-link]\n",
"\n",
"# **Cagliostro Colab UI**\n",
Expand Down Expand Up @@ -46,13 +46,20 @@
"import shutil\n",
"import subprocess\n",
"import threading\n",
"import sys\n",
"from IPython.display import display, HTML\n",
"from google.colab.output import eval_js\n",
"from IPython.utils import capture\n",
"from tqdm import tqdm\n",
"subprocess.run(['pip', 'install', '--upgrade', 'git+https://github.com/Linaqruf/colablib'])\n",
"\n",
"python_version = \".\".join(sys.version.split(\".\")[:2])\n",
"colablib_path = f\"/usr/local/lib/python{python_version}/dist-packages/colablib\"\n",
"if not os.path.exists(colablib_path):\n",
" subprocess.run(['pip', 'install', 'git+https://github.com/Linaqruf/colablib'])\n",
"\n",
"from colablib.colored_print import cprint, print_line\n",
"from colablib.utils import py_utils, config_utils, package_utils\n",
"from colablib.utils.config_utils import pastebin_reader as read\n",
"from colablib.utils.ubuntu_utils import ubuntu_deps\n",
"from colablib.sd_models.downloader import aria2_download\n",
"from colablib.utils.git_utils import update_repo, batch_update, validate_repo, reset_repo, patch_repo\n",
Expand Down Expand Up @@ -84,8 +91,7 @@
"################################\n",
"\n",
"# VAR\n",
"voldemort = base64.b64decode(\"c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==\".encode('ascii')).decode('ascii')\n",
"voldy = base64.b64decode(\"c2Qtd2VidWk=\".encode('ascii')).decode('ascii')\n",
"voldemort, voldy = read(\"kq6ZmHFU\")[:2]\n",
"\n",
"# ROOT DIR\n",
"root_dir = \"/content\"\n",
Expand All @@ -108,7 +114,7 @@
"annotator_dir = os.path.join(extensions_dir, f\"{voldy}-controlnet\", \"annotator\")\n",
"output_subdir = [\"txt2img-images\", \"img2img-images\", \"extras-images\", \"txt2img-grids\", \"img2img-grids\"]\n",
"\n",
"# CONFIG \n",
"# CONFIG\n",
"config_file = os.path.join(repo_dir, \"config.json\")\n",
"ui_config_file = os.path.join(repo_dir, \"ui-config.json\")\n",
"style_path = os.path.join(repo_dir, \"style.css\")\n",
Expand Down Expand Up @@ -147,7 +153,7 @@
"\n",
"def mount_func(directory):\n",
" output_dir = os.path.join(repo_dir, \"outputs\")\n",
" \n",
"\n",
" if mount_drive:\n",
" print_line(80, color=\"green\")\n",
" if not os.path.exists(directory):\n",
Expand All @@ -160,8 +166,8 @@
" return output_dir\n",
"\n",
"def setup_directories():\n",
" for dir in [fused_dir, models_dir, vaes_dir, \n",
" hypernetworks_dir, embeddings_dir, extensions_dir, \n",
" for dir in [fused_dir, models_dir, vaes_dir,\n",
" hypernetworks_dir, embeddings_dir, extensions_dir,\n",
" lora_dir, control_dir, esrgan_dir]:\n",
" os.makedirs(dir, exist_ok=True)\n",
"\n",
Expand Down Expand Up @@ -204,19 +210,19 @@
" if not os.path.exists(repo_dir):\n",
" pre_download(root_dir, package_url, desc, overwrite=False)\n",
" return\n",
" \n",
"\n",
" repo_name, _, current_branch = validate_repo(repo_dir)\n",
" repo_type_lower = repo_type.lower()\n",
" expected_repo_name = repo_type_to_repo_name.get(repo_type_lower)\n",
" \n",
"\n",
" if expected_repo_name == repo_name:\n",
" expected_branch = branch_type_to_branch.get(repo_type_lower)\n",
" if expected_branch is None or expected_branch == current_branch:\n",
" cprint(f\"'{repo_name}' {current_branch if expected_branch else ''} already installed, skipping...\", color=\"green\")\n",
" return\n",
"\n",
" cprint(f\"Another repository exist. Uninstall '{repo_name}'...\", color=\"green\")\n",
" shutil.rmtree(repo_dir) \n",
" shutil.rmtree(repo_dir)\n",
" pre_download(root_dir, package_url, desc)\n",
" except Exception as e:\n",
" cprint(f\"An error occurred: {e}\", color=\"green\")\n",
Expand Down Expand Up @@ -254,7 +260,7 @@
"\n",
" os.chdir(root_dir)\n",
" start_time = time.time()\n",
" \n",
"\n",
" output_dir = mount_func(drive_dir)\n",
"\n",
" gpu_info = py_utils.get_gpu_info(get_gpu_name=True)\n",
Expand All @@ -272,13 +278,13 @@
" print_line(80, color=\"green\")\n",
" install_webui(repo_dir, cprint(f\"Unpacking {repo_type} Webui\", color=\"green\", tqdm_desc=True))\n",
" prepare_environment()\n",
" \n",
"\n",
" configure_output_path(config_file, output_dir, output_subdir)\n",
"\n",
" print_line(80, color=\"green\")\n",
" if update_webui and not commit_hash:\n",
" update_repo(cwd=repo_dir, args=\"-X theirs --rebase --autostash\")\n",
" \n",
"\n",
" setup_directories ()\n",
"\n",
" if commit_hash:\n",
Expand Down Expand Up @@ -326,7 +332,7 @@
" cprint(\" [-] Hires Prompt patch done!\", color=\"green\")\n",
"\n",
" print_line(80, color=\"green\")\n",
" \n",
"\n",
" if update_extensions:\n",
" batch_update(fetch=True, directory=extensions_dir, desc=cprint(f\"Updating extensions\", color=\"green\", tqdm_desc=True))\n",
"\n",
Expand Down Expand Up @@ -404,7 +410,7 @@
" \"Anime\" : \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors\",\n",
" \"Blessed\" : \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors\",\n",
" \"Waifu_Diffusion\" : \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\",\n",
" \"Stable_Diffusion\" : \"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors\", \n",
" \"Stable_Diffusion\" : \"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors\",\n",
"}\n",
"\n",
"def filter_dict_items(dict_items):\n",
Expand All @@ -416,7 +422,7 @@
"\n",
"def main():\n",
" start_time = time.time()\n",
" \n",
"\n",
" download_list = [\n",
" (filter_dict_items(model_dict), models_dir),\n",
" (filter_dict_items(vae_dict), vaes_dir)\n",
Expand Down Expand Up @@ -450,7 +456,7 @@
{
"cell_type": "code",
"source": [
"# @title ## **ControlNet v1.1** \n",
"# @title ## **ControlNet v1.1**\n",
"import time\n",
"import shutil\n",
"import os\n",
Expand All @@ -461,7 +467,7 @@
"from colablib.colored_print import cprint, print_line\n",
"from colablib.utils.py_utils import get_filename\n",
"\n",
"%store -r \n",
"%store -r\n",
"\n",
"# @markdown ### **ControlNet Annotator**\n",
"pre_download_annotator = True # @param {type: 'boolean'}\n",
Expand Down Expand Up @@ -595,7 +601,7 @@
" filename = get_filename(url)\n",
" download(url=url, filename=filename, dst=control_dir)\n",
" cldm_config(os.path.join(dst, filename))\n",
" \n",
"\n",
"def download_annotator(directory, desc):\n",
" for category, urls in tqdm(annotator_dict.items(), desc=cprint(desc, color=\"green\", tqdm_desc=True)):\n",
" if category == \"clip_vision\":\n",
Expand Down Expand Up @@ -633,13 +639,13 @@
" print_line(80, color=\"green\")\n",
" cprint(\" [-] Downloading Custom ControlNet Models...\", color=\"flat_yellow\")\n",
" custom_controlnet_download(custom_controlnet_url, control_dir)\n",
" \n",
"\n",
" print_line(80, color=\"green\")\n",
" elapsed_time = py_utils.calculate_elapsed_time(start_time)\n",
" cprint(f\"Download finished. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
" cprint(\"All is done! Go to the next step.\", color=\"flat_yellow\")\n",
" print_line(80, color=\"green\")\n",
" \n",
"\n",
"main()"
],
"metadata": {
Expand Down Expand Up @@ -678,7 +684,7 @@
"custom_extensions_url = \"\" # @param {'type': 'string'}\n",
"custom_upscaler_url = \"\" # @param {'type': 'string'}\n",
"# @markdown ### <br>`NEW` **Download from Textfile**\n",
"# @markdown - Provide a custom download URL for a `.txt` file instead of using the URL field. Edit the file: `/content/download_list.txt`. \n",
"# @markdown - Provide a custom download URL for a `.txt` file instead of using the URL field. Edit the file: `/content/download_list.txt`.\n",
"# @markdown - Available hashtags: `#model`, `#vae`, `#embedding`, `#lora`, `#hypernetwork`, `#extensions`, `#upscaler`.\n",
"# @markdown - Or you can input your `.txt` file in `custom_download_list_url` below. Works for `pastebin`.\n",
"custom_download_list_url = \"\" # @param {'type': 'string'}\n",
Expand Down Expand Up @@ -710,7 +716,7 @@
"\n",
" cprint(f\"Fusing process started for PATH: '{path}'\", color=\"green\")\n",
" unionfuse(category_dir, path, dst)\n",
" cprint(f\"Fusing process completed. Valid '{key}' folder located at: '{category_dir}' \", color=\"green\") \n",
" cprint(f\"Fusing process completed. Valid '{key}' folder located at: '{category_dir}' \", color=\"green\")\n",
"\n",
"def parse_urls(filename):\n",
" content = read_config(filename)\n",
Expand All @@ -734,14 +740,14 @@
" for key, value in custom_dirs.items():\n",
" urls = value.url.split(\",\") # Split the comma-separated URLs\n",
" dst = value.dst\n",
" \n",
"\n",
" if value.url:\n",
" print_line(80, color=\"green\")\n",
" cprint(f\" [-] Downloading Custom {key}...\", color=\"flat_yellow\")\n",
" \n",
"\n",
" for url in urls:\n",
" url = url.strip() # Remove leading/trailing whitespaces from each URL\n",
" if url != \"\": \n",
" if url != \"\":\n",
" print_line(80, color=\"green\")\n",
" if \"|\" in url:\n",
" url, filename = map(str.strip, url.split(\"|\"))\n",
Expand Down Expand Up @@ -787,7 +793,7 @@
" textfile_path = custom_download_list(custom_download_list_url)\n",
" download_from_textfile(textfile_path)\n",
" custom_download(custom_dirs)\n",
" \n",
"\n",
" elapsed_time = py_utils.calculate_elapsed_time(start_time)\n",
" print_line(80, color=\"green\")\n",
" cprint(f\"Download finished. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
Expand Down Expand Up @@ -824,7 +830,7 @@
"# @markdown ### **Alternative Tunnel**\n",
"# @markdown > Recommended Tunnels: `ngrok` > `gradio` > `cloudflared` > `remotemoe` > `localhostrun` > `googleusercontent`\n",
"select_tunnel = \"multiple\" # @param ['gradio', 'multiple','cloudflared', 'localhostrun', 'remotemoe', \"googleusercontent\"]\n",
"# @markdown > Get your `ngrok_token` [here](https://dashboard.ngrok.com/get-started/your-authtoken) \n",
"# @markdown > Get your `ngrok_token` [here](https://dashboard.ngrok.com/get-started/your-authtoken)\n",
"ngrok_token = \"\" # @param {type: 'string'}\n",
"ngrok_region = \"ap\" # @param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n",
"# @markdown ### **UI/UX Config**\n",
Expand All @@ -836,7 +842,7 @@
"accelerator = \"xformers\" # @param ['xformers', 'opt-sdp-attention', 'opt-sdp-no-mem-attention', 'opt-split-attention']\n",
"auto_select_model = False # @param {type: 'boolean'}\n",
"auto_select_vae = True # @param {type: 'boolean'}\n",
"additional_arguments = \"--lowram --theme dark\" #@param {type: 'string'}\n",
"additional_arguments = \"--lowram --theme dark --no-half-vae\" #@param {type: 'string'}\n",
"\n",
"# GRADIO AUTH\n",
"user = \"cagliostro\"\n",
Expand Down Expand Up @@ -912,7 +918,7 @@
" config[\"state_img2img\"] = [\"prompt\", \"negative_prompt\", \"styles\", \"sampling\", \"resize_mode\", \"sampling_steps\", \"tiling\", \"restore_faces\", \"width\", \"height\", \"batch_count\", \"batch_size\", \"cfg_scale\", \"denoising_strength\"]\n",
" config[\"state_extensions\"] = [\"control-net\"]\n",
"\n",
" quicksettings_values = [\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \n",
" quicksettings_values = [\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\",\n",
" \"use_old_karras_scheduler_sigmas\", \"always_discard_next_to_last_sigma\",\n",
" \"token_merging_ratio\", \"s_min_uncond\"]\n",
"\n",
Expand All @@ -938,7 +944,7 @@
"\n",
"def is_dir_exist(cloned_dir, original_dir):\n",
" if os.path.exists(cloned_dir):\n",
" return cloned_dir \n",
" return cloned_dir\n",
" else:\n",
" return original_dir\n",
"\n",
Expand Down Expand Up @@ -987,7 +993,7 @@
" cprint(f\"No VAEs were found in the directory '{valid_vae_dir}'.\", color=\"yellow\")\n",
" url = \"https://huggingface.co/NoCrypt/resources/resolve/main/any.vae.safetensors\"\n",
" filename = \"Anime.vae.safetensors\"\n",
" aria2_download(url=url, download_dir=valid_vae_dir, filename=filename) \n",
" aria2_download(url=url, download_dir=valid_vae_dir, filename=filename)\n",
" print_line(80, color=\"green\")\n",
" auto_select_vae = True\n",
"\n",
Expand All @@ -998,7 +1004,7 @@
" if auto_select_vae:\n",
" selected_vae = auto_select_file(valid_vae_dir, \"sd_vae\", ('.vae.pt', '.vae.safetensors', '.pt', '.ckpt'))\n",
" cprint(f\"Selected VAE: {selected_vae}\", color=\"green\")\n",
" \n",
"\n",
" print_line(80, color=\"green\")\n",
"\n",
" configure_main_settings(config_file, valid_lora_dir, use_presets, ui_config_file)\n",
Expand All @@ -1008,7 +1014,7 @@
" cprint(\"[-] Username: cagliostro\", color=\"green\")\n",
" cprint(\"[-] Password:\", password, color=\"green\")\n",
" print_line(80, color=\"green\")\n",
" \n",
"\n",
" config = {\n",
" \"enable-insecure-extension-access\": True,\n",
" \"disable-safe-unpickle\" : True,\n",
Expand Down Expand Up @@ -1095,7 +1101,7 @@
" else:\n",
" cprint(\"Debug: Creating folder\", color=\"green\")\n",
" file = drive.CreateFile({\n",
" \"title\": folder_name, \n",
" \"title\": folder_name,\n",
" \"mimeType\": \"application/vnd.google-apps.folder\"\n",
" })\n",
" file.Upload()\n",
Expand Down Expand Up @@ -1142,7 +1148,7 @@
{
"cell_type": "code",
"source": [
"# @title ## **Download Generated Images V2** \n",
"# @title ## **Download Generated Images V2**\n",
"import shutil\n",
"import os\n",
"from IPython.utils import capture\n",
Expand Down

0 comments on commit f819013

Please sign in to comment.