From 2ae62773f3081207830069ff8623de7a0c6333c6 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:16:56 -0700 Subject: [PATCH 01/16] Allow resizing for larger images but lock to a minimum size --- neuro-gui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neuro-gui.py b/neuro-gui.py index 07b7368..3a55256 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -24,10 +24,10 @@ class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.setFixedSize(900, 800) self.setWindowTitle("Neuro-Image-Generator-GUI") self.out_dir = "outputs/txt2img-samples/samples" self.seed = 27 + self.setBaseSize(1000, 1000) self.ddim_steps = 50 self.plms = False self.laion = False @@ -174,6 +174,6 @@ def plms_func(self, state): if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() - window.show() + window.showNormal() app.exec_() From f674646d3f80c14791ef291765ca3bde9b239d45 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:17:26 -0700 Subject: [PATCH 02/16] Clarify window title --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 3a55256..9349ab6 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -24,10 +24,10 @@ class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.setWindowTitle("Neuro-Image-Generator-GUI") self.out_dir = "outputs/txt2img-samples/samples" self.seed = 27 self.setBaseSize(1000, 1000) + self.setWindowTitle("Stable Diffusion GUI") self.ddim_steps = 50 self.plms = False self.laion = False From b107d2c6e6906cffad9b64a4c37887e4cdeff52d Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:18:47 -0700 Subject: [PATCH 03/16] Use absolute path for default output directory --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 9349ab6..6af62b8 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -24,10 +24,10 @@ class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.out_dir = "outputs/txt2img-samples/samples" self.seed = 27 self.setBaseSize(1000, 1000) self.setWindowTitle("Stable Diffusion GUI") + self.out_dir = os.path.join(os.getcwd(), "outputs/txt2img-samples") self.ddim_steps = 50 self.plms = False self.laion = False From 569c975808ad3495c5ebcbd6cbdff7a85a470d48 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:20:13 -0700 Subject: [PATCH 04/16] Choose a random seed every time (for me this kept the same image from re-appearing) --- neuro-gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 6af62b8..b0f985e 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -7,6 +7,7 @@ import logging import os import subprocess +import random class QTextEditLogger(logging.Handler): def __init__(self, parent): @@ -24,10 +25,10 @@ class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.seed = 27 self.setBaseSize(1000, 1000) self.setWindowTitle("Stable Diffusion GUI") self.out_dir = os.path.join(os.getcwd(), "outputs/txt2img-samples") + self.seed = random.randint(1,2147483647) self.ddim_steps = 50 self.plms = False self.laion = False From 704c4a38638595cad702b0874661a96722f7ea29 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:21:37 -0700 Subject: [PATCH 05/16] set plms to True by default and show in UI. --- neuro-gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index b0f985e..af322e8 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -30,7 +30,7 @@ def __init__(self, *args, **kwargs): self.out_dir = os.path.join(os.getcwd(), "outputs/txt2img-samples") self.seed = random.randint(1,2147483647) self.ddim_steps = 50 - self.plms = False + self.plms = True self.laion = False self.height = 512 self.width = 512 @@ -59,6 +59,7 @@ def _init_settings(self): self.width_line = QLineEdit(self) self.plms_bool = QCheckBox("Enable plms", self) self.laion_bool = QCheckBox("Enable laion",self) + self.plms_bool.setCheckState(2 if self.plms is True else 0) self.start_button = QtWidgets.QPushButton(self) self.start_button.setText("Start!") From 6fc62f35ead412514999e88f88fc02d99740bdbc Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:22:08 -0700 Subject: [PATCH 06/16] Give more room for output directory --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index af322e8..03185eb 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -66,7 +66,7 @@ def _init_settings(self): self.select_dir_button = QtWidgets.QPushButton(self) self.select_dir_button.setText("Select Output Directory") self.out_log = QLabel(self.out_dir) - self.out_log.setFixedWidth(120) + self.out_log.setFixedWidth(500) self.layout.addRow(QLabel("Prompt:"), self.prompt) self.layout.addRow(QLabel("Seed:"), self.seed_line) From b1ce69ed827a47b3766b540c1ab2d8983f2cf849 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:25:02 -0700 Subject: [PATCH 07/16] Always display most recently created file no matter the name --- neuro-gui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 03185eb..d97f491 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -8,6 +8,7 @@ import os import subprocess import random +import glob class QTextEditLogger(logging.Handler): def __init__(self, parent): @@ -153,7 +154,8 @@ def start(self): generated_string += "--skip_grid --n_samples 1" process = subprocess.call(generated_string) - last_image = self.out_dir + "/samples/" + os.listdir(self.out_dir + "/samples")[-1] + last_images = glob.glob(os.path.join(self.out_dir, 'samples/*')) + last_image = max(last_images, key=os.path.getctime) self._set_image(last_image) def sel_dir(self): From 8bbc6569063549e7df8c3c3c1e792ba28ef165e6 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:28:12 -0700 Subject: [PATCH 08/16] Put "out" directory on its own line to maximize width --- neuro-gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index d97f491..723e38c 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -75,7 +75,8 @@ def _init_settings(self): self.layout.addRow(QLabel("Height:"), self.height_line) self.layout.addRow(QLabel("Width:"), self.width_line) self.layout.addRow(self.plms_bool,self.laion_bool) - self.layout.addRow(QLabel("Current Out Dir:"), self.out_log) + self.layout.addRow(QLabel("Current Out Dir:")) + self.layout.addRow(self.out_log) self.layout.addRow(self.select_dir_button) self.layout.addRow(self.start_button) From 5dc841ff59fb644713d1d8a6b4b89bcafa60fc4c Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:29:12 -0700 Subject: [PATCH 09/16] Use --n_iter 1 to only generate a single image rather than two --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 723e38c..758ac74 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -153,7 +153,7 @@ def start(self): logging.debug(generated_string) - generated_string += "--skip_grid --n_samples 1" + generated_string += "--skip_grid --n_samples 1 --n_iter 1" process = subprocess.call(generated_string) last_images = glob.glob(os.path.join(self.out_dir, 'samples/*')) last_image = max(last_images, key=os.path.getctime) From 0e9079b6977588582cc670dece1023580ff9a8f4 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:40:57 -0700 Subject: [PATCH 10/16] use subprocess.run() instead of call + use shell=True to avoid Linux error Run is recommended over call see: https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 758ac74..813feea 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -154,7 +154,7 @@ def start(self): logging.debug(generated_string) generated_string += "--skip_grid --n_samples 1 --n_iter 1" - process = subprocess.call(generated_string) + process = subprocess.run(generated_string, shell=True) last_images = glob.glob(os.path.join(self.out_dir, 'samples/*')) last_image = max(last_images, key=os.path.getctime) self._set_image(last_image) From 608c466f30732ebfae44a47d4c09c4c5302405c2 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 15:43:26 -0700 Subject: [PATCH 11/16] Minor formatting (extra spaces, etc.) --- neuro-gui.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/neuro-gui.py b/neuro-gui.py index 813feea..93a70cd 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -10,26 +10,27 @@ import random import glob + class QTextEditLogger(logging.Handler): def __init__(self, parent): super().__init__() self.widget = QtWidgets.QPlainTextEdit(parent) self.widget.setFixedWidth(512) self.widget.setReadOnly(True) - def emit(self, record): msg = self.format(record) self.widget.appendPlainText(msg) + class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - + self.setBaseSize(1000, 1000) self.setWindowTitle("Stable Diffusion GUI") self.out_dir = os.path.join(os.getcwd(), "outputs/txt2img-samples") - self.seed = random.randint(1,2147483647) + self.seed = random.randint(1, 2147483647) self.ddim_steps = 50 self.plms = True self.laion = False @@ -37,17 +38,16 @@ def __init__(self, *args, **kwargs): self.width = 512 self.start_command = 'python scripts/txt2img.py --prompt' self._setMainUi() - - + def _init_layouts(self): - self.widget = QWidget() + self.widget = QWidget() self.left_panel = QVBoxLayout() self.right_panel = QVBoxLayout() self.tree_settings = QHBoxLayout() self.layer_hor = QHBoxLayout() self.formGroupBox = QGroupBox("Settings") self.layout = QFormLayout() - + def _set_image(self, image: str = "rickroll.jpg"): self.pixmap = QPixmap(image) self.label.setPixmap(self.pixmap) @@ -59,7 +59,7 @@ def _init_settings(self): self.height_line = QLineEdit(self) self.width_line = QLineEdit(self) self.plms_bool = QCheckBox("Enable plms", self) - self.laion_bool = QCheckBox("Enable laion",self) + self.laion_bool = QCheckBox("Enable laion", self) self.plms_bool.setCheckState(2 if self.plms is True else 0) self.start_button = QtWidgets.QPushButton(self) @@ -74,7 +74,7 @@ def _init_settings(self): self.layout.addRow(QLabel("Ddim Steps:"), self.ddim_line) self.layout.addRow(QLabel("Height:"), self.height_line) self.layout.addRow(QLabel("Width:"), self.width_line) - self.layout.addRow(self.plms_bool,self.laion_bool) + self.layout.addRow(self.plms_bool, self.laion_bool) self.layout.addRow(QLabel("Current Out Dir:")) self.layout.addRow(self.out_log) self.layout.addRow(self.select_dir_button) @@ -93,7 +93,7 @@ def _init_log(self): self.logTextBox.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) logging.getLogger().addHandler(self.logTextBox) logging.getLogger().setLevel(logging.DEBUG) - + def _init_left_panel(self): self.label = QLabel(self) self._set_image() @@ -126,13 +126,13 @@ def start(self): generated_string += "--plms " if self.laion: generated_string += "--laion400m " - + if self.seed_line.text() != "": generated_string += "--seed " + str(self.seed_line.text()) + " " if self.seed_line.text() == "": generated_string += "--seed " + str(self.seed) + " " - + if self.height_line.text() == "": generated_string += f"--H {str(self.height)} " if self.width_line.text() == "": @@ -168,7 +168,7 @@ def laion_func(self, state): self.laion = True else: self.laion = False - + def plms_func(self, state): if state == QtCore.Qt.Checked: self.plms = True From a843664603d5fdb7c107735b647954ba8c3a26d7 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 16:17:50 -0700 Subject: [PATCH 12/16] If directory selection is canceled, keep existing directory. --- neuro-gui.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 93a70cd..031c52d 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -160,7 +160,10 @@ def start(self): self._set_image(last_image) def sel_dir(self): - self.out_dir = str(QFileDialog.getExistingDirectory(self, "Select Directory")) + tmp = self.out_dir + self.out_dir = str(QFileDialog.getExistingDirectory(self, "Select \"outputs\" Directory")) + if not os.path.isdir(self.out_dir): + self.out_dir = tmp self.out_log.setText(self.out_dir) def laion_func(self, state): From d689536148d078e31db8eb9a2958d12eaf76a142 Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 16:19:20 -0700 Subject: [PATCH 13/16] Select an "outputs" directory and only use txt2img-samples if it exists --- neuro-gui.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/neuro-gui.py b/neuro-gui.py index 031c52d..375d791 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs): self.setBaseSize(1000, 1000) self.setWindowTitle("Stable Diffusion GUI") - self.out_dir = os.path.join(os.getcwd(), "outputs/txt2img-samples") + self.out_dir = os.path.join(os.getcwd(), "outputs") self.seed = random.randint(1, 2147483647) self.ddim_steps = 50 self.plms = True @@ -65,7 +65,7 @@ def _init_settings(self): self.start_button = QtWidgets.QPushButton(self) self.start_button.setText("Start!") self.select_dir_button = QtWidgets.QPushButton(self) - self.select_dir_button.setText("Select Output Directory") + self.select_dir_button.setText("Select \"outputs\" Directory") self.out_log = QLabel(self.out_dir) self.out_log.setFixedWidth(500) @@ -75,7 +75,7 @@ def _init_settings(self): self.layout.addRow(QLabel("Height:"), self.height_line) self.layout.addRow(QLabel("Width:"), self.width_line) self.layout.addRow(self.plms_bool, self.laion_bool) - self.layout.addRow(QLabel("Current Out Dir:")) + self.layout.addRow(QLabel("Current \"outputs\" Directory:")) self.layout.addRow(self.out_log) self.layout.addRow(self.select_dir_button) self.layout.addRow(self.start_button) @@ -148,8 +148,10 @@ def start(self): if self.ddim_line.text() == "": generated_string += f"--ddim_steps {str(self.ddim_steps)} " - if self.out_dir != "outputs/samples": - generated_string += f"--outdir {self.out_dir} " + if os.path.exists(os.path.join(self.out_dir, "txt2img-samples")): + self.out_dir = os.path.join(self.out_dir, "txt2img-samples") + + generated_string += f"--outdir {self.out_dir} " logging.debug(generated_string) From 2c1a96606bb936039359d98a18be4e68cbed099c Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 16:28:18 -0700 Subject: [PATCH 14/16] Set/show default values --- neuro-gui.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/neuro-gui.py b/neuro-gui.py index 375d791..9f00c9e 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -27,6 +27,7 @@ class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) + self.prompt="a photograph of an astronaut riding a horse" self.setBaseSize(1000, 1000) self.setWindowTitle("Stable Diffusion GUI") self.out_dir = os.path.join(os.getcwd(), "outputs") @@ -53,14 +54,20 @@ def _set_image(self, image: str = "rickroll.jpg"): self.label.setPixmap(self.pixmap) def _init_settings(self): - self.prompt = QLineEdit(self) + self.prompt_line = QLineEdit(self) + self.prompt_line.setText(self.prompt) self.seed_line = QLineEdit(self) + self.seed_line.setText(str(self.seed)) self.ddim_line = QLineEdit(self) + self.ddim_line.setText(str(self.ddim_steps)) self.height_line = QLineEdit(self) + self.height_line.setText(str(self.height)) self.width_line = QLineEdit(self) + self.width_line.setText(str(self.width)) self.plms_bool = QCheckBox("Enable plms", self) - self.laion_bool = QCheckBox("Enable laion", self) self.plms_bool.setCheckState(2 if self.plms is True else 0) + self.laion_bool = QCheckBox("Enable laion", self) + self.laion_bool.setCheckState(2 if self.laion is True else 0) self.start_button = QtWidgets.QPushButton(self) self.start_button.setText("Start!") @@ -69,7 +76,7 @@ def _init_settings(self): self.out_log = QLabel(self.out_dir) self.out_log.setFixedWidth(500) - self.layout.addRow(QLabel("Prompt:"), self.prompt) + self.layout.addRow(QLabel("Prompt:"), self.prompt_line) self.layout.addRow(QLabel("Seed:"), self.seed_line) self.layout.addRow(QLabel("Ddim Steps:"), self.ddim_line) self.layout.addRow(QLabel("Height:"), self.height_line) @@ -121,7 +128,7 @@ def _setMainUi(self): self.setCentralWidget(self.widget) def start(self): - generated_string = self.start_command + f' "{str(self.prompt.text())}" ' + generated_string = self.start_command + f' "{str(self.prompt_line.text())}" ' if self.plms: generated_string += "--plms " if self.laion: From 7f6cc7d162b6bfd76b43544b59c4ace20fc48e9d Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 16:58:55 -0700 Subject: [PATCH 15/16] Add a "randomize seed" button. --- neuro-gui.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/neuro-gui.py b/neuro-gui.py index 9f00c9e..4adef22 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -69,6 +69,9 @@ def _init_settings(self): self.laion_bool = QCheckBox("Enable laion", self) self.laion_bool.setCheckState(2 if self.laion is True else 0) + self.new_seed_button = QtWidgets.QPushButton(self) + self.new_seed_button.setText("Randomize Seed") + self.start_button = QtWidgets.QPushButton(self) self.start_button.setText("Start!") self.select_dir_button = QtWidgets.QPushButton(self) @@ -85,6 +88,7 @@ def _init_settings(self): self.layout.addRow(QLabel("Current \"outputs\" Directory:")) self.layout.addRow(self.out_log) self.layout.addRow(self.select_dir_button) + self.layout.addRow(self.new_seed_button) self.layout.addRow(self.start_button) self._init_button_slots() @@ -94,6 +98,7 @@ def _init_button_slots(self): self.select_dir_button.clicked.connect(self.sel_dir) self.laion_bool.stateChanged.connect(self.laion_func) self.plms_bool.stateChanged.connect(self.plms_func) + self.new_seed_button.clicked.connect(self.new_seed) def _init_log(self): self.logTextBox = QTextEditLogger(self) @@ -187,6 +192,10 @@ def plms_func(self, state): else: self.plms = False + def new_seed(self): + self.seed = random.randint(1, 2147483647) + self.seed_line.setText(str(self.seed)) + if __name__ == '__main__': app = QApplication(sys.argv) From 312f3c617fe399c76a63db461c1487b286aed09c Mon Sep 17 00:00:00 2001 From: fattire Date: Sun, 28 Aug 2022 17:09:36 -0700 Subject: [PATCH 16/16] Use a default width of 640, it's more visually pleasing I think. --- neuro-gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuro-gui.py b/neuro-gui.py index 4adef22..bc4dcd1 100644 --- a/neuro-gui.py +++ b/neuro-gui.py @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs): self.plms = True self.laion = False self.height = 512 - self.width = 512 + self.width = 640 self.start_command = 'python scripts/txt2img.py --prompt' self._setMainUi()