{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "##~ WIDGET CODE | BY: ANXETY ~##\n", "\n", "import os\n", "import json\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", "# ================= DETECT ENV =================\n", "def detect_environment():\n", " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n", " environments = {\n", " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n", " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n", " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n", " }\n", "\n", " for env_var, (environment, path) in environments.items():\n", " if env_var in os.environ:\n", " return environment, path, free_plan\n", "\n", "env, root_path, free_plan = detect_environment()\n", "webui_path = f\"{root_path}/sdw\"\n", "\n", "!mkdir -p {root_path}\n", "# ----------------------------------------------\n", "\n", "\n", "# ==================== CSS JS ====================\n", "# custom background images (test)\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', type=str, help='Specify \"no-repeat\" so that the image pattern is not repeated.', metavar='', default='repeat')\n", "parser.add_argument('-t', '--transparent', action='store_true', help='Flag to exclude z-index from CSS. Makes fields transparent')\n", "args = parser.parse_args()\n", "# ---\n", "url_img, opacity_img, blur_img, y_img, x_img, scale_img, mode_img = args.image, args.opacity, args.blur, args.y, args.x, args.scale, args.mode\n", "\n", "container_background = f'''\n", "\\n\"\n", "\n", "display(HTML(container_background))\n", "# ---\n", "\n", "CSS = '''\n", "\n", "\n", "\n", "\n", "'''\n", "\n", "display(HTML(CSS))\n", "# ==================== CSS JS ====================\n", "\n", "\n", "# ==================== WIDGETS ====================\n", "# --- global widgets ---\n", "style = {'description_width': 'initial'}\n", "layout = widgets.Layout(min_width='1047px')\n", "\n", "HR = widgets.HTML('
')\n", "\n", "# --- MODEL ---\n", "model_header = widgets.HTML('
Выбор Модели
')\n", "model_options = ['none',\n", " '1.Anime (by Xpuct) + INP',\n", " '2.Cetus-Mix [Anime] [V4] + INP',\n", " '3.Counterfeit [Anime] [V3] + INP',\n", " '4.CuteColor [Anime] [V3]',\n", " '5.Dark-Sushi-Mix [Anime]',\n", " '6.Meina-Mix [Anime] [V11] + INP',\n", " '7.Mix-Pro [Anime] [V4] + INP',\n", " '8.BluMix [Anime] [V7]']\n", "# ---\n", "Model_widget = widgets.Dropdown(options=model_options, value='3.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)\n", "Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)\n", "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)\n", "\n", "display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\").add_class(\"image_1\"))\n", "\n", "# --- VAE ---\n", "vae_header = widgets.HTML('
Выбор VAE
')\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 = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n", "Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)\n", "\n", "display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\").add_class(\"image_2\"))\n", "\n", "# --- ADDITIONAL ---\n", "additional_header = widgets.HTML('
Дополнительно
')\n", "latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)\n", "latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)\n", "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)\n", "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\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", "# ---\n", "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n", "controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)\n", "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n", "optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)\n", "ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))\n", "ngrock_button = widgets.HTML('Получить Ngrok Токен').add_class(\"button_ngrok\")\n", "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n", "# ---\n", "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n", "commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)\n", "\n", "additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget]\n", "if free_plan and env == \"Google Colab\":\n", " additional_widget_list.remove(ngrok_widget)\n", "display(widgets.VBox(additional_widget_list).add_class(\"container\").add_class(\"image_3\"))\n", "\n", "# --- CUSTOM DOWNLOAD ---\n", "custom_download_header_popup = widgets.HTML('''\n", "\n", "\n", "
Кастомная Загрузка
\n", "\n", "
FAQ?
\n", "
\n", " Разделите несколько URL-адресов запятой/пробелом. Для пользовательского имени файла/расширения укажите его через []\n", " после URL без пробелов.\n", " Для файлов обязательно укажите - Расширение Файла.\n", "
\n", " Пример для Файла:\n", " https://civitai.com/api/download/models/229782[Detailer.safetensors]\n", "
\n", " Пример для Расширения:\n", " https://github.com/hako-mikan/sd-webui-regional-prompter[Regional-Prompter]\n", "
\n", "
\n", "''')\n", "# ---\n", "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n", "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n", "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n", "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n", "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n", "custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)\n", "\n", "display(widgets.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", " ]).add_class(\"container\").add_class(\"image_4\").add_class(\"container_custom_downlad\"))\n", "\n", "# --- Save Button ---\n", "save_button = widgets.Button(description='Сохранить').add_class(\"button_save\")\n", "display(save_button)\n", "\n", "\n", "# ============ Load / Save - Settings V3 ============\n", "try:\n", " import toml\n", "except ImportError: # SageMaker - only for you...\n", " !pip install toml > /dev/null 2>&1\n", " import toml\n", "\n", "SETTINGS_FILE = f'{root_path}/settings.toml'\n", "\n", "settings_structure = {\n", " \"Model\": ['Model', 'Model_Num', 'Inpainting_Model'],\n", " \"Vae\": ['Vae', 'Vae_Num'],\n", " \"Additional\": ['latest_webui', 'latest_exstensions', 'detailed_download', 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token', 'ngrok_token', 'commandline_arguments'],\n", " \"CustomUrl\": ['Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls']\n", "}\n", "\n", "def save_settings():\n", " settings = {}\n", " for section, keys in settings_structure.items():\n", " settings[section] = {key: globals()[f\"{key}_widget\"].value for key in keys}\n", " with open(SETTINGS_FILE, 'w') as f:\n", " toml.dump(settings, f)\n", "\n", "def load_settings():\n", " if os.path.exists(SETTINGS_FILE):\n", " with open(SETTINGS_FILE, 'r') as f:\n", " loaded_settings = toml.load(f)\n", " for section, keys in settings_structure.items():\n", " for key in keys:\n", " if key in loaded_settings[section]:\n", " globals()[f\"{key}_widget\"].value = loaded_settings[section][key]\n", "\n", "def save_data(button):\n", " save_settings()\n", " widgets.Widget.close_all()\n", "\n", "settings = load_settings()\n", "save_button.on_click(save_data)" ], "metadata": { "id": "2lJmbqrs3Mu8" }, "execution_count": null, "outputs": [] } ] }