# base webui import and utils. from webui_streamlit import st # streamlit imports from streamlit import StopException #streamlit components section from streamlit_server_state import server_state, server_state_lock #other imports import warnings import json import base64 import os, sys, re, random, datetime, time, math, glob from PIL import Image, ImageFont, ImageDraw, ImageFilter from PIL.PngImagePlugin import PngInfo from scipy import integrate import torch from torchdiffeq import odeint import k_diffusion as K import math import mimetypes import numpy as np import pynvml import threading import torch from torch import autocast from torchvision import transforms import torch.nn as nn from omegaconf import OmegaConf import yaml from pathlib import Path from contextlib import nullcontext from einops import rearrange from ldm.util import instantiate_from_config from retry import retry from slugify import slugify import skimage import piexif import piexif.helper from tqdm import trange # Temp imports # end of imports #--------------------------------------------------------------------------------------------------------------- try: # this silences the annoying "Some weights of the model checkpoint were not used when initializing..." message at start. from transformers import logging logging.set_verbosity_error() except: pass # remove some annoying deprecation warnings that show every now and then. warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning) # this is a fix for Windows users. Without it, javascript files will be served with text/html content-type and the bowser will not show any UI mimetypes.init() mimetypes.add_type('application/javascript', '.js') # some of those options should not be changed at all because they would break the model, so I removed them from options. opt_C = 4 opt_f = 8 if not "defaults" in st.session_state: st.session_state["defaults"] = {} st.session_state["defaults"] = OmegaConf.load("configs/webui/webui_streamlit.yaml") if (os.path.exists("configs/webui/userconfig_streamlit.yaml")): user_defaults = OmegaConf.load("configs/webui/userconfig_streamlit.yaml") st.session_state["defaults"] = OmegaConf.merge(st.session_state["defaults"], user_defaults) # should and will be moved to a settings menu in the UI at some point grid_format = [s.lower() for s in st.session_state["defaults"].general.grid_format.split(':')] grid_lossless = False grid_quality = 100 if grid_format[0] == 'png': grid_ext = 'png' grid_format = 'png' elif grid_format[0] in ['jpg', 'jpeg']: grid_quality = int(grid_format[1]) if len(grid_format) > 1 else 100 grid_ext = 'jpg' grid_format = 'jpeg' elif grid_format[0] == 'webp': grid_quality = int(grid_format[1]) if len(grid_format) > 1 else 100 grid_ext = 'webp' grid_format = 'webp' if grid_quality < 0: # e.g. webp:-100 for lossless mode grid_lossless = True grid_quality = abs(grid_quality) # should and will be moved to a settings menu in the UI at some point save_format = [s.lower() for s in st.session_state["defaults"].general.save_format.split(':')] save_lossless = False save_quality = 100 if save_format[0] == 'png': save_ext = 'png' save_format = 'png' elif save_format[0] in ['jpg', 'jpeg']: save_quality = int(save_format[1]) if len(save_format) > 1 else 100 save_ext = 'jpg' save_format = 'jpeg' elif save_format[0] == 'webp': save_quality = int(save_format[1]) if len(save_format) > 1 else 100 save_ext = 'webp' save_format = 'webp' if save_quality < 0: # e.g. webp:-100 for lossless mode save_lossless = True save_quality = abs(save_quality) # this should force GFPGAN and RealESRGAN onto the selected gpu as well os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152 os.environ["CUDA_VISIBLE_DEVICES"] = str(st.session_state["defaults"].general.gpu) def set_page_title(title): """ Simple function to allows us to change the title dynamically. Normally you can use `st.set_page_config` to change the title but it can only be used once per app. """ st.sidebar.markdown(unsafe_allow_html=True, body=f"""