Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions koi/koi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from io import BytesIO
from zipfile import ZipFile
import re
import random

class Koi(DockWidget):
def __init__(self):
Expand All @@ -19,6 +20,9 @@ def __init__(self):

self.setWindowTitle("Koi")

# Initializing random seed ===
random.seed(None)

# Main WIdget ===
self.mainWidget = QWidget(self)
self.mainWidget.setLayout(QVBoxLayout())
Expand All @@ -43,9 +47,12 @@ def __init__(self):
self.variations.setRange(1, 8)
self.variations.setValue(1)

self.base_seed_min = 0
self.base_seed_max = 100000000
self.base_seed = QSpinBox(self.input_widget)
self.base_seed.setRange(1, 100000000)
self.base_seed.setRange(self.base_seed_min-1, self.base_seed_max) #let -1 choosable
self.base_seed.setValue(1337)
self.base_seed.setToolTip('If set to -1, then the seed will be randomized in the background.')

self.sketch_strengh = QDoubleSpinBox(self.input_widget)
self.sketch_strengh.setRange(0.05, 0.95)
Expand All @@ -67,6 +74,12 @@ def __init__(self):

self.mainWidget.layout().addWidget(self.input_widget)

# Auto random seed checkbox ===
self.auto_random = QCheckBox(self.mainWidget)
self.auto_random.setText("Auto randomize seed after Dream")

self.mainWidget.layout().addWidget(self.auto_random)

# Endpoint Settings ===
self.endpoint_widget = QWidget(self.mainWidget)
self.endpoint_layout = QFormLayout()
Expand Down Expand Up @@ -106,7 +119,7 @@ def _get_extra_args(self):
"variations": str(self.variations.value()),
"prompt": self._prompt_text(),
"steps": str(self.steps.value()),
"seed": str(self.base_seed.value()),
"seed": str(self.getRandSeed() if self.base_seed.value()==-1 else self.base_seed.value()),
"sketch_strength": str(self.sketch_strengh.value()),
"prompt_strength": str(self.prompt_strength.value()),
}
Expand Down Expand Up @@ -141,6 +154,9 @@ def _add_paint_layer(self, doc, root, returned_file, name):
def _get_timeout(self):
return int(1.5 * self.steps.value()) * self.variations.value()

def getRandSeed(self):
return random.randint(self.base_seed_min,self.base_seed_max-self.variations.value())

def pingServer(self):
# get the current layer as a I/O buffer
image_buffer = self.layer2buffer()
Expand All @@ -164,6 +180,10 @@ def pingServer(self):
returned_file = QImage.fromData(file)
self._add_paint_layer(doc, root, returned_file, name)

# check for auto random needed
if self.auto_random.isChecked():
self.base_seed.setValue(self.getRandSeed())

# update user
doc.refreshProjection()

Expand Down