File size: 17,963 Bytes
ceeafb1 88bad94 ceeafb1 c8ce98f ceeafb1 f9b46d8 c1d0017 ceeafb1 88bad94 45612dd eeb2a24 88bad94 45612dd 88bad94 da4d50a eeb2a24 45612dd eeb2a24 4424587 eeb2a24 c8ce98f 45612dd e3a2f7c 45612dd e3a2f7c eeb2a24 45612dd ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 1291827 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 c8ce98f 4424587 c8ce98f 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 9de0e56 ba1b35e 88bad94 ceeafb1 88bad94 ceeafb1 bb6c2f5 ceeafb1 c8ce98f ceeafb1 bb6c2f5 ceeafb1 bb6c2f5 ceeafb1 bb6c2f5 ceeafb1 bb6c2f5 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 88bad94 ceeafb1 1291827 ceeafb1 c8ce98f 45612dd 88bad94 bca80c8 88bad94 c8ce98f ceeafb1 88bad94 ceeafb1 eeb2a24 ceeafb1 c8ce98f 88bad94 c8ce98f 88bad94 c8ce98f ceeafb1 88bad94 3de4bee 88bad94 ceeafb1 88bad94 ceeafb1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JKTCrY9LU7Oq"
},
"outputs": [],
"source": [
"##~ WIDGET CODE | BY: ANXETY ~##\n",
"\n",
"import os\n",
"import json\n",
"import time\n",
"import ipywidgets as widgets\n",
"from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
"from IPython.display import display, HTML, Javascript, clear_output\n",
"\n",
"\n",
"# Setup Env\n",
"env = os.getenv('ENV_NAME')\n",
"root_path = os.getenv('ROOT_PATH')\n",
"webui_path = os.getenv('WEBUI_PATH')\n",
"free_plan = os.getenv('FREE_PLAN')\n",
"\n",
"\n",
"# ==================== CSS JS ====================\n",
"##~ custom background images V1.5 ~##\n",
"import argparse\n",
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
"\n",
"args = parser.parse_args()\n",
"\n",
"url_img = args.image\n",
"opacity_img = args.opacity\n",
"blur_img = args.blur\n",
"y_img = args.y\n",
"x_img = args.x\n",
"scale_img = args.scale\n",
"blur_fields = args.blur_fields\n",
"\n",
"## ---\n",
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
"\n",
"\"\"\" transperent fields \"\"\"\n",
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
"\n",
"\"\"\" mode img - repeats \"\"\"\n",
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
"\n",
"container_background = f'''\n",
"<style>\n",
":root {{\n",
" /* for background container*/\n",
" --img_background: url({url_img});\n",
" --img_opacity: {opacity_img};\n",
" --img_blur: {blur_img}px;\n",
" --image_y: {y_img}px;\n",
" --image_x: {x_img}px;\n",
" --img_scale: {scale_img}%;\n",
" --img_mode: {mode_img};\n",
" --img_height_dif: {fix_heigh_img};\n",
"\n",
" /* for fields */\n",
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
" --bg-field-blur-level: {blur_fields}px;\n",
"}}\n",
"'''\n",
"\n",
"display(HTML(container_background))\n",
"\n",
"# Main CSS\n",
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
"with open(css_file_path , \"r\") as f:\n",
" CSS = f.read()\n",
"display(HTML(f\"<style>{CSS}</style>\"))\n",
"\n",
"# Main JS\n",
"JS = '''\n",
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
"<script>\n",
"function toggleContainer() {\n",
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
" let info = document.querySelector('.info');\n",
"\n",
" downloadContainer.classList.toggle('expanded');\n",
" info.classList.toggle('showed');\n",
"}\n",
"</script>\n",
"'''\n",
"display(HTML(JS))\n",
"\n",
"\n",
"# ==================== WIDGETS V2 ====================\n",
"HR = widgets.HTML('<hr>')\n",
"\n",
"class WidgetFactory:\n",
" def __init__(self, style=None, layout=None):\n",
" self.style = style if style else {'description_width': 'initial'}\n",
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
"\n",
" def create_html(self, content, class_name=None):\n",
" html_widget = widgets.HTML(content)\n",
" if class_name:\n",
" html_widget.add_class(class_name)\n",
" return html_widget\n",
"\n",
" def create_header(self, name):\n",
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
"\n",
" def create_dropdown(self, options, value, description):\n",
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
"\n",
" def create_text(self, description, placeholder='', value=''):\n",
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
"\n",
" def create_checkbox(self, value, description):\n",
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
"\n",
" def create_button(self, description, class_name=None):\n",
" button = widgets.Button(description=description)\n",
" if class_name:\n",
" button.add_class(class_name)\n",
" return button\n",
"\n",
" def create_hbox(self, children):\n",
" return widgets.HBox(children)\n",
"\n",
" def create_vbox(self, children, class_names=None):\n",
" vbox = widgets.VBox(children)\n",
" if class_names:\n",
" for class_name in class_names:\n",
" vbox.add_class(class_name)\n",
" return vbox\n",
"\n",
" def display(self, widget):\n",
" display(widget)\n",
"\n",
"# Instantiate the factory\n",
"factory = WidgetFactory()\n",
"\n",
"# --- MODEL ---\n",
"model_header = factory.create_header('Model Selection')\n",
"model_options = ['none',\n",
" '1.Anime (by XpucT) + INP',\n",
" '2.BluMix [Anime] [V7] + INP',\n",
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
" '4.Counterfeit [Anime] [V3] + INP',\n",
" '5.CuteColor [Anime] [V3]',\n",
" '6.Dark-Sushi-Mix [Anime]',\n",
" '7.Deliberate [Realism] [V6] + INP',\n",
" '8.Meina-Mix [Anime] [V11] + INP',\n",
" '9.Mix-Pro [Anime] [V4] + INP']\n",
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')\n",
"model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')\n",
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')\n",
"\n",
"# Display Model\n",
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
"factory.display(all_model_box)\n",
"\n",
"# --- VAE ---\n",
"vae_header = factory.create_header('VAE Selection')\n",
"vae_options = ['none',\n",
" '1.Anime.vae',\n",
" '2.Anything.vae',\n",
" '3.Blessed2.vae',\n",
" '4.ClearVae.vae',\n",
" '5.WD.vae']\n",
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
"vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')\n",
"\n",
"# Display Vae\n",
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
"factory.display(all_vae_box)\n",
"\n",
"# --- ADDITIONAL ---\n",
"additional_header = factory.create_header('Additional')\n",
"latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')\n",
"latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')\n",
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')\n",
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')\n",
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
"\n",
"controlnet_options = ['none', 'ALL', '1.canny',\n",
" '2.openpose', '3.depth',\n",
" '4.normal_map', '5.mlsd',\n",
" '6.lineart', '7.soft_edge',\n",
" '8.scribble', '9.segmentation',\n",
" '10.shuffle', '11.tile',\n",
" '12.inpaint', '13.instruct_p2p']\n",
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
"controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')\n",
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
"huggingface_token_widget = factory.create_text('HuggingFace Token:')\n",
"\n",
"ngrok_token_widget = factory.create_text('Ngrok Token:')\n",
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
"\n",
"zrok_token_widget = factory.create_text('Zrok Token:')\n",
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
"\n",
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
"commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)\n",
"\n",
"# Display Additional\n",
"additional_widget_list = [additional_header,\n",
" choose_changes_widget,\n",
" HR,\n",
" controlnet_widget,\n",
" controlnet_num_widget,\n",
" commit_hash_widget,\n",
" huggingface_token_widget,\n",
" ngrok_widget,\n",
" zrok_widget,\n",
" HR,\n",
" commandline_arguments_widget]\n",
"\n",
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
" additional_widget_list.remove(ngrok_widget)\n",
"\n",
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
"factory.display(all_additional_box)\n",
"\n",
"# --- CUSTOM DOWNLOAD ---\n",
"custom_download_header_popup = factory.create_html('''\n",
"<style>\n",
"/* Term Colors */\n",
".sample_label {color: #dbafff;}\n",
".braces {color: #ffff00;}\n",
".extension {color: #eb934b;}\n",
".file_name {color: #ffffd8;}\n",
"</style>\n",
"\n",
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
"<!-- PopUp Window -->\n",
"<div class=\"info\">INFO</div>\n",
"<div class=\"popup\">\n",
" Separate multiple URLs with a comma/space. For a <span class=\"file_name\">custom name</span> file/extension, specify it with <span class=\"braces\">[]</span>\n",
" after the URL without spaces.\n",
" <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
" <div class=\"sample\">\n",
" <span class=\"sample_label\">Example for File:</span>\n",
" https://civitai.com/api/download/models/229782<span class=\"braces\">[</span><span class=\"file_name\">Detailer</span><span class=\"extension\">.safetensors</span><span class=\"braces\">]</span>\n",
" <br>\n",
" <span class=\"sample_label\">Example for Extension:</span>\n",
" https://github.com/hako-mikan/sd-webui-regional-prompter<span class=\"braces\">[</span><span class=\"file_name\">Regional-Prompter</span><span class=\"braces\">]</span>\n",
" </div>\n",
"</div>\n",
"''')\n",
"\n",
"Model_url_widget = factory.create_text('Model:')\n",
"Vae_url_widget = factory.create_text('Vae:')\n",
"LoRA_url_widget = factory.create_text('LoRa:')\n",
"Embedding_url_widget = factory.create_text('Embedding:')\n",
"Extensions_url_widget = factory.create_text('Extensions:')\n",
"custom_file_urls_widget = factory.create_text('File (txt):')\n",
"\n",
"# Display CustomDl\n",
"all_custom_box = factory.create_vbox([\n",
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
"factory.display(all_custom_box)\n",
"\n",
"# --- Save Button ---\n",
"save_button = factory.create_button('Save', class_name=\"button_save\")\n",
"factory.display(save_button)\n",
"\n",
"\n",
"# ==================== OTHER FUNC ====================\n",
"# Setup UI\n",
"def setup_webui(change_webui_widget):\n",
" if 'SDW_UI' in os.environ:\n",
" UI = os.environ['SDW_UI']\n",
" else:\n",
" os.environ['SDW_UI'] = change_webui_widget\n",
" os.environ['SDW_OLD_UI'] = change_webui_widget\n",
"\n",
" UI = os.getenv('SDW_UI')\n",
"\n",
" if UI != change_webui_widget:\n",
" os.environ['SDW_UI'] = change_webui_widget\n",
"\n",
"\n",
"# ============ Load / Save - Settings V2 ============\n",
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
"\n",
"SETTINGS_KEYS = [\n",
" 'model', 'model_num', 'inpainting_model',\n",
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
" 'change_webui', 'detailed_download', 'controlnet',\n",
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
" 'Extensions_url', 'custom_file_urls'\n",
"]\n",
"\n",
"def save_settings():\n",
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
" with open(SETTINGS_FILE, 'w') as f:\n",
" json.dump(settings, f, indent=2)\n",
"\n",
"def load_settings():\n",
" if os.path.exists(SETTINGS_FILE):\n",
" with open(SETTINGS_FILE, 'r') as f:\n",
" settings = json.load(f)\n",
" for key in SETTINGS_KEYS:\n",
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
"\n",
"def hide_widgets():\n",
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
" for widget in widgets_list:\n",
" widget.add_class(\"hide\")\n",
" time.sleep(0.5)\n",
" widgets.Widget.close_all()\n",
"\n",
"def save_data(button):\n",
" save_settings()\n",
" setup_webui(change_webui_widget.value)\n",
" hide_widgets()\n",
"\n",
"load_settings()\n",
"save_button.on_click(save_data)"
]
}
]
} |