shorter names in json schema (neg/pre/postPrompt)

pull/75/head
GeorgLegato 2023-04-28 21:49:41 +02:00
parent c284fa24e5
commit 14b2f4edaa
5 changed files with 23 additions and 46 deletions

View File

@ -100,9 +100,9 @@ def putPrompts(files):
data = readJsonPrompt(file_contents,False) data = readJsonPrompt(file_contents,False)
return [ return [
gr.Textbox.update(data["commonPromptPrefix"]), gr.Textbox.update(data["prePrompt"]),
gr.DataFrame.update(data["prompts"]), gr.DataFrame.update(data["prompts"]),
gr.Textbox.update(data["commonPromptSuffix"]), gr.Textbox.update(data["postPromt"]),
gr.Textbox.update(data["negPrompt"]) gr.Textbox.update(data["negPrompt"])
] ]

View File

@ -7,40 +7,21 @@ from .static_variables import (
jsonprompt_schemafile jsonprompt_schemafile
) )
""" def completeOptionals(j):
json is valid, but not our current schema.
lets try something.
does it look like something usable?
def fixJson(j):
fixedJ = empty_prompt
try:
if isinstance(j, dict):
if "prompts" in j:
if "data" in j["prompts"]:
if isinstance (j["prompts"]["data"],list):
fixedJ["prompts"]["data"] = j["prompts"]["data"]
if not isinstance (fixedJ["prompts"]["data"][0].
if "headers" not in j["prompts"]:
fixedJ["prompts"]["headers"] = ["outpaint steps","prompt"]
else:
fixedJ["prompts"]["headers"] = j["prompts"]["headers"]
if "negPrompt" in j:
fixedJ["prompts"]["headers"]
if "commonPrompt" in j:
return j
except Exception:
raise "JsonFix: Failed on recovering json prompt"
return j
"""
def fixHeaders(j):
if isinstance(j, dict): if isinstance(j, dict):
if "prompts" in j: if "prompts" in j:
if "headers" not in j["prompts"]: if "headers" not in j["prompts"]:
j["prompts"]["headers"] = ["outpaint steps","prompt"] j["prompts"]["headers"] = ["outpaint steps","prompt"]
if "negPrompt" not in j:
j["prompts"]["negPrompt"]=""
if "prePrompt" not in j:
j["prompts"]["prePrompt"]=""
if "postPrompt" not in j:
j["prompts"]["postPrompt"]=""
return j return j
@ -49,11 +30,12 @@ def validatePromptJson_throws(data):
schema = json.load(s) schema = json.load(s)
try: try:
validate(instance=data, schema=schema) validate(instance=data, schema=schema)
except Exception: except Exception:
raise "Your prompts are not schema valid." raise "Your prompts are not schema valid."
#fixJson(data) #fixJson(data)
return fixHeaders(data) return completeOptionals(data)
def readJsonPrompt(txt, returnFailPrompt=False): def readJsonPrompt(txt, returnFailPrompt=False):

View File

@ -47,17 +47,14 @@
"negPrompt": { "negPrompt": {
"type": "string" "type": "string"
}, },
"commonPromptPrefix": { "prePrompt": {
"type": "string" "type": "string"
}, },
"commonPromptSuffix": { "postPrompt": {
"type": "string" "type": "string"
} }
}, },
"required": [ "required": [
"prompts", "prompts"
"negPrompt",
"commonPromptPrefix",
"commonPromptSuffix"
] ]
} }

View File

@ -4,20 +4,20 @@ import modules.sd_samplers
default_prompt = """ default_prompt = """
{ {
"commonPromptPrefix":"<lora:epiNoiseoffset_v2:0.6> ", "prePrompt":"<lora:epiNoiseoffset_v2:0.6> ",
"prompts":{ "prompts":{
"headers":["outpaint steps","prompt","img"], "headers":["outpaint steps","prompt","img"],
"data":[ "data":[
[0,"Huge spectacular Waterfall in a dense tropical forest,epic perspective,(vegetation overgrowth:1.3)(intricate, ornamentation:1.1),(baroque:1.1), fantasy, (realistic:1) digital painting , (magical,mystical:1.2) , (wide angle shot:1.4), (landscape composed:1.2)(medieval:1.1), divine,cinematic,(tropical forest:1.4),(river:1.3)mythology,india, volumetric lighting, Hindu ,epic"] [0,"Huge spectacular Waterfall in a dense tropical forest,epic perspective,(vegetation overgrowth:1.3)(intricate, ornamentation:1.1),(baroque:1.1), fantasy, (realistic:1) digital painting , (magical,mystical:1.2) , (wide angle shot:1.4), (landscape composed:1.2)(medieval:1.1), divine,cinematic,(tropical forest:1.4),(river:1.3)mythology,india, volumetric lighting, Hindu ,epic"]
] ]
}, },
"commonPromptSuffix":"style by Alex Horley Wenjun Lin greg rutkowski Ruan Jia (Wayne Barlowe:1.2)", "postPrompt":"style by Alex Horley Wenjun Lin greg rutkowski Ruan Jia (Wayne Barlowe:1.2)",
"negPrompt":"frames, border, edges, borderline, text, character, duplicate, error, out of frame, watermark, low quality, ugly, deformed, blur, bad-artist" "negPrompt":"frames, border, edges, borderline, text, character, duplicate, error, out of frame, watermark, low quality, ugly, deformed, blur, bad-artist"
} }
""" """
empty_prompt = ( empty_prompt = (
'{"prompts":{"data":[],"headers":["outpaint steps","prompt"]},"negPrompt":"", commonPromptPrefix:"", commonPromptSuffix}' '{"prompts":{"data":[],"headers":["outpaint steps","prompt"]},"negPrompt":"", prePrompt:"", postPrompt:""}'
) )
invalid_prompt = { invalid_prompt = {
@ -26,8 +26,8 @@ invalid_prompt = {
"headers": ["outpaint steps", "prompt"], "headers": ["outpaint steps", "prompt"],
}, },
"negPrompt": "Invalid prompt-json", "negPrompt": "Invalid prompt-json",
"commonPromptPrefix": "Invalid prompt", "prePromp": "Invalid prompt",
"commonPromptSuffix": "Invalid prompt" "postPrompt": "Invalid prompt"
} }
available_samplers = [ available_samplers = [

View File

@ -1,7 +1,5 @@
from modules import script_callbacks from modules import script_callbacks
from iz_helpers.ui import on_ui_tabs from iz_helpers.ui import on_ui_tabs
from iz_helpers.settings import on_ui_settings from iz_helpers.settings import on_ui_settings
script_callbacks.on_ui_tabs(on_ui_tabs) script_callbacks.on_ui_tabs(on_ui_tabs)
script_callbacks.on_ui_settings(on_ui_settings) script_callbacks.on_ui_settings(on_ui_settings)