2022-10-02 06:03:39 -06:00
|
|
|
import html
|
|
|
|
|
|
|
|
import gradio as gr
|
|
|
|
|
2022-10-02 13:41:21 -06:00
|
|
|
import modules.textual_inversion.textual_inversion
|
2022-10-02 06:03:39 -06:00
|
|
|
from modules import sd_hijack, shared
|
|
|
|
|
|
|
|
|
2022-10-19 17:24:24 -06:00
|
|
|
def create_embedding(name, initialization_text, nvpt, overwrite_old):
|
|
|
|
filename = modules.textual_inversion.textual_inversion.create_embedding(name, nvpt, overwrite_old, init_text=initialization_text)
|
2022-10-02 06:03:39 -06:00
|
|
|
|
|
|
|
sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings()
|
|
|
|
|
|
|
|
return gr.Dropdown.update(choices=sorted(sd_hijack.model_hijack.embedding_db.word_embeddings.keys())), f"Created: {filename}", ""
|
|
|
|
|
|
|
|
|
|
|
|
def train_embedding(*args):
|
2022-10-11 09:33:57 -06:00
|
|
|
|
2022-10-11 14:07:09 -06:00
|
|
|
assert not shared.cmd_opts.lowvram, 'Training models with lowvram not possible'
|
2022-10-11 09:33:57 -06:00
|
|
|
|
2022-10-31 05:26:08 -06:00
|
|
|
apply_optimizations = shared.opts.training_xattention_optimizations
|
2022-10-02 06:03:39 -06:00
|
|
|
try:
|
2022-10-31 05:26:08 -06:00
|
|
|
if not apply_optimizations:
|
|
|
|
sd_hijack.undo_optimizations()
|
2022-10-02 06:03:39 -06:00
|
|
|
|
2022-10-02 13:41:21 -06:00
|
|
|
embedding, filename = modules.textual_inversion.textual_inversion.train_embedding(*args)
|
2022-10-02 06:03:39 -06:00
|
|
|
|
|
|
|
res = f"""
|
2022-10-02 12:09:10 -06:00
|
|
|
Training {'interrupted' if shared.state.interrupted else 'finished'} at {embedding.step} steps.
|
2022-10-02 06:03:39 -06:00
|
|
|
Embedding saved to {html.escape(filename)}
|
|
|
|
"""
|
|
|
|
return res, ""
|
|
|
|
except Exception:
|
|
|
|
raise
|
|
|
|
finally:
|
2022-10-31 05:26:08 -06:00
|
|
|
if not apply_optimizations:
|
|
|
|
sd_hijack.apply_optimizations()
|
2022-10-02 13:41:21 -06:00
|
|
|
|