Okto Ramadhan commited on
Commit
0a05936
1 Parent(s): 0a67fd7

Upload Linaqru_Diffusion_.ipynb

Browse files
Files changed (1) hide show
  1. Linaqru_Diffusion_.ipynb +1503 -0
Linaqru_Diffusion_.ipynb ADDED
@@ -0,0 +1,1503 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "view-in-github",
7
+ "colab_type": "text"
8
+ },
9
+ "source": [
10
+ "<a href=\"https://colab.research.google.com/github/0ktoo/Linaqruf-Difusion/blob/main/Linaqru_Diffusion_.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "source": [
16
+ "<center>\n",
17
+ "\n",
18
+ "#<font color=\"#FFD700\">***LINAQRUF DIFFUSION***</font>\n",
19
+ "\n",
20
+ "*Hak cipta © 2023 oleh saya. Notebook ini adalah hasil modifikasi dari notebook milik linaqurf. Saya telah mendapatkan izin untuk melakukan modifikasi ini untuk keperluan pribadi(bukan komersil).\n",
21
+ "kalian wajib mengikuti akun media sosial linaqruf untuk melihat karya-karya hebat lainnya.*\n"
22
+ ],
23
+ "metadata": {
24
+ "id": "rA4rv1H4uMTP"
25
+ }
26
+ },
27
+ {
28
+ "cell_type": "markdown",
29
+ "source": [
30
+ "##<font color=\"#7FFF00\">***1. MEMPERSIAPKAN DATA***</font>\n"
31
+ ],
32
+ "metadata": {
33
+ "id": "fof1qg-QUyFv"
34
+ }
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "source": [
39
+ "#@title ### <font color=\"#FFD700\">***Mempersiapkan Data Stable Diffusion***</font>\n",
40
+ "import os\n",
41
+ "import time\n",
42
+ "import json\n",
43
+ "import base64\n",
44
+ "import shutil\n",
45
+ "import subprocess\n",
46
+ "import threading\n",
47
+ "import sys\n",
48
+ "from IPython.display import display, HTML\n",
49
+ "from google.colab.output import eval_js\n",
50
+ "from IPython.utils import capture\n",
51
+ "from tqdm import tqdm\n",
52
+ "\n",
53
+ "python_version = \".\".join(sys.version.split(\".\")[:2])\n",
54
+ "colablib_path = f\"/usr/local/lib/python{python_version}/dist-packages/colablib\"\n",
55
+ "if not os.path.exists(colablib_path):\n",
56
+ " subprocess.run(['pip', 'install', 'git+https://github.com/Linaqruf/colablib'])\n",
57
+ "\n",
58
+ "from colablib.colored_print import cprint, print_line\n",
59
+ "from colablib.utils import py_utils, config_utils, package_utils\n",
60
+ "from colablib.utils.config_utils import pastebin_reader as read\n",
61
+ "from colablib.utils.ubuntu_utils import ubuntu_deps\n",
62
+ "from colablib.sd_models.downloader import aria2_download\n",
63
+ "from colablib.utils.git_utils import update_repo, batch_update, validate_repo, reset_repo, patch_repo\n",
64
+ "\n",
65
+ "%store -r\n",
66
+ "\n",
67
+ "\n",
68
+ "################################\n",
69
+ "# COLAB ARGUMENTS GOES HERE\n",
70
+ "################################\n",
71
+ "\n",
72
+ "#@markdown ### <font color=\"#00CED\">***Sambungkan ke Google Drive***</font>\n",
73
+ "mount_drive = False # @param {type:'boolean'}\n",
74
+ "output_drive_folder = \"cagliostro-colab-ui/outputs\" #@param {type:'string'}\n",
75
+ "#@markdown ### <font color=\"#00CED\">***Repo Config/Pilih Jenis UI***</font>\n",
76
+ "repo_type = \"AUTOMATIC1111\" #@param [\"AUTOMATIC1111\", \"AUTOMATIC1111-Dev\", \"Anapnoe\"]\n",
77
+ "update_webui = False # @param {type:'boolean'}\n",
78
+ "update_extensions = False # @param {type:'boolean'}\n",
79
+ "commit_hash = \"\" # @param {type:'string'}\n",
80
+ "dpmpp_2m_v2_patch = True # @param {type:'boolean'}\n",
81
+ "#@markdown ### <font color=\"#00CED\">***Optimization Config***</font>\n",
82
+ "# @markdown > Tidak disarankan untuk `Mencentang` di bawah ini jika Anda memiliki langganan Colab Pro.\n",
83
+ "ram_alloc_patch = True # @param {type:'boolean'}\n",
84
+ "colab_optimizations = True # @param {type:'boolean'}\n",
85
+ "#@markdown > Centang `mobile_optimizations` Jika Kalian Pengguna Handphone/Mobile\n",
86
+ "mobile_optimizations = True # @param {type:'boolean'}\n",
87
+ "\n",
88
+ "################################\n",
89
+ "# DIRECTORY CONFIG\n",
90
+ "################################\n",
91
+ "\n",
92
+ "# VAR\n",
93
+ "voldemort, voldy = read(\"kq6ZmHFU\")[:2]\n",
94
+ "\n",
95
+ "# ROOT DIR\n",
96
+ "root_dir = \"/content\"\n",
97
+ "drive_dir = os.path.join(root_dir, \"drive\", \"MyDrive\")\n",
98
+ "repo_dir = os.path.join(root_dir, \"cagliostro-colab-ui\")\n",
99
+ "tmp_dir = os.path.join(root_dir, \"tmp\")\n",
100
+ "patches_dir = os.path.join(root_dir, \"patches\")\n",
101
+ "deps_dir = os.path.join(root_dir, \"deps\")\n",
102
+ "fused_dir = os.path.join(root_dir, \"fused\")\n",
103
+ "\n",
104
+ "# REPO DIR\n",
105
+ "models_dir = os.path.join(repo_dir, \"models\", \"Stable-diffusion\")\n",
106
+ "vaes_dir = os.path.join(repo_dir, \"models\", \"VAE\")\n",
107
+ "hypernetworks_dir = os.path.join(repo_dir, \"models\", \"hypernetworks\")\n",
108
+ "lora_dir = os.path.join(repo_dir, \"models\", \"Lora\")\n",
109
+ "control_dir = os.path.join(repo_dir, \"models\", \"ControlNet\")\n",
110
+ "esrgan_dir = os.path.join(repo_dir, \"models\", \"ESRGAN\")\n",
111
+ "embeddings_dir = os.path.join(repo_dir, \"embeddings\")\n",
112
+ "extensions_dir = os.path.join(repo_dir, \"extensions\")\n",
113
+ "annotator_dir = os.path.join(extensions_dir, f\"{voldy}-controlnet\", \"annotator\")\n",
114
+ "output_subdir = [\"txt2img-images\", \"img2img-images\", \"extras-images\", \"txt2img-grids\", \"img2img-grids\"]\n",
115
+ "\n",
116
+ "# CONFIG\n",
117
+ "config_file = os.path.join(repo_dir, \"config.json\")\n",
118
+ "ui_config_file = os.path.join(repo_dir, \"ui-config.json\")\n",
119
+ "style_path = os.path.join(repo_dir, \"style.css\")\n",
120
+ "download_list = os.path.join(root_dir, \"download_list.txt\")\n",
121
+ "\n",
122
+ "\n",
123
+ "################################\n",
124
+ "# REPO TYPE CONFIG\n",
125
+ "################################\n",
126
+ "\n",
127
+ "repo_type_lower = repo_type.lower()\n",
128
+ "\n",
129
+ "package_url = [\n",
130
+ " f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui.tar.lz4\",\n",
131
+ " f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui-deps.tar.lz4\",\n",
132
+ " f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui-cache.tar.lz4\",\n",
133
+ "]\n",
134
+ "\n",
135
+ "repo_type_to_repo_name = {\n",
136
+ " \"anapnoe\" : f\"anapnoe/{voldemort}-ux\",\n",
137
+ " \"automatic1111\" : f\"AUTOMATIC1111/{voldemort}\",\n",
138
+ " \"automatic1111-dev\" : f\"AUTOMATIC1111/{voldemort}\",\n",
139
+ "}\n",
140
+ "\n",
141
+ "branch_type_to_branch = {\n",
142
+ " \"automatic1111\" : \"master\",\n",
143
+ " \"automatic1111-dev\" : \"dev\"\n",
144
+ "}\n",
145
+ "\n",
146
+ "with capture.capture_output() as cap:\n",
147
+ " for dir in [\"root_dir\", \"fused_dir\", \"repo_dir\", \"tmp_dir\", \"models_dir\", \"vaes_dir\", \"hypernetworks_dir\", \"embeddings_dir\", \"extensions_dir\", \"lora_dir\", \"control_dir\", \"esrgan_dir\"]:\n",
148
+ " %store {dir}\n",
149
+ " for file in [\"config_file\", \"ui_config_file\", \"style_path\", \"download_list\"]:\n",
150
+ " %store {file}\n",
151
+ " for var in [\"voldemort\", \"voldy\"]:\n",
152
+ " %store {var}\n",
153
+ " del cap\n",
154
+ "\n",
155
+ "def mount_func(directory):\n",
156
+ " output_dir = os.path.join(repo_dir, \"outputs\")\n",
157
+ "\n",
158
+ " if mount_drive:\n",
159
+ " print_line(80, color=\"green\")\n",
160
+ " if not os.path.exists(directory):\n",
161
+ " from google.colab import drive\n",
162
+ " cprint(\"Mounting google drive...\", color=\"green\", reset=False)\n",
163
+ " drive.mount(os.path.dirname(directory))\n",
164
+ " output_dir = os.path.join(directory, output_drive_folder)\n",
165
+ " cprint(\"Set default output path to:\", output_dir, color=\"green\")\n",
166
+ "\n",
167
+ " return output_dir\n",
168
+ "\n",
169
+ "def setup_directories():\n",
170
+ " for dir in [fused_dir, models_dir, vaes_dir,\n",
171
+ " hypernetworks_dir, embeddings_dir, extensions_dir,\n",
172
+ " lora_dir, control_dir, esrgan_dir]:\n",
173
+ " os.makedirs(dir, exist_ok=True)\n",
174
+ "\n",
175
+ "def pre_download(dir, urls, desc, overwrite=False):\n",
176
+ " gpu_info = py_utils.get_gpu_info()\n",
177
+ " version = py_utils.get_python_version().split()[0]\n",
178
+ " major_minor = \".\".join(version.split(\".\")[:2])\n",
179
+ " xformers_version = \"0.0.20\"\n",
180
+ " insightface_version = \"0.7.3\"\n",
181
+ " python_path = f\"/usr/local/lib/python{major_minor}/dist-packages/\"\n",
182
+ " ffmpy_path = os.path.join(python_path, \"ffmpy-0.3.0.dist-info\")\n",
183
+ "\n",
184
+ " for url in tqdm(urls, desc=desc):\n",
185
+ " filename = py_utils.get_filename(url)\n",
186
+ " aria2_download(dir, filename, url, quiet=True)\n",
187
+ " if filename == f\"{repo_type.lower()}-webui-deps.tar.lz4\":\n",
188
+ " package_utils.extract_package(filename, python_path, overwrite=True)\n",
189
+ " else:\n",
190
+ " package_utils.extract_package(filename, \"/\", overwrite=overwrite)\n",
191
+ " os.remove(filename)\n",
192
+ "\n",
193
+ " if os.path.exists(ffmpy_path):\n",
194
+ " shutil.rmtree(ffmpy_path)\n",
195
+ "\n",
196
+ " if not 'T4' in gpu_info:\n",
197
+ " subprocess.run(['pip', 'uninstall', '-y', 'xformers'], check=True)\n",
198
+ " subprocess.run(['pip', 'install', '-q', f'xformers=={xformers_version}'], check=True)\n",
199
+ " subprocess.run(['pip', 'install', '-q', f'insightface=={insightface_version}'], check=True)\n",
200
+ "\n",
201
+ "def install_dependencies():\n",
202
+ " ubuntu_deps_url = \"https://huggingface.co/Linaqruf/fast-repo/resolve/main/ubuntu-deps.zip\"\n",
203
+ " ram_patch_url = \"https://huggingface.co/Linaqruf/fast-repo/resolve/main/ram_patch.zip\"\n",
204
+ "\n",
205
+ " ubuntu_deps(ubuntu_deps_url, deps_dir, cprint(\"Installing ubuntu dependencies\", color=\"green\", tqdm_desc=True))\n",
206
+ "\n",
207
+ " if ram_alloc_patch:\n",
208
+ " subprocess.run([\"apt\", \"install\", 'libunwind8-dev', \"-y\"], check=True)\n",
209
+ " ubuntu_deps(ram_patch_url, deps_dir, cprint(\"Installing RAM allocation patch\", color=\"green\", tqdm_desc=True))\n",
210
+ "\n",
211
+ "def install_webui(repo_dir, desc):\n",
212
+ " try:\n",
213
+ " if not os.path.exists(repo_dir):\n",
214
+ " pre_download(root_dir, package_url, desc, overwrite=False)\n",
215
+ " return\n",
216
+ "\n",
217
+ " repo_name, _, current_branch = validate_repo(repo_dir)\n",
218
+ " repo_type_lower = repo_type.lower()\n",
219
+ " expected_repo_name = repo_type_to_repo_name.get(repo_type_lower)\n",
220
+ "\n",
221
+ " if expected_repo_name == repo_name:\n",
222
+ " expected_branch = branch_type_to_branch.get(repo_type_lower)\n",
223
+ " if expected_branch is None or expected_branch == current_branch:\n",
224
+ " cprint(f\"'{repo_name}' {current_branch if expected_branch else ''} already installed, skipping...\", color=\"green\")\n",
225
+ " return\n",
226
+ "\n",
227
+ " cprint(f\"Another repository exist. Uninstall '{repo_name}'...\", color=\"green\")\n",
228
+ " shutil.rmtree(repo_dir)\n",
229
+ " pre_download(root_dir, package_url, desc)\n",
230
+ " except Exception as e:\n",
231
+ " cprint(f\"An error occurred: {e}\", color=\"green\")\n",
232
+ "\n",
233
+ "def configure_output_path(config_path, output_dir, output_subdir):\n",
234
+ " config = config_utils.read_config(config_path)\n",
235
+ " config_updates = {\n",
236
+ " \"outdir_txt2img_samples\" : os.path.join(output_dir, output_subdir[0]),\n",
237
+ " \"outdir_img2img_samples\" : os.path.join(output_dir, output_subdir[1]),\n",
238
+ " \"outdir_extras_samples\" : os.path.join(output_dir, output_subdir[2]),\n",
239
+ " \"outdir_txt2img_grids\" : os.path.join(output_dir, output_subdir[3]),\n",
240
+ " \"outdir_img2img_grids\" : os.path.join(output_dir, output_subdir[4])\n",
241
+ " }\n",
242
+ "\n",
243
+ " config.update(config_updates)\n",
244
+ " config_utils.write_config(config_path, config)\n",
245
+ "\n",
246
+ " for dir in output_subdir:\n",
247
+ " os.makedirs(os.path.join(output_dir, dir), exist_ok=True)\n",
248
+ "\n",
249
+ "def prepare_environment():\n",
250
+ " cprint(f\"Preparing environment...\", color=\"green\")\n",
251
+ "\n",
252
+ " os.environ[\"colab_url\"] = eval_js(\"google.colab.kernel.proxyPort(7860, {'cache': false})\")\n",
253
+ " os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
254
+ " os.environ[\"SAFETENSORS_FAST_GPU\"] = \"1\"\n",
255
+ " os.environ['PYTORCH_CUDA_ALLOC_CONF'] = \"garbage_collection_threshold:0.9,max_split_size_mb:512\"\n",
256
+ " os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
257
+ "\n",
258
+ "def play_audio(url):\n",
259
+ " display(HTML(f''))\n",
260
+ "\n",
261
+ "def main():\n",
262
+ " global output_dir\n",
263
+ "\n",
264
+ " os.chdir(root_dir)\n",
265
+ " start_time = time.time()\n",
266
+ "\n",
267
+ " output_dir = mount_func(drive_dir)\n",
268
+ "\n",
269
+ " gpu_info = py_utils.get_gpu_info(get_gpu_name=True)\n",
270
+ " python_info = py_utils.get_python_version()\n",
271
+ " torch_info = py_utils.get_torch_version()\n",
272
+ "\n",
273
+ " print_line(80, color=\"green\")\n",
274
+ " cprint(f\" [-] Current GPU:\", gpu_info, color=\"flat_yellow\")\n",
275
+ " cprint(f\" [-] Python\", python_info, color=\"flat_yellow\")\n",
276
+ " cprint(f\" [-] Torch\", torch_info, color=\"flat_yellow\")\n",
277
+ " print_line(80, color=\"green\")\n",
278
+ "\n",
279
+ " install_dependencies()\n",
280
+ "\n",
281
+ " print_line(80, color=\"green\")\n",
282
+ " install_webui(repo_dir, cprint(f\"Unpacking {repo_type} Webui\", color=\"green\", tqdm_desc=True))\n",
283
+ " prepare_environment()\n",
284
+ "\n",
285
+ " configure_output_path(config_file, output_dir, output_subdir)\n",
286
+ "\n",
287
+ " print_line(80, color=\"green\")\n",
288
+ " if update_webui and not commit_hash:\n",
289
+ " update_repo(cwd=repo_dir, args=\"-X theirs --rebase --autostash\")\n",
290
+ "\n",
291
+ " setup_directories ()\n",
292
+ "\n",
293
+ " if commit_hash:\n",
294
+ " reset_repo(repo_dir, commit_hash)\n",
295
+ "\n",
296
+ " repo_name, current_commit_hash, current_branch = validate_repo(repo_dir)\n",
297
+ " cprint(f\"Using '{repo_name}' repository...\", color=\"green\")\n",
298
+ " cprint(f\"Branch: {current_branch}, Commit hash: {current_commit_hash}\", color=\"green\")\n",
299
+ "\n",
300
+ " print_line(80, color=\"green\")\n",
301
+ " cprint(\"Hotfixes and Optimization:\", color=\"green\")\n",
302
+ "\n",
303
+ " if dpmpp_2m_v2_patch:\n",
304
+ " dpmpp_2m_v2_url = \"https://gist.githubusercontent.com/Linaqruf/514d40676e97a70ffc3a2451bbf51555/raw/3fa447ebfac6b98a25485374b70447f848267589/01-add-DPMPP-2M-V2.patch\"\n",
305
+ " patch_repo(url=dpmpp_2m_v2_url, dir=patches_dir, cwd=repo_dir, whitespace_fix=True, quiet=True)\n",
306
+ " shutil.rmtree(patches_dir)\n",
307
+ " cprint(\" [-] DPM++ 2m V2 and DPM++ 2m Karras V2 patch done!\", color=\"green\")\n",
308
+ "\n",
309
+ " if ram_alloc_patch:\n",
310
+ " os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n",
311
+ " cprint(\" [-] Camenduru's ram allocation patch done!\", color=\"green\")\n",
312
+ "\n",
313
+ " if colab_optimizations:\n",
314
+ " lowram_patch_url = \"https://raw.githubusercontent.com/ddPn08/automatic1111-colab/main/patches/stablediffusion-lowram.patch\"\n",
315
+ " stable_diffusion_repo_dir = os.path.join(repo_dir, \"repositories/stable-diffusion-stability-ai\")\n",
316
+ " patch_repo(url=lowram_patch_url, dir=patches_dir, cwd=stable_diffusion_repo_dir, quiet=True)\n",
317
+ " shutil.rmtree(patches_dir)\n",
318
+ " cprint(\" [-] Stable Diffusion V2.x lowram patch done!\", color=\"green\")\n",
319
+ "\n",
320
+ " subprocess.run([\"sed\", \"-i\", f\"s@os.path.splitext(checkpoint_file)@os.path.splitext(checkpoint_file); map_location='cuda'@\", os.path.join(repo_dir, \"modules\", \"sd_models.py\")])\n",
321
+ " subprocess.run([\"sed\", \"-i\", f\"s@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@\", os.path.join(repo_dir, \"webui.py\")])\n",
322
+ " subprocess.run([\"sed\", \"-i\", f\"s@map_location='cpu'@map_location='cuda'@\", os.path.join(repo_dir, \"modules\", \"extras.py\")])\n",
323
+ " cprint(\" [-] TheLastben's colab optimization done!\", color=\"green\")\n",
324
+ "\n",
325
+ " if mobile_optimizations:\n",
326
+ " audio_url = \"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\"\n",
327
+ " audio_thread = threading.Thread(target=play_audio, args=(audio_url,))\n",
328
+ " audio_thread.start()\n",
329
+ " cprint(\" [-] Mobile Optimization done!\", color=\"green\")\n",
330
+ "\n",
331
+ " if \"anapnoe\" in repo_name and \"9931e861dfb128735c4a928a7beb5b5c0af30593\" in current_commit_hash:\n",
332
+ " hires_prompt_fix = \"https://gist.githubusercontent.com/Linaqruf/8fef456d53604f8c3bcd16722ea7d2f6/raw/a3382087c6e32f9a171f4b5e8aeb572a61682801/0001-Add-New-Label-for-Hires-Prompt.patch\"\n",
333
+ " patch_repo(url=hires_prompt_fix, dir=patches_dir, cwd=repo_dir, whitespace_fix=True, quiet=True)\n",
334
+ " shutil.rmtree(patches_dir)\n",
335
+ " cprint(\" [-] Hires Prompt patch done!\", color=\"green\")\n",
336
+ "\n",
337
+ " print_line(80, color=\"green\")\n",
338
+ "\n",
339
+ " if update_extensions:\n",
340
+ " batch_update(fetch=True, directory=extensions_dir, desc=cprint(f\"Updating extensions\", color=\"green\", tqdm_desc=True))\n",
341
+ "\n",
342
+ " if not os.path.exists(download_list):\n",
343
+ " download_list_url = \"https://raw.githubusercontent.com/Linaqruf/sd-notebook-collection/main/config/download_list.txt\"\n",
344
+ " aria2_download(os.path.dirname(download_list), os.path.basename(download_list), download_list_url, quiet=True)\n",
345
+ "\n",
346
+ " elapsed_time = py_utils.calculate_elapsed_time(start_time)\n",
347
+ " print_line(80, color=\"green\")\n",
348
+ " cprint(f\"Finished installation. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
349
+ " cprint(\"All is done! Go to the next step.\", color=\"flat_yellow\")\n",
350
+ " print_line(80, color=\"green\")\n",
351
+ "\n",
352
+ "main()"
353
+ ],
354
+ "metadata": {
355
+ "id": "dMeAsZmWUyFx"
356
+ },
357
+ "execution_count": null,
358
+ "outputs": []
359
+ },
360
+ {
361
+ "cell_type": "markdown",
362
+ "source": [
363
+ "##<font color=\"#7FFF00\">***2. MEMPERSIAPKAN BAHAN***</font>\n"
364
+ ],
365
+ "metadata": {
366
+ "id": "v9md6r0tG0jQ"
367
+ }
368
+ },
369
+ {
370
+ "cell_type": "code",
371
+ "source": [
372
+ "import os\n",
373
+ "import time\n",
374
+ "import base64\n",
375
+ "from datetime import timedelta\n",
376
+ "from IPython.utils import capture\n",
377
+ "from tqdm import tqdm\n",
378
+ "\n",
379
+ "os.chdir(root_dir)\n",
380
+ "\n",
381
+ "\n",
382
+ "#@title ### <font color=\"#FFD700\">**_PILIH MODEL DAN VAE_**</font>\n",
383
+ "\n",
384
+ "#@markdown <font color=\"#00CED1\">**Pilih Model yang akan di gunakan di stable diffusion**:</font>\n",
385
+ "\n",
386
+ "#@markdown <font color=\"#CC3E3E\">**JANGAN CENTANG SEMUA!!!**</font>\n",
387
+ "\n",
388
+ "#@markdown (hapus centang model yang tidak dipakai)\n",
389
+ "anylora = False # @param {type: 'boolean'}\n",
390
+ "Majic_Mix_V5 = True # @param {type: 'boolean'}\n",
391
+ "Chilloutmix = False # @param {type: 'boolean'}\n",
392
+ "PerfectWorld = False #@param {type:\"boolean\"}\n",
393
+ "Figure = False #@param {type:\"boolean\"}\n",
394
+ "RevAnimated = False #@param {type:\"boolean\"}\n",
395
+ "CyberReal = False #@param {type:\"boolean\"}\n",
396
+ "MarvelWhatIf = False #@param {type:\"boolean\"}\n",
397
+ "\n",
398
+ "\n",
399
+ "downloadModels = []\n",
400
+ "\n",
401
+ "\n",
402
+ "models = [\n",
403
+ " (\"anylora\", \"https://huggingface.co/Lykon/AnyLoRA/resolve/main/AnyLoRA_noVae_fp16.safetensors\"),\n",
404
+ " (\"Majic_Mix_V5\", \"https://huggingface.co/Linaqruf/stolen/resolve/main/fp16/majicmixRealistic_v5.safetensors\"),\n",
405
+ " (\"Chilloutmix\", \"https://huggingface.co/AnonPerson/ChilloutMix/resolve/main/ChilloutMix-ni-fp16.safetensors\"),\n",
406
+ " (\"PerfectWorld\", \"https://huggingface.co/ckpt/perfect_world/resolve/main/perfectWorld_v2Baked.safetensors\"),\n",
407
+ " (\"Figure\", \"https://huggingface.co/vorstcavry/figurestyle/resolve/main/figure.safetensors\"),\n",
408
+ " (\"RevAnimated\", \"https://huggingface.co/ckpt/rev-animated/resolve/main/revAnimated_v11.safetensors\"),\n",
409
+ " (\"CyberReal\", \"https://huggingface.co/ckpt/CyberRealistic/resolve/main/cyberrealistic_v13.safetensors\"),\n",
410
+ " (\"MarvelWhatIf\", \"https://huggingface.co/ItsJayQz/Marvel_WhatIf_Diffusion/resolve/main/Marvel_WhatIf_DiffusionV2_whatif_style.safetensors\"),\n",
411
+ "]\n",
412
+ "\n",
413
+ "\n",
414
+ "\n",
415
+ "for model, url in models:\n",
416
+ " if locals()[model]: # if checkbox is checked\n",
417
+ " downloadModels.append((model, url))\n",
418
+ "\n",
419
+ "def download(checkpoint_name, url, is_vae=None, is_control=None):\n",
420
+ " basename = os.path.basename(url)\n",
421
+ " hf_token = \"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\"\n",
422
+ " user_header = f'\"Authorization: Bearer {hf_token}\"'\n",
423
+ " if is_vae:\n",
424
+ " !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {vaes_dir} -o {checkpoint_name}.vae.pt {url}\n",
425
+ " else:\n",
426
+ " if url.startswith(\"https://huggingface.co/\"):\n",
427
+ " ext = \"ckpt\" if url.endswith(\".ckpt\") else \"safetensors\"\n",
428
+ " !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {models_dir} -o {checkpoint_name}.{ext} {url}\n",
429
+ " else:\n",
430
+ " !aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {models_dir} {url}\n",
431
+ "\n",
432
+ "def main():\n",
433
+ " downloaded_model = []\n",
434
+ "\n",
435
+ " for model in tqdm(downloadModels, desc=\"\u001b[1;32mDownloading Models\"):\n",
436
+ " with capture.capture_output() as cap:\n",
437
+ " download(model[0], model[1], is_vae=False)\n",
438
+ " downloaded_model.append(model[0])\n",
439
+ " del cap\n",
440
+ "\n",
441
+ "print(f\"\u001b[1;32mDownloading...\")\n",
442
+ "start_time = time.time()\n",
443
+ "\n",
444
+ "main()\n",
445
+ "\n",
446
+ "end_time = time.time()\n",
447
+ "elapsed_time = int(end_time - start_time)\n",
448
+ "\n",
449
+ "if elapsed_time < 60:\n",
450
+ " print(f\"\\n\u001b[1;32mDownload completed. Took {elapsed_time} sec\")\n",
451
+ "else:\n",
452
+ " mins, secs = divmod(elapsed_time, 60)\n",
453
+ " print(f\"\\n\u001b[1;32mDownload completed. Took {mins} mins {secs} sec\")\n",
454
+ "\n",
455
+ "#install-vae-untuk-model-checkpoint-yang-akan-dipakai\n",
456
+ "#@markdown <font color=\"#00CED1\">**Pilih VAE**:</font> `Rekomendasi VAE : VaeftMse`\n",
457
+ "Pilih_VAE = \"VaeftMse\" #@param [\"VaeftMse\", \"WDv2\", \"ClearVae\", \"Klf8Anime\", \"Klf8Anime2\", \"Nai\", \"OrangeVae\", \"PastelWaifu\"]\n",
458
+ "\n",
459
+ "with open(\"vae.txt\", \"w\") as f:\n",
460
+ " if Pilih_VAE == \"VaeftMse\":\n",
461
+ " f.write(\"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\\n\"\n",
462
+ " \" out=vae-ft-mse-840000-ema-pruned.ckpt\\n\")\n",
463
+ " else:\n",
464
+ " pass\n",
465
+ " if Pilih_VAE == \"WDv2\":\n",
466
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/WD-v2.vae.pt\\n\"\n",
467
+ " \" out=WD-v2.vae.pt\\n\")\n",
468
+ " else:\n",
469
+ " pass\n",
470
+ " if Pilih_VAE == \"ClearVae\":\n",
471
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/clearvae_main.safetensors\\n\"\n",
472
+ " \" out=clearvae_main.safetensors\\n\")\n",
473
+ " else:\n",
474
+ " pass\n",
475
+ " if Pilih_VAE == \"Klf8Anime\":\n",
476
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/kl-f8-anime.ckpt\\n\"\n",
477
+ " \" out=kl-f8-anime.ckpt\\n\")\n",
478
+ " else:\n",
479
+ " pass\n",
480
+ " if Pilih_VAE == \"Klf8Anime2\":\n",
481
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/kl-f8-anime2.ckpt\\n\"\n",
482
+ " \" out=kl-f8-anime2.ckpt\\n\")\n",
483
+ " else:\n",
484
+ " pass\n",
485
+ " if Pilih_VAE == \"Nai\":\n",
486
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/nai.vae.pt\\n\"\n",
487
+ " \" out=nai.vae.pt\\n\")\n",
488
+ " else:\n",
489
+ " pass\n",
490
+ " if Pilih_VAE == \"OrangeVae\":\n",
491
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/orangemix.vae.pt\\n\"\n",
492
+ " \" out=orangemix.vae.pt\\n\")\n",
493
+ " else:\n",
494
+ " pass\n",
495
+ " if Pilih_VAE == \"PastelWaifu\":\n",
496
+ " f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/pastel-waifu-diffusion.vae.pt\\n\"\n",
497
+ " \" out=pastel-waifu-diffusion.vae.pt\\n\")\n",
498
+ " else:\n",
499
+ " pass\n",
500
+ "\n",
501
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --input-file vae.txt -d /content/cagliostro-colab-ui/models/VAE\n",
502
+ "!rm -rf /content/vae.txt\n",
503
+ "\n",
504
+ "print(\"\u001b[1;32mAll is done! Go to the next step\")"
505
+ ],
506
+ "metadata": {
507
+ "id": "15oA4o1eqtbt",
508
+ "cellView": "form"
509
+ },
510
+ "execution_count": null,
511
+ "outputs": []
512
+ },
513
+ {
514
+ "cell_type": "code",
515
+ "source": [
516
+ "import os\n",
517
+ "import time\n",
518
+ "from pydantic import BaseModel\n",
519
+ "from colablib.utils.py_utils import get_filename\n",
520
+ "from colablib.sd_models.downloader import aria2_download, download\n",
521
+ "from colablib.utils.ubuntu_utils import unionfuse\n",
522
+ "from colablib.utils.git_utils import clone_repo\n",
523
+ "from colablib.colored_print import cprint, print_line\n",
524
+ "from colablib.utils.config_utils import read_config\n",
525
+ "\n",
526
+ "%store -r\n",
527
+ "\n",
528
+ "#@title ## <font color=\"#FFD700\">***Custom Download Model,Vae, Embedding, LoRA, Hypernetwork, Ekstension, dan Upscaler***</font>\n",
529
+ "\n",
530
+ "# @markdown\n",
531
+ "# @markdown ### <font color=\"#00CED1\">***Download Bahan tambahan yang kalian inginkan :***</font>\n",
532
+ "# @markdown\n",
533
+ "# @markdown - Jika kalian ingin mendownload lebih dari satu, kalian bisa memsiakannya dengan koma. <font color=\"#00CED1\">**CONTOH**:</font> `url1, url2, url3`.\n",
534
+ "# @markdown - Download dari file Google Drive, gunakan `fuse:` lalu dilanjutkan tata letak foldernya. <font color=\"#00CED1\">**CONTOH**:</font> `fuse:/content/drive/MyDrive/LoRA`.\n",
535
+ "# @markdown - Letakan Salinan jalur model dari Google Drive ke kolom URL untuk menyalin model ke direktori model UI web.\n",
536
+ "custom_model_url = \"\" # @param {'type': 'string'}\n",
537
+ "custom_vae_url = \"\" # @param {'type': 'string'}\n",
538
+ "custom_embedding_url = \"\" # @param {'type': 'string'}\n",
539
+ "custom_LoRA_url = \"\" # @param {'type': 'string'}\n",
540
+ "custom_hypernetwork_url = \"\" # @param {'type': 'string'}\n",
541
+ "custom_extensions_url = \"\" # @param {'type': 'string'}\n",
542
+ "custom_upscaler_url = \"\" # @param {'type': 'string'}\n",
543
+ "# @markdown ### <br>`NEW` <font color=\"#00CED1\">***Download Bahan tambahan yang kalian inginkan dengan list file.txt***\n",
544
+ "# @markdown - Berikan URL unduhan khusus untuk file `.txt` alih-alih menggunakan bidang URL. Mengedit file tersebut: `/content/download_list.txt`.\n",
545
+ "# @markdown - Hastag yang dipakai: `#model`, `#vae`, `#embedding`, `#lora`, `#hypernetwork`, `#extensions`, `#upscaler`.\n",
546
+ "# @markdown - Atau Kalian dapat memasukkan Link file `.txt` di `custom_download_list_url` Untuk Mendownload bahan tambahan secara instan.\n",
547
+ "custom_download_list_url = \"https://huggingface.co/vorstcavry/test/resolve/main/download_list.txt\" # @param {'type': 'string'}\n",
548
+ "\n",
549
+ "\n",
550
+ "class CustomDirs(BaseModel):\n",
551
+ " url: str\n",
552
+ " dst: str\n",
553
+ "\n",
554
+ "custom_dirs = {\n",
555
+ " \"model\" : CustomDirs(url=custom_model_url, dst=models_dir),\n",
556
+ " \"vae\" : CustomDirs(url=custom_vae_url, dst=vaes_dir),\n",
557
+ " \"embedding\" : CustomDirs(url=custom_embedding_url, dst=embeddings_dir),\n",
558
+ " \"lora\" : CustomDirs(url=custom_LoRA_url, dst=lora_dir),\n",
559
+ " \"hypernetwork\": CustomDirs(url=custom_hypernetwork_url, dst=hypernetworks_dir),\n",
560
+ " \"extensions\" : CustomDirs(url=custom_extensions_url, dst=extensions_dir),\n",
561
+ " \"upscaler\" : CustomDirs(url=custom_upscaler_url, dst=esrgan_dir)\n",
562
+ "}\n",
563
+ "\n",
564
+ "def fuse(url, key, dst):\n",
565
+ " if \"extensions\" in key:\n",
566
+ " cprint(f\"Folder can't be fused, skipping...\")\n",
567
+ " return\n",
568
+ "\n",
569
+ " path = url.split(\"fuse:\")[1].strip()\n",
570
+ " category_dir = os.path.join(fused_dir, key)\n",
571
+ " if os.path.exists(category_dir):\n",
572
+ " cprint(f\"Folder '{category_dir}' is already fused, skipping...\", color=\"yellow\")\n",
573
+ " return\n",
574
+ "\n",
575
+ " cprint(f\"Fusing process started for PATH: '{path}'\", color=\"green\")\n",
576
+ " unionfuse(category_dir, path, dst)\n",
577
+ " cprint(f\"Fusing process completed. Valid '{key}' folder located at: '{category_dir}' \", color=\"green\")\n",
578
+ "\n",
579
+ "def parse_urls(filename):\n",
580
+ " content = read_config(filename)\n",
581
+ " lines = content.strip().split('\\n')\n",
582
+ " result = {}\n",
583
+ " key = ''\n",
584
+ " for line in lines:\n",
585
+ " if not line.strip():\n",
586
+ " continue\n",
587
+ " if line.startswith('//'):\n",
588
+ " continue\n",
589
+ " if line.startswith('#'):\n",
590
+ " key = line[1:].lower()\n",
591
+ " result[key] = []\n",
592
+ " else:\n",
593
+ " urls = [url.strip() for url in line.split(',') if url.strip() != '']\n",
594
+ " result[key].extend(urls)\n",
595
+ " return result\n",
596
+ "\n",
597
+ "def custom_download(custom_dirs):\n",
598
+ " for key, value in custom_dirs.items():\n",
599
+ " urls = value.url.split(\",\") # Split the comma-separated URLs\n",
600
+ " dst = value.dst\n",
601
+ "\n",
602
+ " if value.url:\n",
603
+ " print_line(80, color=\"green\")\n",
604
+ " cprint(f\" [-] Downloading Custom {key}...\", color=\"flat_yellow\")\n",
605
+ "\n",
606
+ " for url in urls:\n",
607
+ " url = url.strip() # Remove leading/trailing whitespaces from each URL\n",
608
+ " if url != \"\":\n",
609
+ " print_line(80, color=\"green\")\n",
610
+ " if \"|\" in url:\n",
611
+ " url, filename = map(str.strip, url.split(\"|\"))\n",
612
+ " if not filename.endswith((\".safetensors\", \".ckpt\", \".pt\", \"pth\", \".png\", \".jpeg\", \".jpg\")):\n",
613
+ " filename = filename + os.path.splitext(get_filename(url))[1]\n",
614
+ " else:\n",
615
+ " if not url.startswith(\"fuse:\"):\n",
616
+ " filename = get_filename(url)\n",
617
+ "\n",
618
+ " if url.startswith(\"fuse:\"):\n",
619
+ " fuse(url, key, dst)\n",
620
+ " elif key == \"extensions\":\n",
621
+ " clone_repo(url, cwd=dst)\n",
622
+ " else:\n",
623
+ " download(url=url, filename=filename, dst=dst, quiet=False)\n",
624
+ "\n",
625
+ "def download_from_textfile(filename):\n",
626
+ " for key, urls in parse_urls(filename).items():\n",
627
+ " key_lower = key.lower()\n",
628
+ " if key_lower in custom_dirs:\n",
629
+ " if custom_dirs[key_lower].url:\n",
630
+ " custom_dirs[key_lower].url += ',' + ','.join(urls)\n",
631
+ " else:\n",
632
+ " custom_dirs[key_lower].url = ','.join(urls)\n",
633
+ " else:\n",
634
+ " cprint(f\"Warning: Category '{key}' from the file is not found in custom_dirs.\", color=\"yellow\")\n",
635
+ "\n",
636
+ "def custom_download_list(url):\n",
637
+ " filename = \"custom_download_list.txt\"\n",
638
+ " filepath = os.path.join(root_dir, filename)\n",
639
+ " if os.path.exists(filepath):\n",
640
+ " os.remove(filepath)\n",
641
+ " if 'pastebin.com' in url:\n",
642
+ " if 'raw' not in url:\n",
643
+ " url = url.replace('pastebin.com', 'pastebin.com/raw')\n",
644
+ " download(url=url, filename=filename, dst=root_dir, quiet=True)\n",
645
+ " return filepath\n",
646
+ "\n",
647
+ "def main():\n",
648
+ " start_time = time.time()\n",
649
+ " textfile_path = download_list\n",
650
+ " if custom_download_list_url:\n",
651
+ " textfile_path = custom_download_list(custom_download_list_url)\n",
652
+ " download_from_textfile(textfile_path)\n",
653
+ " custom_download(custom_dirs)\n",
654
+ "\n",
655
+ " elapsed_time = py_utils.calculate_elapsed_time(start_time)\n",
656
+ " print_line(80, color=\"green\")\n",
657
+ " cprint(f\"Download finished. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
658
+ " cprint(\"All is done! Go to the next step.\", color=\"flat_yellow\")\n",
659
+ " print_line(80, color=\"green\")\n",
660
+ "\n",
661
+ "main()"
662
+ ],
663
+ "metadata": {
664
+ "cellView": "form",
665
+ "id": "v-CXDLscV5HM"
666
+ },
667
+ "execution_count": null,
668
+ "outputs": []
669
+ },
670
+ {
671
+ "cell_type": "markdown",
672
+ "source": [
673
+ "##<font color=\"#7FFF00\">***3. INSTALL CONTROLNET DAN EKSTENSION SPESIAL LAINNYA***</font>\n",
674
+ "\n",
675
+ "<small><font color=\"#00CED1\">**bisa di lewati jika tidak diperlukan**:</font> </small></small>\n"
676
+ ],
677
+ "metadata": {
678
+ "id": "6TtktCcHHBmo"
679
+ }
680
+ },
681
+ {
682
+ "cell_type": "code",
683
+ "source": [
684
+ "#@title ## <font color=\"#FFD700\">***Install Controlnet***</font>\n",
685
+ "# @markdown **1.ControlNet Annotator**\n",
686
+ "pre_download_annotator = True # @param {type: 'boolean'}\n",
687
+ "# @markdown **2.Stable Diffusion v1.x ControlNet Model**\n",
688
+ "control_v11_sd15_model = True # @param {type: 'boolean'}\n",
689
+ "# @markdown **3.Stable Diffusion v2.x ControlNet Model**\n",
690
+ "control_v11_sd21_model = True # @param {type: 'boolean'}\n",
691
+ "# @markdown **4.Stable Diffusion text2img ControlNet Model**\n",
692
+ "t2i_adapter_model = True # @param {type: 'boolean'}\n",
693
+ "# @markdown **ControlNet Config** <small><font color=\"#00CED1\">*Bagian Bawah ini Tidak perlu diubah jika belum paham*</font> </small></small>\n",
694
+ "control_net_max_models_num = 2 #@param {type:\"slider\", min:1, max:10, step:1}\n",
695
+ "config_file = os.path.join(repo_dir, \"config.json\")\n",
696
+ "\n",
697
+ "annotator_dict = {\n",
698
+ " \"oneformer\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/150_16_swin_l_oneformer_coco_100ep.pth\",\n",
699
+ " \"oneformer\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/250_16_swin_l_oneformer_ade20k_160k.pth\",\n",
700
+ " \"zoedepth\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/ZoeD_M12_N.pt\",\n",
701
+ " \"midas\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_beit_large_512.pt\",\n",
702
+ " \"midas\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_hybrid-midas-501f0c75.pt\",\n",
703
+ " \"midas\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_large-midas-2f21e586.pt\",\n",
704
+ " \"openpose\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/facenet.pth\",\n",
705
+ " \"openpose\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/hand_pose_model.pth\",\n",
706
+ " \"openpose\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/body_pose_model.pth\",\n",
707
+ " \"keypose\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth\",\n",
708
+ " \"keypose\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth\",\n",
709
+ " \"leres\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/latest_net_G.pth\",\n",
710
+ " \"leres\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/res101.pth\",\n",
711
+ " \"mlsd\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/mlsd_large_512_fp32.pth\",\n",
712
+ " \"lineart_anime\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/netG.pth\",\n",
713
+ " \"hed\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/network-bsds500.pth\",\n",
714
+ " \"normal_bae\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/scannet.pt\",\n",
715
+ " \"lineart\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/sk_model.pth\",\n",
716
+ " \"lineart\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/sk_model2.pth\",\n",
717
+ " \"pidinet\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/table5_pidinet.pth\",\n",
718
+ " \"uniformer\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/upernet_global_small.pth\",\n",
719
+ "}\n",
720
+ "\n",
721
+ "control_v11_sd15_url = [\n",
722
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\",\n",
723
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\",\n",
724
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\",\n",
725
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\",\n",
726
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\",\n",
727
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\",\n",
728
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\",\n",
729
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\",\n",
730
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\",\n",
731
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\",\n",
732
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\",\n",
733
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\",\n",
734
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\",\n",
735
+ " \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\",\n",
736
+ "]\n",
737
+ "\n",
738
+ "control_v11_sd21_url = [\n",
739
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_ade20k.safetensors\",\n",
740
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors\",\n",
741
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_color.safetensors\",\n",
742
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors\",\n",
743
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors\",\n",
744
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_lineart.safetensors\",\n",
745
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_normalbae.safetensors\",\n",
746
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openpose.safetensors\",\n",
747
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors\",\n",
748
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors\",\n",
749
+ " \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_zoedepth.safetensors\"\n",
750
+ "]\n",
751
+ "\n",
752
+ "t2i_adapter_url = [\n",
753
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd14v1.pth\",\n",
754
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd15v2.pth\",\n",
755
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_color_sd14v1.pth\",\n",
756
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd14v1.pth\",\n",
757
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd15v2.pth\",\n",
758
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_keypose_sd14v1.pth\",\n",
759
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_openpose_sd14v1.pth\",\n",
760
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_seg_sd14v1.pth\",\n",
761
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_sketch_sd14v1.pth\",\n",
762
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_sketch_sd15v2.pth\",\n",
763
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_style_sd14v1.pth\",\n",
764
+ " \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_zoedepth_sd15v1.pth\"\n",
765
+ "]\n",
766
+ "\n",
767
+ "def read_config(filename):\n",
768
+ " with open(filename, \"r\") as f:\n",
769
+ " config = json.load(f)\n",
770
+ " return config\n",
771
+ "\n",
772
+ "def write_config(filename, config):\n",
773
+ " with open(filename, \"w\") as f:\n",
774
+ " json.dump(config, f, indent=4)\n",
775
+ "\n",
776
+ "def cldm_config_path(destination_path):\n",
777
+ " if \"control\" in destination_path and \"sd15\" in destination_path:\n",
778
+ " if \"_shuffle_\" in destination_path:\n",
779
+ " return \"control_v11e_sd15_shuffle.yaml\"\n",
780
+ " else:\n",
781
+ " return \"cldm_v15.yaml\"\n",
782
+ " elif \"control\" in destination_path and \"sd21\"in destination_path:\n",
783
+ " return \"cldm_v21.yaml\"\n",
784
+ " elif \"t2i\" in destination_path:\n",
785
+ " adapter_name = os.path.splitext(os.path.basename(destination_path))[0]\n",
786
+ " return adapter_name + \".yaml\"\n",
787
+ " else:\n",
788
+ " return None\n",
789
+ "\n",
790
+ "def cldm_config(destination_path):\n",
791
+ " control_net_model_config = cldm_config_path(destination_path)\n",
792
+ " if control_net_model_config is not None:\n",
793
+ " cldm_config_src = os.path.join(extensions_dir, os.path.join(\"sd-webui-controlnet/models\", control_net_model_config))\n",
794
+ " cldm_config_dst = os.path.splitext(destination_path)[0] + \".yaml\"\n",
795
+ " if not os.path.exists(cldm_config_dst):\n",
796
+ " shutil.copy(cldm_config_src, cldm_config_dst)\n",
797
+ "\n",
798
+ "def download(url, destination_path, is_annotator=None):\n",
799
+ " hf_token = \"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\"\n",
800
+ " user_header = f'\"Authorization: Bearer {hf_token}\"'\n",
801
+ " basename = os.path.basename(url)\n",
802
+ " dst_dir = os.path.join(os.path.dirname(control_dir), destination_path) if is_annotator else destination_path\n",
803
+ " os.makedirs(dst_dir, exist_ok=True)\n",
804
+ " !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {dst_dir} -o {basename} {url}\n",
805
+ " cldm_config(os.path.join(dst_dir, basename))\n",
806
+ "\n",
807
+ "def batch(url, download_description, is_annotator=None):\n",
808
+ " if is_annotator:\n",
809
+ " for dest_path, url in tqdm(annotator_dict.items(), desc=f\"\u001b[1;32mDownloading {download_description}\"):\n",
810
+ " with capture.capture_output() as cap:\n",
811
+ " download(url, dest_path, is_annotator=True)\n",
812
+ " del cap\n",
813
+ " else:\n",
814
+ " for control in tqdm(url, desc=f\"\u001b[1;32mDownloading {download_description}\"):\n",
815
+ " with capture.capture_output() as cap:\n",
816
+ " download(control, control_dir, is_annotator=False)\n",
817
+ " del cap\n",
818
+ "\n",
819
+ "def main():\n",
820
+ " config = read_config(config_file)\n",
821
+ " config[\"control_net_max_models_num\"] = control_net_max_models_num\n",
822
+ " config[\"control_net_models_path\"] = control_dir\n",
823
+ " config[\"control_net_allow_script_control\"] = True\n",
824
+ " write_config(config_file, config)\n",
825
+ "\n",
826
+ " if pre_download_annotator:\n",
827
+ " batch(annotator_dict, \"ControlNet Annotator/Preprocessor\", is_annotator=True)\n",
828
+ " if control_v11_sd15_model:\n",
829
+ " batch(control_v11_sd15_url, \"SDv1.x ControlNet Model\", is_annotator=False)\n",
830
+ " if t2i_adapter_model:\n",
831
+ " batch(t2i_adapter_url, \"SDv1.x Text2Image Adapter Model\", is_annotator=False)\n",
832
+ " if control_v11_sd21_model:\n",
833
+ " batch(control_v11_sd21_url, \"SDv2.x ControlNet Model\", is_annotator=False)\n",
834
+ "\n",
835
+ "print(f\"\u001b[1;32mDownloading...\")\n",
836
+ "start_time = time.time()\n",
837
+ "\n",
838
+ "main()\n",
839
+ "\n",
840
+ "end_time = time.time()\n",
841
+ "elapsed_time = int(end_time - start_time)\n",
842
+ "\n",
843
+ "if elapsed_time < 60:\n",
844
+ " print(f\"\\n\u001b[1;32mDownload completed. Took {elapsed_time} sec\")\n",
845
+ "else:\n",
846
+ " mins, secs = divmod(elapsed_time, 60)\n",
847
+ " print(f\"\\n\u001b[1;32mDownload completed. Took {mins} mins {secs} sec\")\n",
848
+ "\n",
849
+ "print(\"\u001b[1;32mAll is done! Go to the next step\")"
850
+ ],
851
+ "metadata": {
852
+ "cellView": "form",
853
+ "id": "LKKtxDoIIg1T"
854
+ },
855
+ "execution_count": null,
856
+ "outputs": []
857
+ },
858
+ {
859
+ "cell_type": "code",
860
+ "source": [
861
+ "# @title ## **Download Deforum**\n",
862
+ "# @markdown ###**Deforum**\n",
863
+ "\n",
864
+ "#@markdown ###Deforum adalah fitur ekstension spesial di stable diffusion yang dapat membuat video pendek yang menakjubkan dari hasil generate gambar dari sebuah cuplikan video pendek, ataupun dari text untuk membuat karya AI.\n",
865
+ "!git clone https://github.com/deforum-art/deforum-for-automatic1111-$masbro /content/cagliostro-colab-ui/extensions/deforum-for-automatic1111-$masbro\n",
866
+ "!mkdir /content/cagliostro-colab-ui/extensions/deforum-for-automatic1111-$masbro/models\n",
867
+ "!sed -i -e 's/\\\"sd_model_checkpoint\\\"\\,/\\\"sd_model_checkpoint\\,sd_vae\\,CLIP_stop_at_last_layers\\\"\\,/g' /content/cagliostro-colab-ui/modules/shared.py"
868
+ ],
869
+ "metadata": {
870
+ "id": "URRJW7Gm6gCf",
871
+ "cellView": "form"
872
+ },
873
+ "execution_count": null,
874
+ "outputs": []
875
+ },
876
+ {
877
+ "cell_type": "code",
878
+ "source": [
879
+ "# @title ## **Download SD Animation**\n",
880
+ "# @markdown ###**SD Animation**\n",
881
+ "\n",
882
+ "#@markdown ###SD Animation adalah fitur ekstension spesial di stable diffusion yang dapat membuat video animasi AI, untuk pembuatan animasi ai memiliki dua tipe pembuatan(video menjadi animasi AI, dan Text Menjadi Animasi AI)\n",
883
+ "!git clone https://github.com/volotat/SD-CN-Animation /content/cagliostro-colab-ui/extensions/SD-CN-Animation"
884
+ ],
885
+ "metadata": {
886
+ "cellView": "form",
887
+ "id": "mTG_NHlGGn8E"
888
+ },
889
+ "execution_count": null,
890
+ "outputs": []
891
+ },
892
+ {
893
+ "cell_type": "code",
894
+ "source": [
895
+ "# @title ## **Download TemporalKit**\n",
896
+ "# @markdown ###**TemporalKit**\n",
897
+ "\n",
898
+ "#@markdown ###TemporalKit adalah fitur ekstension spesial di stable diffusion yang dapat membuat video pendek yang menakjubkan dari hasil generate gambar dari sebuah cuplikan video pendek, fitur ini mirip seperti deforum\n",
899
+ "!git clone https://github.com/vorstcavry/TemporalKit /content/cagliostro-colab-ui/extensions/TemporalKit"
900
+ ],
901
+ "metadata": {
902
+ "cellView": "form",
903
+ "id": "kybH-cavkMLN"
904
+ },
905
+ "execution_count": null,
906
+ "outputs": []
907
+ },
908
+ {
909
+ "cell_type": "code",
910
+ "source": [
911
+ "# @title ## **Download Photopea** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
912
+ "# @markdown ###**Photopea**\n",
913
+ "\n",
914
+ "#@markdown ###Photopea adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi seperti Photoshop yang dapat digunakan untuk mengedit gambar secara langsung di stable diffusion.\n",
915
+ "!git clone https://github.com/vorstcavry/photopea-embed /content/cagliostro-colab-ui/extensions/photopea"
916
+ ],
917
+ "metadata": {
918
+ "cellView": "form",
919
+ "id": "QrVUPNNJ9_zj"
920
+ },
921
+ "execution_count": null,
922
+ "outputs": []
923
+ },
924
+ {
925
+ "cell_type": "code",
926
+ "source": [
927
+ "# @title ## **Download Open Pose 2D Editor** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
928
+ "# @markdown ###**Open Pose 2D Editor**\n",
929
+ "\n",
930
+ "#@markdown ###Open Pose 2D Editor adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model 2D untuk membuat gambar sesuai dengan pose yang di inginkan\n",
931
+ "!git clone https://github.com/vorstcavry/openpose-editor /content/cagliostro-colab-ui/extensions/openpose-editor\n",
932
+ "!git clone https://github.com/hnmr293/posex /content/cagliostro-colab-ui/extensions/posex"
933
+ ],
934
+ "metadata": {
935
+ "id": "AjrbWxNvltmK",
936
+ "cellView": "form"
937
+ },
938
+ "execution_count": null,
939
+ "outputs": []
940
+ },
941
+ {
942
+ "cell_type": "code",
943
+ "source": [
944
+ "# @title ## **Download Open Pose 3D Editor** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
945
+ "# @markdown ###**Open Pose 3D Editor**\n",
946
+ "\n",
947
+ "#@markdown ###Open Pose 3D Editor adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model 3D untuk membuat gambar sesuai dengan pose yang di inginkan\n",
948
+ "!git clone https://github.com/vorstcavry/3d-open-pose-editor /content/cagliostro-colab-ui/extensions/3d-open-pose-editor"
949
+ ],
950
+ "metadata": {
951
+ "cellView": "form",
952
+ "id": "CezKb0BHjlWO"
953
+ },
954
+ "execution_count": null,
955
+ "outputs": []
956
+ },
957
+ {
958
+ "cell_type": "code",
959
+ "source": [
960
+ "# @title ## **Download Manekin Model Loader** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
961
+ "# @markdown ###**Manekin Model Loader**\n",
962
+ "\n",
963
+ "#@markdown ###Manekin Model Loader adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model Manekin untuk membuat gambar sesuai dengan pose yang di inginkan\n",
964
+ "!git clone https://github.com/vorstcavry/sd-manekin-model-loader /content/cagliostro-colab-ui/extensions/sd-manekin-model-loader"
965
+ ],
966
+ "metadata": {
967
+ "id": "un6YnwGKOvs-",
968
+ "cellView": "form"
969
+ },
970
+ "execution_count": null,
971
+ "outputs": []
972
+ },
973
+ {
974
+ "cell_type": "code",
975
+ "source": [
976
+ "# @title ## **Download SD MOV2MOV**\n",
977
+ "# @markdown ###**SD MOV2MOV**\n",
978
+ "\n",
979
+ "#@markdown ###SD MOV2MOV adalah fitur ekstension spesial di stable diffusion yang dapat membuat Animasi AI dengan prompt dan video\n",
980
+ "!git clone https://github.com/vorstcavry/mov2mov /content/cagliostro-colab-ui/extensions/sd-$masbro-mov2mov"
981
+ ],
982
+ "metadata": {
983
+ "id": "ZWhRKcEomuYB",
984
+ "cellView": "form"
985
+ },
986
+ "execution_count": null,
987
+ "outputs": []
988
+ },
989
+ {
990
+ "cell_type": "markdown",
991
+ "source": [
992
+ "##<font color=\"#7FFF00\">***4. MULAI MENJALANKAN WEB UI***</font>\n"
993
+ ],
994
+ "metadata": {
995
+ "id": "Nyv6g0sNHJaO"
996
+ }
997
+ },
998
+ {
999
+ "cell_type": "code",
1000
+ "source": [
1001
+ "#@title ## <font color=\"#FFD700\">**_Menjalankan Alternative UI_**</font>\n",
1002
+ "!git clone https://github.com/Iyashinouta/sd-model-downloader /content/cagliostro-colab-ui/extensions/sd-model-downloader\n",
1003
+ "!git clone https://github.com/vorstcavry/images-browser /content/cagliostro-colab-ui/extensions/images-browser\n",
1004
+ "\n",
1005
+ "import random\n",
1006
+ "import string\n",
1007
+ "from pydantic import BaseModel\n",
1008
+ "from typing import List, Optional\n",
1009
+ "from colablib.utils import config_utils\n",
1010
+ "from colablib.colored_print import cprint, print_line\n",
1011
+ "from colablib.utils.git_utils import validate_repo\n",
1012
+ "\n",
1013
+ "%store -r\n",
1014
+ "\n",
1015
+ "################################\n",
1016
+ "# ARGUMEN COLAB ADA DI SINI\n",
1017
+ "################################\n",
1018
+ "\n",
1019
+ "\n",
1020
+ "#@markdown ### <font color=\"#00CED1\">**Alternative Tunnel**:</font>\n",
1021
+ "# @markdown > Recommended Tunnels: `ngrok` > `gradio` > `cloudflared` > `remotemoe` > `localhostrun` > `googleusercontent`\n",
1022
+ "select_tunnel = \"multiple\" # @param ['gradio', 'multiple','cloudflared', 'localhostrun', 'remotemoe', \"googleusercontent\"]\n",
1023
+ "# @markdown > dapatkan `ngrok_token` [disini](https://dashboard.ngrok.com/get-started/your-authtoken)\n",
1024
+ "ngrok_token = \"\" # @param {type: 'string'}\n",
1025
+ "ngrok_region = \"in\" # @param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n",
1026
+ "#@markdown ### <font color=\"#00CED1\">**UI/UX Config**:</font>\n",
1027
+ "select_theme = \"minimal_orange\" # @param ['moonlight', 'ogxRed', 'fun', 'ogxCyan', 'ogxCyanInvert', 'ogxBGreen', 'default_orange', 'tron2', 'd-230-52-94', 'minimal', 'ogxRedYellow', 'retrog', 'ogxRedPurple', 'ogxGreen', 'tron', 'default_cyan', 'default', 'backup', 'minimal_orange', 'Golde']\n",
1028
+ "# @markdown > Centang `use_preset` Untuk Menggunakan default prompt, resolusi, sampler, dan pengaturan lainnya\n",
1029
+ "use_presets = True # @param {type: 'boolean'}\n",
1030
+ "#@markdown ### <font color=\"#00CED1\">**Arguments**:</font>\n",
1031
+ "use_gradio_auth = False # @param {type: 'boolean'}\n",
1032
+ "accelerator = \"xformers\" # @param ['xformers', 'opt-sdp-attention', 'opt-sdp-no-mem-attention', 'opt-split-attention']\n",
1033
+ "auto_select_model = True # @param {type: 'boolean'}\n",
1034
+ "auto_select_vae = True # @param {type: 'boolean'}\n",
1035
+ "additional_arguments = \"--lowram --theme dark\" #@param {type: 'string'}\n",
1036
+ "\n",
1037
+ "# GRADIO AUTH\n",
1038
+ "user = \"cagliostro\"\n",
1039
+ "password = \"\".join(random.choices(string.ascii_letters + string.digits, k=6))\n",
1040
+ "\n",
1041
+ "def change_theme(filename):\n",
1042
+ " themes_folder = os.path.join(repo_dir, \"extensions-builtin\", \"sd_theme_editor\", \"themes\")\n",
1043
+ " themes_file = os.path.join(themes_folder, f\"{filename}.css\")\n",
1044
+ "\n",
1045
+ " style_config = config_utils.read_config(style_path)\n",
1046
+ " style_contents = style_config.split(\"/*BREAKPOINT_CSS_CONTENT*/\")[1]\n",
1047
+ "\n",
1048
+ " theme_config = config_utils.read_config(themes_file)\n",
1049
+ " style_data = \":host{\" + theme_config + \"}\" + \"/*BREAKPOINT_CSS_CONTENT*/\" + style_contents\n",
1050
+ " config_utils.write_config(style_path, style_data)\n",
1051
+ "\n",
1052
+ "def is_valid(valid_dir, file_types):\n",
1053
+ " return [f for f in os.listdir(valid_dir) if f.endswith(file_types)]\n",
1054
+ "\n",
1055
+ "def auto_select_file(valid_dir, config_key, file_types):\n",
1056
+ " valid_files = is_valid(valid_dir, file_types)\n",
1057
+ " if valid_files:\n",
1058
+ " file_path = random.choice(valid_files)\n",
1059
+ " if os.path.exists(os.path.join(valid_dir, file_path)):\n",
1060
+ " config = config_utils.read_config(config_file)\n",
1061
+ " config[config_key] = file_path\n",
1062
+ " config_utils.write_config(config_file, config)\n",
1063
+ " return file_path\n",
1064
+ " else:\n",
1065
+ " return None\n",
1066
+ "\n",
1067
+ "def ui_preset_config():\n",
1068
+ " global default_upscaler, default_sampler_v2\n",
1069
+ "\n",
1070
+ " default_prompt = \"masterpiece, best quality,\"\n",
1071
+ " default_neg_prompt = \"(worst quality, low quality:1.4)\"\n",
1072
+ " default_sampler = \"DPM++ 2M Karras\"\n",
1073
+ " default_steps = 20\n",
1074
+ " default_width = 512\n",
1075
+ " default_height = 768\n",
1076
+ " default_strength = 0.55\n",
1077
+ " default_cfg_scale = 7\n",
1078
+ " default_upscaler = \"Latent (nearest-exact)\"\n",
1079
+ "\n",
1080
+ " config = {\n",
1081
+ " \"Prompt/value\" : default_prompt,\n",
1082
+ " \"Negative prompt/value\" : default_neg_prompt,\n",
1083
+ " \"Sampling method/value\" : default_sampler,\n",
1084
+ " \"Sampling steps/value\" : default_steps,\n",
1085
+ " \"Width/value\" : default_width,\n",
1086
+ " \"Height/value\" : default_height,\n",
1087
+ " \"Denoising strength/value\" : default_strength,\n",
1088
+ " \"CFG Scale/value\" : default_cfg_scale\n",
1089
+ " }\n",
1090
+ "\n",
1091
+ " return config\n",
1092
+ "\n",
1093
+ "def configure_main_settings(config_file: str, lora_dir: str, use_presets: bool, ui_config_file: str):\n",
1094
+ " config = config_utils.read_config(config_file)\n",
1095
+ "\n",
1096
+ " config[\"additional_networks_extra_lora_path\"] = lora_dir\n",
1097
+ " config[\"CLIP_stop_at_last_layers\"] = 2\n",
1098
+ " config[\"eta_noise_seed_delta\"] = 0\n",
1099
+ " config[\"show_progress_every_n_steps\"] = 10\n",
1100
+ " config[\"show_progressbar\"] = True\n",
1101
+ " config[\"samples_filename_pattern\"] = \"[model_name]_[seed]\"\n",
1102
+ " config[\"show_progress_type\"] = \"Approx NN\" # Full, Approx NN, TAESD, Approx cheap\n",
1103
+ " config[\"live_preview_content\"] = \"Prompt\" # Combined, Prompt, Negative Prompt\n",
1104
+ " config[\"hires_fix_show_sampler\"] = True\n",
1105
+ " config[\"hires_fix_show_prompts\"] = True\n",
1106
+ " config[\"state\"] = [\"tabs\"]\n",
1107
+ " config[\"state_txt2img\"] = [\"prompt\", \"negative_prompt\", \"styles\", \"sampling\", \"sampling_steps\", \"width\", \"height\", \"batch_count\", \"batch_size\", \"hires_resize_y\", \"hires_resize_x\", \"hires_scale\", \"hires_steps\", \"hires_upscaler\", \"hires_fix\", \"tiling\", \"restore_faces\", \"cfg_scale\", \"hires_denoising_strength\"]\n",
1108
+ " 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",
1109
+ " config[\"state_extensions\"] = [\"control-net\"]\n",
1110
+ "\n",
1111
+ " quicksettings_values = [\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\",\n",
1112
+ " \"use_old_karras_scheduler_sigmas\", \"always_discard_next_to_last_sigma\",\n",
1113
+ " \"token_merging_ratio\", \"s_min_uncond\"]\n",
1114
+ "\n",
1115
+ " if \"quicksettings\" in config:\n",
1116
+ " config[\"quicksettings\"] = \", \".join(quicksettings_values)\n",
1117
+ " elif \"quicksettings_list\" in config:\n",
1118
+ " config[\"quicksettings_list\"] = quicksettings_values\n",
1119
+ "\n",
1120
+ " config_utils.write_config(config_file, config)\n",
1121
+ "\n",
1122
+ " if use_presets:\n",
1123
+ " configure_ui_settings(ui_config_file)\n",
1124
+ "\n",
1125
+ "def configure_ui_settings(ui_config_file: str):\n",
1126
+ " config = config_utils.read_config(ui_config_file)\n",
1127
+ " preset_config = ui_preset_config()\n",
1128
+ " for key in [\"txt2img\", \"img2img\"]:\n",
1129
+ " for subkey, value in preset_config.items():\n",
1130
+ " config[f\"{key}/{subkey}\"] = value\n",
1131
+ "\n",
1132
+ " config[\"txt2img/Upscaler/value\"] = default_upscaler\n",
1133
+ " config_utils.write_config(ui_config_file, config)\n",
1134
+ "\n",
1135
+ "def is_dir_exist(cloned_dir, original_dir):\n",
1136
+ " if os.path.exists(cloned_dir):\n",
1137
+ " return cloned_dir\n",
1138
+ " else:\n",
1139
+ " return original_dir\n",
1140
+ "\n",
1141
+ "def parse_args(config):\n",
1142
+ " args = \"\"\n",
1143
+ " for k, v in config.items():\n",
1144
+ " if k.startswith(\"_\"):\n",
1145
+ " args += f'\"{v}\" '\n",
1146
+ " elif isinstance(v, str):\n",
1147
+ " args += f'--{k}=\"{v}\" '\n",
1148
+ " elif isinstance(v, bool) and v:\n",
1149
+ " args += f\"--{k} \"\n",
1150
+ " elif isinstance(v, float) and not isinstance(v, bool):\n",
1151
+ " args += f\"--{k}={v} \"\n",
1152
+ " elif isinstance(v, int) and not isinstance(v, bool):\n",
1153
+ " args += f\"--{k}={v} \"\n",
1154
+ "\n",
1155
+ " return args\n",
1156
+ "\n",
1157
+ "def main():\n",
1158
+ " global auto_select_model, auto_select_vae\n",
1159
+ "\n",
1160
+ " repo_name, _, _ = validate_repo(repo_dir)\n",
1161
+ " if \"anapnoe\" in repo_name:\n",
1162
+ " change_theme(select_theme)\n",
1163
+ "\n",
1164
+ " valid_ckpt_dir = is_dir_exist(os.path.join(fused_dir, \"model\"), models_dir)\n",
1165
+ " valid_vae_dir = is_dir_exist(os.path.join(fused_dir, \"vae\"), vaes_dir)\n",
1166
+ " valid_embedding_dir = is_dir_exist(os.path.join(fused_dir, \"embedding\"), embeddings_dir)\n",
1167
+ " valid_lora_dir = is_dir_exist(os.path.join(fused_dir, \"lora\"), lora_dir)\n",
1168
+ " valid_hypernetwork_dir = is_dir_exist(os.path.join(fused_dir, \"hypernetwork\"), hypernetworks_dir)\n",
1169
+ "\n",
1170
+ " print_line(80, color=\"green\")\n",
1171
+ " cprint(f\"Launching '{repo_name}'\", color=\"flat_yellow\")\n",
1172
+ " print_line(80, color=\"green\")\n",
1173
+ "\n",
1174
+ " if not is_valid(valid_ckpt_dir, ('.ckpt', '.safetensors')):\n",
1175
+ " cprint(f\"No checkpoints were found in the directory '{valid_ckpt_dir}'.\", color=\"yellow\")\n",
1176
+ " url = \"https://huggingface.co/vorstcavry/mymodel/resolve/main/Cavry_V2.safetensors\"\n",
1177
+ " filename = \"Cavry_V2.safetensors\"\n",
1178
+ " aria2_download(url=url, download_dir=valid_ckpt_dir, filename=filename)\n",
1179
+ " print_line(80, color=\"green\")\n",
1180
+ " auto_select_model = True\n",
1181
+ "\n",
1182
+ " if not is_valid(valid_vae_dir, ('.vae.pt', '.vae.safetensors', '.pt', '.ckpt')):\n",
1183
+ " cprint(f\"No VAEs were found in the directory '{valid_vae_dir}'.\", color=\"yellow\")\n",
1184
+ " url = \"https://huggingface.co/vorstcavry/vaecollection/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\"\n",
1185
+ " filename = \"vae-ft-mse-840000-ema-pruned.ckpt\"\n",
1186
+ " aria2_download(url=url, download_dir=valid_vae_dir, filename=filename)\n",
1187
+ " print_line(80, color=\"green\")\n",
1188
+ " auto_select_vae = True\n",
1189
+ "\n",
1190
+ " if auto_select_model:\n",
1191
+ " selected_model = auto_select_file(valid_ckpt_dir, \"sd_model_checkpoint\", ('.ckpt', '.safetensors'))\n",
1192
+ " cprint(f\"Selected Model: {selected_model}\", color=\"green\")\n",
1193
+ "\n",
1194
+ " if auto_select_vae:\n",
1195
+ " selected_vae = auto_select_file(valid_vae_dir, \"sd_vae\", ('.vae.pt', '.vae.safetensors', '.pt', '.ckpt'))\n",
1196
+ " cprint(f\"Selected VAE: {selected_vae}\", color=\"green\")\n",
1197
+ "\n",
1198
+ " print_line(80, color=\"green\")\n",
1199
+ "\n",
1200
+ " configure_main_settings(config_file, valid_lora_dir, use_presets, ui_config_file)\n",
1201
+ "\n",
1202
+ " if use_gradio_auth:\n",
1203
+ " cprint(\"Gradio Auth (use this account to login):\", color=\"green\")\n",
1204
+ " cprint(\"[-] Username: cagliostro\", color=\"green\")\n",
1205
+ " cprint(\"[-] Password:\", password, color=\"green\")\n",
1206
+ " print_line(80, color=\"green\")\n",
1207
+ "\n",
1208
+ " config = {\n",
1209
+ " \"enable-insecure-extension-access\": True,\n",
1210
+ " \"disable-safe-unpickle\" : True,\n",
1211
+ " f\"{accelerator}\" : True,\n",
1212
+ " f\"{select_tunnel}\" : True if not select_tunnel == \"gradio\" and not ngrok_token else False,\n",
1213
+ " \"share\" : True if not ngrok_token else False,\n",
1214
+ " \"gradio-auth\" : f\"{user}:{password}\" if use_gradio_auth else None,\n",
1215
+ " \"no-hashing\" : True,\n",
1216
+ " \"disable-console-progressbars\" : True,\n",
1217
+ " \"ngrok\" : ngrok_token if ngrok_token else None,\n",
1218
+ " \"ngrok-region\" : ngrok_region if ngrok_token else None,\n",
1219
+ " \"opt-sub-quad-attention\" : True,\n",
1220
+ " \"opt-channelslast\" : True,\n",
1221
+ " \"no-download-sd-model\" : True,\n",
1222
+ " \"gradio-queue\" : True,\n",
1223
+ " \"listen\" : True,\n",
1224
+ " \"ckpt-dir\" : valid_ckpt_dir,\n",
1225
+ " \"vae-dir\" : valid_vae_dir,\n",
1226
+ " \"hypernetwork-dir\" : valid_hypernetwork_dir,\n",
1227
+ " \"embeddings-dir\" : valid_embedding_dir,\n",
1228
+ " \"lora-dir\" : valid_lora_dir,\n",
1229
+ " \"lyco-dir\" : valid_lora_dir,\n",
1230
+ " }\n",
1231
+ "\n",
1232
+ " args = parse_args(config)\n",
1233
+ " final_args = f\"python launch.py {args} {additional_arguments}\"\n",
1234
+ "\n",
1235
+ " cprint()\n",
1236
+ " os.chdir(repo_dir)\n",
1237
+ " !{final_args}\n",
1238
+ "\n",
1239
+ "main()"
1240
+ ],
1241
+ "metadata": {
1242
+ "id": "Gh3uUu-RT6fV",
1243
+ "cellView": "form"
1244
+ },
1245
+ "execution_count": null,
1246
+ "outputs": []
1247
+ },
1248
+ {
1249
+ "cell_type": "markdown",
1250
+ "source": [
1251
+ "##<font color=\"#7FFF00\">***Fitur Download dan Upload***</font>\n"
1252
+ ],
1253
+ "metadata": {
1254
+ "id": "frYxBNQhVHSK"
1255
+ }
1256
+ },
1257
+ {
1258
+ "cell_type": "code",
1259
+ "source": [
1260
+ "#@title ## <font color=\"#FFD700\">**_Download Hasil Stable Diffusion_**</font>\n",
1261
+ "\n",
1262
+ "# @markdown Centang di bawah ini jika ingin menyimpannya di Google Drive\n",
1263
+ "\n",
1264
+ "import os\n",
1265
+ "\n",
1266
+ "from pydrive.auth import GoogleAuth\n",
1267
+ "from pydrive.drive import GoogleDrive\n",
1268
+ "from google.colab import auth, drive\n",
1269
+ "from oauth2client.client import GoogleCredentials\n",
1270
+ "from colablib.colored_print import cprint, print_line\n",
1271
+ "\n",
1272
+ "%store -r\n",
1273
+ "\n",
1274
+ "os.chdir(output_dir)\n",
1275
+ "\n",
1276
+ "use_drive = False # @param {type:\"boolean\"}\n",
1277
+ "folder_name = \"cagliostro-colab-ui\" # @param {type: \"string\"}\n",
1278
+ "filename = \"output.zip\" # @param {type: \"string\"}\n",
1279
+ "save_as = filename\n",
1280
+ "\n",
1281
+ "if os.path.exists(filename):\n",
1282
+ " i = 1\n",
1283
+ " while os.path.exists(f\"waifu({i}).zip\"):\n",
1284
+ " i += 1\n",
1285
+ " filename = f\"waifu({i}).zip\"\n",
1286
+ "\n",
1287
+ "os.system('zip -r /content/outputs.zip .')\n",
1288
+ "\n",
1289
+ "if use_drive:\n",
1290
+ " auth.authenticate_user()\n",
1291
+ " gauth = GoogleAuth()\n",
1292
+ " gauth.credentials = GoogleCredentials.get_application_default()\n",
1293
+ " drive = GoogleDrive(gauth)\n",
1294
+ "\n",
1295
+ " def create_folder(folder_name):\n",
1296
+ " file_list = drive.ListFile({\n",
1297
+ " \"q\": f\"title='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false\"\n",
1298
+ " }).GetList()\n",
1299
+ " if file_list:\n",
1300
+ " cprint(\"Debug: Folder exists\", color=\"green\")\n",
1301
+ " folder_id = file_list[0][\"id\"]\n",
1302
+ " else:\n",
1303
+ " cprint(\"Debug: Creating folder\", color=\"green\")\n",
1304
+ " file = drive.CreateFile({\n",
1305
+ " \"title\": folder_name,\n",
1306
+ " \"mimeType\": \"application/vnd.google-apps.folder\"\n",
1307
+ " })\n",
1308
+ " file.Upload()\n",
1309
+ " folder_id = file.attr[\"metadata\"][\"id\"]\n",
1310
+ " return folder_id\n",
1311
+ "\n",
1312
+ " def upload_file(file_name, folder_id, save_as):\n",
1313
+ " file_list = drive.ListFile({\"q\": f\"title='{save_as}' and trashed=false\"}).GetList()\n",
1314
+ " if file_list:\n",
1315
+ " cprint(\"Debug: File already exists\", color=\"green\")\n",
1316
+ " i = 1\n",
1317
+ " while True:\n",
1318
+ " new_name = f\"{os.path.splitext(save_as)[0]}({i}){os.path.splitext(save_as)[1]}\"\n",
1319
+ " file_list = drive.ListFile({\"q\": f\"title='{new_name}' and trashed=false\"}).GetList()\n",
1320
+ " if not file_list:\n",
1321
+ " save_as = new_name\n",
1322
+ " break\n",
1323
+ " i += 1\n",
1324
+ " file = drive.CreateFile({\"title\": save_as, \"parents\": [{\"id\": folder_id}]})\n",
1325
+ " file.SetContentFile(file_name)\n",
1326
+ " file.Upload()\n",
1327
+ " file.InsertPermission({\"type\": \"anyone\", \"value\": \"anyone\", \"role\": \"reader\"})\n",
1328
+ " return file.attr[\"metadata\"][\"id\"]\n",
1329
+ "\n",
1330
+ " file_id = upload_file(\"/content/outputs.zip\", create_folder(folder_name), save_as)\n",
1331
+ " cprint(f\"Your sharing link: https://drive.google.com/file/d/{file_id}/view?usp=sharing\", color=\"green\")"
1332
+ ],
1333
+ "metadata": {
1334
+ "cellView": "form",
1335
+ "id": "LphRDI1JVHS8"
1336
+ },
1337
+ "execution_count": null,
1338
+ "outputs": []
1339
+ },
1340
+ {
1341
+ "cell_type": "code",
1342
+ "execution_count": null,
1343
+ "metadata": {
1344
+ "cellView": "form",
1345
+ "id": "DscmcGPtVHTd"
1346
+ },
1347
+ "outputs": [],
1348
+ "source": [
1349
+ "#@title ## <font color=\"#FFD700\">**_Login Akun dan Konfirmasi Letak Penyimpan Huggingface_**</font>\n",
1350
+ "from huggingface_hub import login\n",
1351
+ "from huggingface_hub import HfApi\n",
1352
+ "from huggingface_hub.utils import validate_repo_id, HfHubHTTPError\n",
1353
+ "\n",
1354
+ "# @markdown Login akun Huggingface Hub (Jika belum punya akun, bisa daftar dulu [**Join di sini**](https://huggingface.co/join))\n",
1355
+ "# @markdown > Dapatkan huggingface [disini](https://huggingface.co/settings/tokens)\n",
1356
+ "write_token = \"\" # @param {type:\"string\"}\n",
1357
+ "# @markdown Masukan Nama organisasi, Jika tidak ada bisa di kosongkan.\n",
1358
+ "# @markdown >tekan [Masuk](https://huggingface.co/organizations/INDONESIA-AI/share/rcGdQObpefOQvqndOutQcfYFZfRYVGitTy) untuk bergabung ke Komunitas Huggingface saya\n",
1359
+ "orgs_name = \"\" # @param{type:\"string\"}\n",
1360
+ "# @markdown Masukan repositori model dan dataset huggingface, kosongkan jika ingin terbuat secara otomatis.\n",
1361
+ "model_name = \"\" # @param{type:\"string\"}\n",
1362
+ "dataset_name = \"\" # @param{type:\"string\"}\n",
1363
+ "# @markdown Simpan sebagi menjadi Privat\n",
1364
+ "make_private = False # @param{type:\"boolean\"}\n",
1365
+ "\n",
1366
+ "def authenticate(write_token):\n",
1367
+ " login(write_token, add_to_git_credential=True)\n",
1368
+ " api = HfApi()\n",
1369
+ " return api.whoami(write_token), api\n",
1370
+ "\n",
1371
+ "\n",
1372
+ "def create_repo(api, user, orgs_name, repo_name, repo_type, make_private=False):\n",
1373
+ " global model_repo\n",
1374
+ " global datasets_repo\n",
1375
+ "\n",
1376
+ " if orgs_name == \"\":\n",
1377
+ " repo_id = user[\"name\"] + \"/\" + repo_name.strip()\n",
1378
+ " else:\n",
1379
+ " repo_id = orgs_name + \"/\" + repo_name.strip()\n",
1380
+ "\n",
1381
+ " try:\n",
1382
+ " validate_repo_id(repo_id)\n",
1383
+ " api.create_repo(repo_id=repo_id, repo_type=repo_type, private=make_private)\n",
1384
+ " print(f\"{repo_type.capitalize()} repo '{repo_id}' didn't exist, creating repo\")\n",
1385
+ " except HfHubHTTPError as e:\n",
1386
+ " print(f\"{repo_type.capitalize()} repo '{repo_id}' exists, skipping create repo\")\n",
1387
+ "\n",
1388
+ " if repo_type == \"model\":\n",
1389
+ " model_repo = repo_id\n",
1390
+ " print(f\"{repo_type.capitalize()} repo '{repo_id}' link: https://huggingface.co/{repo_id}\\n\")\n",
1391
+ " else:\n",
1392
+ " datasets_repo = repo_id\n",
1393
+ " print(f\"{repo_type.capitalize()} repo '{repo_id}' link: https://huggingface.co/datasets/{repo_id}\\n\")\n",
1394
+ "\n",
1395
+ "user, api = authenticate(write_token)\n",
1396
+ "\n",
1397
+ "if model_name:\n",
1398
+ " create_repo(api, user, orgs_name, model_name, \"model\", make_private)\n",
1399
+ "if dataset_name:\n",
1400
+ " create_repo(api, user, orgs_name, dataset_name, \"dataset\", make_private)"
1401
+ ]
1402
+ },
1403
+ {
1404
+ "cell_type": "code",
1405
+ "execution_count": null,
1406
+ "metadata": {
1407
+ "cellView": "form",
1408
+ "id": "vb6LoMwPVHTh"
1409
+ },
1410
+ "outputs": [],
1411
+ "source": [
1412
+ "#@title ## <font color=\"#FFD700\">**_Proses Upload ke Huggingface_**</font>\n",
1413
+ "\n",
1414
+ "from huggingface_hub import HfApi\n",
1415
+ "from pathlib import Path\n",
1416
+ "\n",
1417
+ "%store -r\n",
1418
+ "\n",
1419
+ "api = HfApi()\n",
1420
+ "\n",
1421
+ "# @markdown Masukkan tata letak file yang ingin di Upload\n",
1422
+ "model_path = \"/content/\" # @param {type :\"string\"}\n",
1423
+ "#@markdown Masukkan tata letak file path dan config (jika ada)\n",
1424
+ "path_in_repo = \"\" # @param {type :\"string\"}\n",
1425
+ "config_path = \"\" # @param {type :\"string\"}\n",
1426
+ "\n",
1427
+ "# @markdown Masukan informasi untuk Upload\n",
1428
+ "commit_message = \"upload\" # @param {type :\"string\"}\n",
1429
+ "\n",
1430
+ "if not commit_message:\n",
1431
+ " commit_message = f\"feat: upload {project_name} lora model\"\n",
1432
+ "\n",
1433
+ "def upload_to_hf(model_path, is_folder, is_config):\n",
1434
+ " path_obj = Path(model_path)\n",
1435
+ " trained_model = path_obj.parts[-1]\n",
1436
+ "\n",
1437
+ " if path_in_repo:\n",
1438
+ " trained_model = path_in_repo\n",
1439
+ "\n",
1440
+ " if is_config:\n",
1441
+ " trained_model = f\"{project_name}_config\"\n",
1442
+ "\n",
1443
+ " print(f\"Uploading {trained_model} to https://huggingface.co/{model_repo}\")\n",
1444
+ " print(\"Please wait...\")\n",
1445
+ "\n",
1446
+ " if is_folder:\n",
1447
+ " api.upload_folder(\n",
1448
+ " folder_path=model_path,\n",
1449
+ " path_in_repo=trained_model,\n",
1450
+ " repo_id=model_repo,\n",
1451
+ " commit_message=commit_message,\n",
1452
+ " ignore_patterns=\".ipynb_checkpoints\",\n",
1453
+ " )\n",
1454
+ " print(f\"Upload success, located at https://huggingface.co/{model_repo}/tree/main\\n\")\n",
1455
+ " else:\n",
1456
+ " api.upload_file(\n",
1457
+ " path_or_fileobj=model_path,\n",
1458
+ " path_in_repo=trained_model,\n",
1459
+ " repo_id=model_repo,\n",
1460
+ " commit_message=commit_message,\n",
1461
+ " )\n",
1462
+ " print(f\"Upload success, located at https://huggingface.co/{model_repo}/blob/main/{trained_model}\\n\")\n",
1463
+ "\n",
1464
+ "def upload():\n",
1465
+ " is_model_file = model_path.endswith((\".ckpt\", \".safetensors\", \".pt\", \".png\", \".zip\"))\n",
1466
+ " upload_to_hf(model_path, not is_model_file, False)\n",
1467
+ "\n",
1468
+ " if config_path:\n",
1469
+ " upload_to_hf(config_path, True, True)\n",
1470
+ "\n",
1471
+ "upload()"
1472
+ ]
1473
+ }
1474
+ ],
1475
+ "metadata": {
1476
+ "accelerator": "GPU",
1477
+ "colab": {
1478
+ "private_outputs": true,
1479
+ "provenance": [],
1480
+ "collapsed_sections": [
1481
+ "upiFioaJfziP",
1482
+ "fof1qg-QUyFv",
1483
+ "v9md6r0tG0jQ",
1484
+ "6TtktCcHHBmo",
1485
+ "Nyv6g0sNHJaO",
1486
+ "frYxBNQhVHSK",
1487
+ "oEk611XKY623",
1488
+ "kfdbFRjs1Q-T"
1489
+ ],
1490
+ "include_colab_link": true
1491
+ },
1492
+ "gpuClass": "standard",
1493
+ "kernelspec": {
1494
+ "display_name": "Python 3",
1495
+ "name": "python3"
1496
+ },
1497
+ "language_info": {
1498
+ "name": "python"
1499
+ }
1500
+ },
1501
+ "nbformat": 4,
1502
+ "nbformat_minor": 0
1503
+ }