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
35 changes: 27 additions & 8 deletions stablehorde/gimp-stable-diffusion-horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def checkStatus():
elif data["done"] == True:
return

def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, nsfw, prompt, apikey, maxWaitMin):
def generate(image, drawable, mode, selModel, initStrength, promptStrength, steps, seed, nsfw, prompt, apikey, maxWaitMin):
if image.width < 384 or image.width > 1024 or image.height < 384 or image.height > 1024:
raise Exception("Invalid image size. Image needs to be between 384x384 and 1024x1024.")

Expand All @@ -131,9 +131,10 @@ def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, n

pdb.gimp_progress_init("", None)

global checkMax
global checkMax, modelList
checkMax = (maxWaitMin * 60)/CHECK_WAIT

selectedModel = [ modelList[selModel] ]

try:
params = {
"cfg_scale": float(promptStrength),
Expand All @@ -143,12 +144,13 @@ def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, n

data = {
"params": params,
"models": selectedModel,
"prompt": prompt,
"nsfw": nsfw,
"censor_nsfw": False,
"r2": True
}

if image.width % 64 != 0:
width = math.floor(image.width/64) * 64
else:
Expand All @@ -169,10 +171,10 @@ def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, n
params.update({"denoising_strength": (1 - float(initStrength))})
elif mode == "MODE_INPAINTING":
init = getImageData(image, drawable)
models = ["stable_diffusion_inpainting"]
#models = ["stable_diffusion_inpainting"]
data.update({"source_image": init})
data.update({"source_processing": "inpainting"})
data.update({"models": models})
#data.update({"models": models})

data = json.dumps(data)

Expand Down Expand Up @@ -218,6 +220,22 @@ def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, n

return

def getAvailModels():

url = API_ROOT + "status/models?type=image"
response = urllib2.urlopen(url)
data = response.read()
data = json.loads(data)

modelList = []
for model in data:
modelList.append(model["name"])
modelList = sorted(modelList)

return modelList

modelList = getAvailModels()

register(
"stable-horde",
"stable-horde",
Expand All @@ -233,14 +251,15 @@ def generate(image, drawable, mode, initStrength, promptStrength, steps, seed, n
("Image -> Image", "MODE_IMG2IMG"),
("Inpainting", "MODE_INPAINTING")
)),
(PF_OPTION, "selModel", "Model", 0, modelList),
(PF_SLIDER, "initStrength", "Init Strength", 0.3, (0, 1, 0.1)),
(PF_SLIDER, "promptStrength", "Prompt Strength", 8, (0, 20, 1)),
(PF_SLIDER, "steps", "Steps", 50, (10, 150, 1)),
(PF_STRING, "seed", "Seed (optional)", ""),
(PF_TOGGLE, "nsfw", "NSFW", False),
(PF_TOGGLE, "nsfw", "NSFW", True),
(PF_STRING, "prompt", "Prompt", ""),
(PF_STRING, "apiKey", "API key (optional)", ""),
(PF_SLIDER, "maxWaitMin", "Max Wait (minutes)", 5, (1, 5, 1))
(PF_SLIDER, "maxWaitMin", "Max Wait (minutes)", 5, (1, 15, 1))
],
[],
generate
Expand Down