Skip to content

Commit 5b32665

Browse files
committed
Merge PR Nerogar#1445 into preview
2 parents 1b2ca9a + 23ad1a2 commit 5b32665

98 files changed

Lines changed: 7639 additions & 6773 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# development
2+
PLAN.md # claude's planning file, kept local-only
23
.idea
34
*.bak
45
*.pyc

modules/ui/AdditionalEmbeddingsTab.py

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
from modules.util.config.TrainConfig import TrainConfig, TrainEmbeddingConfig
3+
4+
5+
class AdditionalEmbeddingsTabController:
6+
def __init__(self, config: TrainConfig):
7+
self.train_config = config
8+
9+
def create_new_element(self) -> TrainEmbeddingConfig:
10+
return TrainEmbeddingConfig.default_values()
11+
12+
def randomize_uuid(self, embedding_config: TrainEmbeddingConfig) -> TrainEmbeddingConfig:
13+
embedding_config.uuid = TrainEmbeddingConfig.default_values().uuid
14+
return embedding_config
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
from modules.ui.BaseConfigListView import BaseConfigListView
3+
from modules.util import path_util
4+
5+
import customtkinter as ctk
6+
7+
8+
class BaseAdditionalEmbeddingsTabView(BaseConfigListView):
9+
10+
def refresh_ui(self):
11+
if self.element_list is not None:
12+
self._destroy_frame(self.element_list)
13+
self.element_list = None
14+
self.widgets_initialized = False
15+
self._create_element_list()
16+
17+
def open_element_window(self, i, ui_state) -> ctk.CTkToplevel:
18+
pass
19+
20+
21+
class BaseEmbeddingWidgetView:
22+
23+
def __init__(self, components):
24+
self.components = components
25+
26+
def build_content(self, top_frame, bottom_frame, ui_state, i, save_command, remove_command, clone_command, controller):
27+
self.ui_state = ui_state
28+
self.i = i
29+
self.save_command = save_command
30+
31+
# close button
32+
self.components.colored_icon_button(top_frame, 0, 0, "X", "#C00000", lambda: remove_command(self.i))
33+
34+
# clone button
35+
self.components.colored_icon_button(top_frame, 0, 1, "+", "#00C000", lambda: clone_command(self.i, controller.randomize_uuid), padx=5)
36+
37+
# embedding model names
38+
self.components.label(top_frame, 0, 2, "base embedding:",
39+
tooltip="The base embedding to train on. Leave empty to create a new embedding")
40+
self.components.path_entry(
41+
top_frame, 0, 3, self.ui_state, "model_name",
42+
mode="file", path_modifier=path_util.json_path_modifier
43+
)
44+
45+
# placeholder
46+
self.components.label(top_frame, 0, 4, "placeholder:",
47+
tooltip="The placeholder used when using the embedding in a prompt")
48+
self.components.entry(top_frame, 0, 5, self.ui_state, "placeholder")
49+
50+
# token count
51+
self.components.label(top_frame, 0, 6, "token count:",
52+
tooltip="The token count used when creating a new embedding. Leave empty to auto detect from the initial embedding text.")
53+
self.components.entry(top_frame, 0, 7, self.ui_state, "token_count", width=40)
54+
55+
# trainable
56+
self.components.label(bottom_frame, 0, 0, "train:")
57+
self.components.switch(bottom_frame, 0, 1, self.ui_state, "train", command=save_command, width=40)
58+
59+
# output embedding
60+
self.components.label(bottom_frame, 0, 2, "output embedding:",
61+
tooltip="Output embeddings are calculated at the output of the text encoder, not the input. This can improve results for larger text encoders and lower VRAM usage.")
62+
self.components.switch(bottom_frame, 0, 3, self.ui_state, "is_output_embedding", width=40)
63+
64+
# stop training after
65+
self.components.label(bottom_frame, 0, 4, "stop training after:",
66+
tooltip="When to stop training the embedding")
67+
self.components.time_entry(bottom_frame, 0, 5, self.ui_state, "stop_training_after", "stop_training_after_unit")
68+
69+
# initial embedding text
70+
self.components.label(bottom_frame, 0, 6, "initial embedding text:",
71+
tooltip="The initial embedding text used when creating a new embedding")
72+
self.components.entry(bottom_frame, 0, 7, self.ui_state, "initial_embedding_text")
73+
74+
def configure_element(self):
75+
pass

modules/ui/BaseCaptionUIView.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import platform
2+
from abc import ABC, abstractmethod
3+
4+
5+
class BaseCaptionUIView(ABC):
6+
def __init__(self, components):
7+
self.components = components
8+
9+
@abstractmethod
10+
def open_directory(self): pass
11+
12+
@abstractmethod
13+
def open_mask_window(self): pass
14+
15+
@abstractmethod
16+
def open_caption_window(self): pass
17+
18+
@abstractmethod
19+
def open_in_explorer(self): pass
20+
21+
@abstractmethod
22+
def draw_mask_editing_mode(self, *args): pass
23+
24+
@abstractmethod
25+
def fill_mask_editing_mode(self, *args): pass
26+
27+
def build_top_bar(self, frame, controller, ui_state):
28+
self.components.button(frame, 0, 0, "Open", self.open_directory,
29+
tooltip="open a new directory")
30+
self.components.button(frame, 0, 1, "Generate Masks", self.open_mask_window,
31+
tooltip="open a dialog to automatically generate masks")
32+
self.components.button(frame, 0, 2, "Generate Captions", self.open_caption_window,
33+
tooltip="open a dialog to automatically generate captions")
34+
35+
if platform.system() == "Windows":
36+
self.components.button(frame, 0, 3, "Open in Explorer", self.open_in_explorer,
37+
tooltip="open the current image in Explorer")
38+
39+
self.components.switch(frame, 0, 4, ui_state, "include_subdirectories",
40+
text="include subdirectories")
41+
42+
frame.grid_columnconfigure(5, weight=1)
43+
44+
self.components.button(frame, 0, 6, "Help", controller.print_help,
45+
tooltip=controller.help_text)
46+
47+
def build_mask_buttons(self, right_frame):
48+
self.components.button(right_frame, 0, 0, "Draw", self.draw_mask_editing_mode,
49+
tooltip="draw a mask using a brush")
50+
self.components.button(right_frame, 0, 1, "Fill", self.fill_mask_editing_mode,
51+
tooltip="draw a mask using a fill tool")

0 commit comments

Comments
 (0)