Select style list to use (json files)
JeromeGH opened this issue · comments
Please implement the option to select between several style lists (json files)
I really dig this features as well, so I tried to bring this to work, but my styles won't just get not updated. Any thoughts on this? This was my approach after 8hrs of work (I am not a coder though)
I added a simple
def getFile(): styleFile = [f for f in os.listdir(folder) if f.endswith('.json')] return styleFile
and updated the class and the ui so far, but I am stuck on the automated update. I can select my files from the dropdown, but nothing happens.
`class StyleSelectorXL(scripts.Script):
def init(self) -> None:
super().init()
self.styleFile = getFile()
self.initial_file = gr.State(self.styleFile[0] if self.styleFile else "sdxl_styles.json")
self.styleNames = self.getStyles(self.initial_file.value)
def getStyles(self, selected_json_file):
global stylespath
json_path = os.path.join(folder, selected_json_file)
stylespath = json_path
json_data = get_json_content(json_path)
styles = read_sdxl_styles(json_data)
return styles
def updateStyles(self, selected_json_file):
self.initial_file.value = selected_json_file
self.styleNames = self.getStyles(selected_json_file)
print(f"Updated initial_file.value: {self.initial_file.value}")
print(f"Updated styleNames: {self.styleNames}")
def title(self):
return "Style Selector for SDXL 1.0"
def show(self, is_img2img):
return scripts.AlwaysVisible
def ui(self, is_img2img):
enabled = getattr(shared.opts, "enable_styleselector_by_default", True)
with gr.Group():
with gr.Accordion("SDXL Styles NEW", open=enabled):
with FormRow():
with FormColumn(min_width=160):
is_enabled = gr.Checkbox(
value=enabled, label="Enable Style Selector", info="Enable Or Disable Style Selector ")
with FormColumn(elem_id="Randomize Style"):
randomize = gr.Checkbox(
value=False, label="Randomize Style", info="This Will Override Selected Style")
with FormColumn(elem_id="Randomize For Each Iteration"):
randomizeEach = gr.Checkbox(
value=False, label="Randomize For Each Iteration", info="Every prompt in Batch Will Have Random Style")
with FormColumn():
json_file = gr.Dropdown(
self.styleFile,
value=self.styleFile[0] if self.styleFile else "sdxl_styles.json",
live=True,
multiselect=False,
label="Select Stylefile",
change=lambda selected: [print(f"Selected JSON File: {selected}"), setattr(initial_file, 'json_file', selected), self.updateStyles(selected)]
)
with FormRow():
with FormColumn(min_width=160):
allstyles = gr.Checkbox(
value=False, label="Generate All Styles In Order", info="To Generate Your Prompt in All Available Styles, Its Better to set batch count to " + str(len(self.styleNames)) + " ( Style Count)")
style_ui_type = shared.opts.data.get(
"styles_ui", "radio-buttons")
if style_ui_type == "select-list":
style = gr.Dropdown(
self.styleNames, value=self.styleNames[10], multiselect=False, label="Select Style")
else:
style = gr.Radio(
label='Style', choices=self.styleNames, value=self.styleNames[10])
# Ignore the error if the attribute is not present
return [is_enabled, randomize, randomizeEach, allstyles, style]`
I got something working here:
https://github.com/benjamin-bertram/StyleSelectorXL_JsonSelector