Added new implementation of the textual inversion page. (#1342)

This commit is contained in:
Alejandro Gil 2022-09-27 11:36:48 -07:00 committed by GitHub
parent f4676517d8
commit 519d7c661f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 471 additions and 431 deletions

View File

@ -299,7 +299,9 @@ gfpgan:
strength: 100
textual_inversion:
value: 0
pretrained_model_name_or_path: "models/ldm/stable-diffusion-v1-4"
tokenizer_name: ""
daisi_app:
running_on_daisi_io: False

View File

@ -60,8 +60,10 @@ dependencies:
- streamlit-option-menu==0.3.2
- streamlit_nested_layout
- streamlit-server-state==0.14.2
- streamlit-tensorboard==0.0.2
- test-tube>=0.7.5
- tensorboard
- tensorboard==2.10.1
- torch-fidelity==0.3.0
- torchmetrics==0.6.0
- transformers==4.19.2
- wxPython==4.2.0

View File

@ -18,7 +18,7 @@ from webui_streamlit import st
# streamlit imports
from streamlit import StopException
from streamlit import StopException, StreamlitAPIException
#streamlit components section
from streamlit_server_state import server_state, server_state_lock
@ -267,8 +267,11 @@ def load_models(continue_prev_run = False, use_GFPGAN=False, use_RealESRGAN=Fals
if "pipe" in server_state:
del server_state["pipe"]
if "textual_inversion" in st.session_state:
del st.session_state['textual_inversion']
# At this point the model is either
# is not loaded yet or have been evicted:
# not loaded yet or have been evicted:
# load new model into memory
server_state["custom_model"] = custom_model
@ -612,6 +615,52 @@ def find_noise_for_image(model, device, init_image, prompt, steps=200, cond_scal
return x / sigmas[-1]
#
def folder_picker(label="Select:", value="", help="", folder_button_label="Select", folder_button_help="", folder_button_key=""):
"""A folder picker that has a text_input field next to it and a button to select the folder.
Returns the text_input field with the folder path."""
import tkinter as tk
from tkinter import filedialog
import string
# Set up tkinter
root = tk.Tk()
root.withdraw()
# Make folder picker dialog appear on top of other windows
root.wm_attributes('-topmost', 1)
col1, col2 = st.columns([2,1], gap="small")
with col1:
dirname = st.empty()
with col2:
st.write("")
st.write("")
folder_picker = st.empty()
# Folder picker button
#st.title('Folder Picker')
#st.write('Please select a folder:')
# Create a label and add a random number of invisible characters
# to it so no two buttons inside a form are the same.
#folder_button_label = ''.join(random.choice(f"{folder_button_label}") for _ in range(5))
folder_button_label = f"{str(folder_button_label)}{'' * random.randint(1, 500)}"
clicked = folder_button_key + '' * random.randint(5, 500)
#try:
#clicked = folder_picker.button(folder_button_label, help=folder_button_help, key=folder_button_key)
#except StreamlitAPIException:
clicked = folder_picker.form_submit_button(folder_button_label, help=folder_button_help)
if clicked:
dirname = dirname.text_input(label, filedialog.askdirectory(master=root), help=help)
else:
dirname = dirname.text_input(label, value, help=help)
return dirname
def get_sigmas_exponential(n, sigma_min, sigma_max, device='cpu'):
"""Constructs an exponential noise schedule."""

File diff suppressed because it is too large Load Diff

View File

@ -225,6 +225,9 @@ def load_diffusers_model(weights_path,torch_device):
with server_state_lock["model"]:
if "model" in server_state:
del server_state["model"]
if "textual_inversion" in st.session_state:
del st.session_state['textual_inversion']
try:
with server_state_lock["pipe"]:

View File

@ -162,7 +162,6 @@ def layout():
elif tabs == 'Textual Inversion':
# set the page url and title
st.experimental_set_query_params(page='textual-inversion')
set_page_title("Textual Inversion - Stable Diffusion Playground")
from textual_inversion import layout
layout()