#!/usr/bin/env python # coding: utf-8 # In[ ]: ##~ WIDGET CODE | BY: ANXETY ~## import os import json import ipywidgets as widgets from ipywidgets import widgets, Layout, Label, Button, VBox, HBox from IPython.display import display, HTML, Javascript, clear_output # ================= DETECT ENV ================= def detect_environment(): environments = { 'COLAB_GPU': ('Google Colab', "/content"), 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"), 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content") } for env_var, (environment, path) in environments.items(): if env_var in os.environ: return environment, path env, root_path = detect_environment() webui_path = f"{root_path}/sdw" get_ipython().system('mkdir -p {root_path}') # ---------------------------------------------- # ==================== CSS JS ==================== CSS = ''' ''' display(HTML(CSS)) # ==================== CSS JS ==================== # ==================== WIDGETS ==================== # --- global widgets --- style = {'description_width': 'initial'} layout = widgets.Layout(min_width='1047px') HR = widgets.HTML('
') # --- MODEL --- model_header = widgets.HTML('
Model Selection
') model_options = ['none', '1.Anime (by Xpuct) + INP', '2.Cetus-Mix [Anime] [V4] + INP', '3.Counterfeit [Anime] [V3] + INP', '4.CuteColor [Anime] [V3]', '5.Dark-Sushi-Mix [Anime]', '6.Meina-Mix [Anime] [V11] + INP', '7.Mix-Pro [Anime] [V4] + INP', '8.BluMix [Anime] [V7]'] # --- Model_widget = widgets.Dropdown(options=model_options, value='6.Meina-Mix [Anime] [V11] + INP', description='Model:', style=style, layout=layout) Model_Num_widget = widgets.Text(description='Model Number:', placeholder='Enter the model numbers to be downloaded using comma/space.', style=style, layout=layout) Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Models', style=style) display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class("container")) # --- VAE --- vae_header = widgets.HTML('
VAE Selection
') vae_options = ['none', '1.Anime.vae', '2.Anything.vae', '3.Blessed2.vae', '4.ClearVae.vae', '5.WD.vae'] Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout) Vae_Num_widget = widgets.Text(description='Vae number:', placeholder='Enter the vae numbers to be downloaded using comma/space.', style=style, layout=layout) display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class("container")) # --- ADDITIONAL --- additional_header = widgets.HTML('
Additional
') latest_webui_widget = widgets.Checkbox(value=True, description='Update WebUI', style=style) latest_exstensions_widget = widgets.Checkbox(value=True, description='Update Extensions', style=style) detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Detailed Download:', style=style) latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between')) controlnet_options = ['none', 'ALL', '1.canny', '2.openpose', '3.depth', '4.normal_map', '5.mlsd', '6.lineart', '7.soft_edge', '8.scribble', '9.segmentation', '10.shuffle', '11.tile', '12.inpaint', '13.instruct_p2p'] # --- controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout) controlnet_Num_widget = widgets.Text(description='ControlNet Number:', placeholder='Enter the ControlNet model numbers to be downloaded using comma/space.', style=style, layout=layout) commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout) optional_huggingface_token_widget = widgets.Text(description='Huggingface token:', style=style, layout=layout) ngrok_token_widget = widgets.Text(description='Ngrok token:',value='2WRNUNr4mA4xBM7dlZuscgyXSR7_4tisCAo2kfWagu1z4fgCL', style=style, layout=widgets.Layout(width='1047px')) ngrock_button = widgets.HTML('Get Ngrok Token').add_class("button_ngrok") ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout) # --- commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers" commandline_arguments_widget = widgets.Text(description='Arguments:', value=commandline_arguments_options, style=style, layout=layout) display(widgets.VBox([ additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget ]).add_class("container")) # --- CUSTOM DOWNLOAD --- custom_download_header_popup = widgets.HTML('''
Custom Download
FAQ?
''') # --- Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout) Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout) LoRA_url_widget = widgets.Text(description='LoRa:',value = 'https://huggingface.co/duhking/kagglee/blob/main/gate.safetensors' ,style=style, layout=layout) Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout) Extensions_url_widget = widgets.Text(description='Extensions:',value = 'https://github.com/BlafKing/sd-civitai-browser-plus.git', style=style, layout=layout) custom_file_urls_widget = widgets.Text(description='File (txt):', style=style, layout=layout) display(widgets.VBox([ custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget ]).add_class("container").add_class("container_custom_downlad")) # --- Save Button --- save_button = widgets.Button(description='Save').add_class("button_save") display(save_button) # ============ Load / Save - Settings V2 ============ SETTINGS_FILE = f'{root_path}/settings.json' settings_keys = [ 'Model', 'Model_Num', 'Inpainting_Model', 'Vae', 'Vae_Num', 'latest_webui', 'latest_exstensions', 'detailed_download', 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token', 'ngrok_token', 'commandline_arguments', 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls' ] def save_settings(): settings = {key: globals()[f"{key}_widget"].value for key in settings_keys} with open(SETTINGS_FILE, 'w') as f: json.dump(settings, f) def load_settings(): if os.path.exists(SETTINGS_FILE): with open(SETTINGS_FILE, 'r') as f: settings = json.load(f) for key in settings_keys: globals()[f"{key}_widget"].value = settings.get(key) def save_data(button): save_settings() widgets.Widget.close_all() settings = load_settings() save_button.on_click(save_data)