commit 334c3e48a94e57ce1207e4478915ea67849d6b2f Author: ahgsql <35695543+ahgsql@users.noreply.github.com> Date: Fri Jul 28 00:42:52 2023 +0300 Release diff --git a/.history/README_20230709123111.md b/.history/README_20230709123111.md new file mode 100644 index 0000000..bed5d0e --- /dev/null +++ b/.history/README_20230709123111.md @@ -0,0 +1,38 @@ +# ExampleSendText +## what is this? +This is an extension for https://github.com/AUTOMATIC1111/stable-diffusion-webui + +## Goal +It's goal is to show extension developers how to send text to the textprompt textbox, +The code is contains comments to clarify some aspects. Feel free to play around with it!! + +## How to use it? + +locate Send centrum +![example](text_to_be_sent.png) + +Afterwards, input your text and click on send text. +The result will be as follows +> ![example](full_text.png) + + + +## credits +Making this extension required going through different extensions and +inspecting their code,which provide vital clues without this, the extension wouldn't exist. + + - https://github.com/Zyin055/Config-Presets + - https://github.com/anime-webui-colab/ext-aspect-ratio-preset + + + + + + + + + + + + + diff --git a/.history/README_20230728003913.md b/.history/README_20230728003913.md new file mode 100644 index 0000000..320d79a --- /dev/null +++ b/.history/README_20230728003913.md @@ -0,0 +1,106 @@ +## Style Selector for SDXL 1.0 + +This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0. + +### Styles + +Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel. + +### Installation + +Enter this repo's URL in Automatic1111's extension tab "Install from Url": + +https://github.com/ahgsql/StyleSelectorXL.git + +### Usage + +1. Import the required libraries and modules: + +```python +import contextlib +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os +``` + +2. Define a function to read JSON content from a file: + +```python +def get_json_content(file_path): + # ... + return json_data +``` + +3. Define a function to extract style names from the JSON data: + +```python +def read_sdxl_styles(json_data): + # ... + return names +``` + +4. Define a function to get the available styles: + +```python +def getStyles(): + # ... + return styles +``` + +5. Define functions to create positive and negative prompts based on the selected style: + +```python +def createPositive(style, positive): + # ... + return positive + +def createNegative(style, negative): + # ... + return negative +``` + +6. Create a class `StyleSelectorXL` that extends the `scripts.Script` class: + +```python +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + # ... (omitting other methods for brevity) + + def ui(self, is_img2img): + # ... + return [is_enabled, style] + + def process(self, p, is_enabled, style): + # ... +``` + +7. In the `__main__` section, create an instance of the `StyleSelectorXL` class and use the `gr.Interface` to expose the UI: + +```python +if __name__ == "__main__": + style_selector = StyleSelectorXL() + + iface = gr.Interface( + fn=style_selector, + inputs=["text" if is_img2img else gr.Image(), "checkbox", "radio"], + outputs=None, + title="Style Selector for SDXL 1.0", + description="Select a style to apply to the input.", + ) + + iface.launch() +``` + +Note: Make sure to replace "text" with "image" for the text-to-image scenario. + +### Example + +For a complete example on how to use the `StyleSelectorXL` class, refer to the provided code and integrate it with your existing project or application. + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/.history/README_20230728004004.md b/.history/README_20230728004004.md new file mode 100644 index 0000000..a9e648a --- /dev/null +++ b/.history/README_20230728004004.md @@ -0,0 +1,26 @@ +## Style Selector for SDXL 1.0 + +This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0. + +### Styles + +Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel. + +### Installation + +Enter this repo's URL in Automatic1111's extension tab "Install from Url": + +https://github.com/ahgsql/StyleSelectorXL.git + +### Usage + +Enable or Disable it On Extension's panel, Select Style then hit Generate! +The selected style will be applied to your current prompts. + +### Example + +For a complete example on how to use the `StyleSelectorXL` class, refer to the provided code and integrate it with your existing project or application. + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/.history/README_20230728004120.md b/.history/README_20230728004120.md new file mode 100644 index 0000000..72b3942 --- /dev/null +++ b/.history/README_20230728004120.md @@ -0,0 +1,27 @@ +## Style Selector for SDXL 1.0 + +This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0. + +### Styles + +Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel. + +### Installation + +Enter this repo's URL in Automatic1111's extension tab "Install from Url": + +https://github.com/ahgsql/StyleSelectorXL.git + +### Usage + +Enable or Disable it On Extension's panel, Write your subject into Prompt field, +Select Style then hit Generate! +The selected style will be applied to your current prompts. + +### Thanks + +Huge thanks for https://github.com/twri/sdxl_prompt_styler as i got style json file from his repo. + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/.history/README_20230728004134.md b/.history/README_20230728004134.md new file mode 100644 index 0000000..0bf85fa --- /dev/null +++ b/.history/README_20230728004134.md @@ -0,0 +1,27 @@ +## Style Selector for SDXL 1.0 + +This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0. + +### Styles + +Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel. + +### Installation + +Enter this repo's URL in Automatic1111's extension tab "Install from Url": + +https://github.com/ahgsql/StyleSelectorXL.git + +### Usage + +Enable or Disable it On Extension's panel, Write your subject into Prompt field, +Select Style then hit Generate! +The selected style will be applied to your current prompts. + +### Thanks + +Huge thanks for https://github.com/twri/sdxl_prompt_styler as i got style json file's original structure from his repo. + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/.history/scripts/SendtoTextImg_20230709123111.py b/.history/scripts/SendtoTextImg_20230709123111.py new file mode 100644 index 0000000..3ef71fc --- /dev/null +++ b/.history/scripts/SendtoTextImg_20230709123111.py @@ -0,0 +1,65 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + return old_text + " " + new_text # else join them together and send it to the textbox + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Example" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Send centrum", open=False): + send_text_button = gr.Button(value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + with contextlib.suppress(AttributeError): # Ignore the error if the attribute is not present + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + #https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": #postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": #postive prompt textbox + self.boxxIMG = component + + #this code below works aswell, you can send negative prompt text box,provided you change the code a little + #switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + #if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + #if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component + + + + + + + + diff --git a/.history/scripts/SendtoTextImg_20230727230227.py b/.history/scripts/SendtoTextImg_20230727230227.py new file mode 100644 index 0000000..b3fb272 --- /dev/null +++ b/.history/scripts/SendtoTextImg_20230727230227.py @@ -0,0 +1,65 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + return old_text + " " + new_text # else join them together and send it to the textbox + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Send centrum", open=False): + send_text_button = gr.Button(value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + with contextlib.suppress(AttributeError): # Ignore the error if the attribute is not present + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + #https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": #postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": #postive prompt textbox + self.boxxIMG = component + + #this code below works aswell, you can send negative prompt text box,provided you change the code a little + #switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + #if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + #if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component + + + + + + + + diff --git a/.history/scripts/SendtoTextImg_20230727230407.py b/.history/scripts/SendtoTextImg_20230727230407.py new file mode 100644 index 0000000..65033db --- /dev/null +++ b/.history/scripts/SendtoTextImg_20230727230407.py @@ -0,0 +1,64 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Send centrum", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/SendtoTextImg_20230727230414.py b/.history/scripts/SendtoTextImg_20230727230414.py new file mode 100644 index 0000000..d1985df --- /dev/null +++ b/.history/scripts/SendtoTextImg_20230727230414.py @@ -0,0 +1,64 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/SendtoTextImg_20230727230903.py b/.history/scripts/SendtoTextImg_20230727230903.py new file mode 100644 index 0000000..d1985df --- /dev/null +++ b/.history/scripts/SendtoTextImg_20230727230903.py @@ -0,0 +1,64 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727230902.py b/.history/scripts/StyleSelectorXL_20230727230902.py new file mode 100644 index 0000000..d1985df --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727230902.py @@ -0,0 +1,64 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class ExampleScript(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231505.py b/.history/scripts/StyleSelectorXL_20230727231505.py new file mode 100644 index 0000000..d3934ce --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231505.py @@ -0,0 +1,64 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231535.py b/.history/scripts/StyleSelectorXL_20230727231535.py new file mode 100644 index 0000000..e73cd6f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231535.py @@ -0,0 +1,150 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [text_to_be_sent, send_text_button] + + def process(self, p, text_to_be_sent): + if not is_enabled: + return + + if use_main_seed: + declone_seed = p.all_seeds[0] + elif declone_seed == -1: + declone_seed = int(random.randrange(4294967294)) + else: + declone_seed = int(declone_seed) + + # original_prompt = p.all_prompts[0] + # settings = f"gender={gender}, beginning={insert_start}, declone_weight={declone_weight}, main_seed={use_main_seed}, " + \ + # f"declone_seed={declone_seed}, exclude_regions={exclude_regions}" + p.extra_generation_params["CloneCleaner enabled"] = True + p.extra_generation_params["CC_gender"] = gender + p.extra_generation_params["CC_insert_start"] = insert_start + p.extra_generation_params["CC_declone_weight"] = declone_weight + p.extra_generation_params["CC_use_main_seed"] = use_main_seed + p.extra_generation_params["CC_declone_seed"] = declone_seed + if exclude_regions: + p.extra_generation_params["CC_exclude_regions"] = ",".join(exclude_regions) + if exclude_hairlength: + p.extra_generation_params["CC_exclude_hairlength"] = ",".join(exclude_hairlength) + if exclude_haircolor: + p.extra_generation_params["CC_exclude_haircolor"] = ",".join(exclude_haircolor) + + countrytree = self.prompt_tree["country"] + hairtree = self.prompt_tree["hair"] + + regions = sorted_difference(countrytree.keys(), exclude_regions) + hairlengths = sorted_difference(hairtree["length"].keys(), exclude_hairlength) + haircolors = sorted_difference(hairtree["color"].keys(), exclude_haircolor) + + use_name = "name" in use_components + use_country = "country" in use_components + use_length = "hair length" in use_components + use_style = "hair style" in use_components + use_color = "hair color" in use_components + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + rng = random.Random() + seed = p.all_seeds[i] if use_main_seed else declone_seed + i + rng.seed(seed) + + region = rng.choice(regions) + countries = list(countrytree[region].keys()) + countryweights = [countrytree[region][cty]["weight"] for cty in countries] + country = rng.choices(countries, weights=countryweights)[0] + + countrydata = countrytree[region][country] + hairdata = countrydata.get("hair", hairtree["defaultweight"][region]) + maincolor = rng.choices(haircolors, weights=[hairdata[col] for col in haircolors])[0] + color = rng.choice(hairtree["color"][maincolor]) + mainlength = rng.choice(hairlengths) + length = rng.choice(hairtree["length"][mainlength]) + style = rng.choice(hairtree["style"][mainlength]) + name = rng.choice(countrydata["names"]) + + inserted_prompt = "" + + if use_name or use_country: + inserted_prompt += name if use_name else "person" + inserted_prompt += " from " + country if use_country else "" + + if use_length or use_style or use_color: + if inserted_prompt: + inserted_prompt += ", " + if use_length: + inserted_prompt += length + " " + if use_style: + inserted_prompt += style + " " + if use_color: + inserted_prompt += color + " " + inserted_prompt += "hair" + + if inserted_prompt: + if declone_weight != 1: + inserted_prompt = f"({inserted_prompt}:{declone_weight})" + + if insert_start: + p.all_prompts[i] = inserted_prompt + ", " + prompt + else: + p.all_prompts[i] = prompt + ", " + inserted_prompt + + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231708.py b/.history/scripts/StyleSelectorXL_20230727231708.py new file mode 100644 index 0000000..9e60c4f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231708.py @@ -0,0 +1,118 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + rng = random.Random() + seed = p.all_seeds[i] if use_main_seed else declone_seed + i + rng.seed(seed) + + region = rng.choice(regions) + countries = list(countrytree[region].keys()) + countryweights = [countrytree[region][cty]["weight"] + for cty in countries] + country = rng.choices(countries, weights=countryweights)[0] + + countrydata = countrytree[region][country] + hairdata = countrydata.get( + "hair", hairtree["defaultweight"][region]) + maincolor = rng.choices(haircolors, weights=[ + hairdata[col] for col in haircolors])[0] + color = rng.choice(hairtree["color"][maincolor]) + mainlength = rng.choice(hairlengths) + length = rng.choice(hairtree["length"][mainlength]) + style = rng.choice(hairtree["style"][mainlength]) + name = rng.choice(countrydata["names"]) + + inserted_prompt = "" + + if use_name or use_country: + inserted_prompt += name if use_name else "person" + inserted_prompt += " from " + country if use_country else "" + + if use_length or use_style or use_color: + if inserted_prompt: + inserted_prompt += ", " + if use_length: + inserted_prompt += length + " " + if use_style: + inserted_prompt += style + " " + if use_color: + inserted_prompt += color + " " + inserted_prompt += "hair" + + if inserted_prompt: + + if insert_start: + p.all_prompts[i] = inserted_prompt + ", " + prompt + else: + p.all_prompts[i] = prompt + ", " + inserted_prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231728.py b/.history/scripts/StyleSelectorXL_20230727231728.py new file mode 100644 index 0000000..acf3492 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231728.py @@ -0,0 +1,114 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + rng = random.Random() + seed = p.all_seeds[i] if use_main_seed else declone_seed + i + rng.seed(seed) + + region = rng.choice(regions) + countries = list(countrytree[region].keys()) + countryweights = [countrytree[region][cty]["weight"] + for cty in countries] + country = rng.choices(countries, weights=countryweights)[0] + + countrydata = countrytree[region][country] + hairdata = countrydata.get( + "hair", hairtree["defaultweight"][region]) + maincolor = rng.choices(haircolors, weights=[ + hairdata[col] for col in haircolors])[0] + color = rng.choice(hairtree["color"][maincolor]) + mainlength = rng.choice(hairlengths) + length = rng.choice(hairtree["length"][mainlength]) + style = rng.choice(hairtree["style"][mainlength]) + name = rng.choice(countrydata["names"]) + + inserted_prompt = "" + + if use_name or use_country: + inserted_prompt += name if use_name else "person" + inserted_prompt += " from " + country if use_country else "" + + if use_length or use_style or use_color: + if inserted_prompt: + inserted_prompt += ", " + if use_length: + inserted_prompt += length + " " + if use_style: + inserted_prompt += style + " " + if use_color: + inserted_prompt += color + " " + inserted_prompt += "hair" + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231803.py b/.history/scripts/StyleSelectorXL_20230727231803.py new file mode 100644 index 0000000..2d3c5e0 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231803.py @@ -0,0 +1,79 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231809.py b/.history/scripts/StyleSelectorXL_20230727231809.py new file mode 100644 index 0000000..6691b5f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231809.py @@ -0,0 +1,79 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727231918.py b/.history/scripts/StyleSelectorXL_20230727231918.py new file mode 100644 index 0000000..9a32fa9 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727231918.py @@ -0,0 +1,79 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232247.py b/.history/scripts/StyleSelectorXL_20230727232247.py new file mode 100644 index 0000000..7b1c228 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232247.py @@ -0,0 +1,90 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def read_json_file(file_path): + try: + # Open file, load JSON content into python dictionary, and return it. + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232356.py b/.history/scripts/StyleSelectorXL_20230727232356.py new file mode 100644 index 0000000..07135d9 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232356.py @@ -0,0 +1,107 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def read_json_file(file_path): + try: + # Open file, load JSON content into python dictionary, and return it. + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"An error occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232544.py b/.history/scripts/StyleSelectorXL_20230727232544.py new file mode 100644 index 0000000..6d14ba3 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232544.py @@ -0,0 +1,118 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def read_json_file(file_path): + try: + # Open file, load JSON content into python dictionary, and return it. + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"An error occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + path = os.path.dirname(os.path.realpath(__file__)) + # Construct 'sdxl_styles.json' path + file_path = os.path.join(path, 'sdxl_styles.json') + + # Read JSON from file + self.json_data = read_json_file(file_path) + # Retrieve styles from JSON data + styles = read_sdxl_styles(self.json_data) + print(styles) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232637.py b/.history/scripts/StyleSelectorXL_20230727232637.py new file mode 100644 index 0000000..f7624e7 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232637.py @@ -0,0 +1,122 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def read_json_file(file_path): + try: + # Open file, load JSON content into python dictionary, and return it. + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + path = os.path.dirname(os.path.realpath(__file__)) + print(path) + # Construct 'sdxl_styles.json' path + file_path = os.path.join(path, 'sdxl_styles.json') + print(file_path) + + # Read JSON from file + self.json_data = read_json_file(file_path) + # Retrieve styles from JSON data + styles = read_sdxl_styles(self.json_data) + print(styles) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232827.py b/.history/scripts/StyleSelectorXL_20230727232827.py new file mode 100644 index 0000000..b70cb5e --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232827.py @@ -0,0 +1,119 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"An error occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + path = os.path.dirname(os.path.realpath(__file__)) + print(path) + # Construct 'sdxl_styles.json' path + file_path = os.path.join(path, 'sdxl_styles.json') + print(file_path) + + # Read JSON from file + self.json_data = read_json_file(file_path) + # Retrieve styles from JSON data + styles = read_sdxl_styles(self.json_data) + print(styles) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232832.py b/.history/scripts/StyleSelectorXL_20230727232832.py new file mode 100644 index 0000000..4f6799c --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232832.py @@ -0,0 +1,119 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + path = os.path.dirname(os.path.realpath(__file__)) + print(path) + # Construct 'sdxl_styles.json' path + file_path = os.path.join(path, 'sdxl_styles.json') + print(file_path) + + # Read JSON from file + self.json_data = read_json_file(file_path) + # Retrieve styles from JSON data + styles = read_sdxl_styles(self.json_data) + print(styles) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727232939.py b/.history/scripts/StyleSelectorXL_20230727232939.py new file mode 100644 index 0000000..515ce2e --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727232939.py @@ -0,0 +1,115 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(file_path) + + # Read JSON from file + self.json_data = read_json_file(file_path) + # Retrieve styles from JSON data + styles = read_sdxl_styles(self.json_data) + print(styles) + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233047.py b/.history/scripts/StyleSelectorXL_20230727233047.py new file mode 100644 index 0000000..99a1b54 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233047.py @@ -0,0 +1,117 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + +def getStyles(): + json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(self.json_data) + print(styles) + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + + + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233056.py b/.history/scripts/StyleSelectorXL_20230727233056.py new file mode 100644 index 0000000..f101cb5 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233056.py @@ -0,0 +1,118 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + +def getStyles(): + json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + + + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233110.py b/.history/scripts/StyleSelectorXL_20230727233110.py new file mode 100644 index 0000000..4aec456 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233110.py @@ -0,0 +1,120 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + +def getStyles(): + json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames=getStyles(); + print(styleNames) + + + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233114.py b/.history/scripts/StyleSelectorXL_20230727233114.py new file mode 100644 index 0000000..5327aef --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233114.py @@ -0,0 +1,119 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + +def getStyles(): + json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames=getStyles(); + print(styleNames) + + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable CloneCleaner") + send_text_button = gr.Button( + value='send text', variant='primary') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233237.py b/.history/scripts/StyleSelectorXL_20230727233237.py new file mode 100644 index 0000000..ad5e380 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233237.py @@ -0,0 +1,124 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + send_text_button = gr.Button( + value='send text', variant='primary') + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233428.py b/.history/scripts/StyleSelectorXL_20230727233428.py new file mode 100644 index 0000000..43d5592 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233428.py @@ -0,0 +1,109 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233450.py b/.history/scripts/StyleSelectorXL_20230727233450.py new file mode 100644 index 0000000..1bf4d01 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233450.py @@ -0,0 +1,109 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233452.py b/.history/scripts/StyleSelectorXL_20230727233452.py new file mode 100644 index 0000000..dd4dfb5 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233452.py @@ -0,0 +1,109 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233502.py b/.history/scripts/StyleSelectorXL_20230727233502.py new file mode 100644 index 0000000..03b33ad --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233502.py @@ -0,0 +1,107 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233525.py b/.history/scripts/StyleSelectorXL_20230727233525.py new file mode 100644 index 0000000..03b33ad --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233525.py @@ -0,0 +1,107 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233536.py b/.history/scripts/StyleSelectorXL_20230727233536.py new file mode 100644 index 0000000..383a85e --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233536.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727233754.py b/.history/scripts/StyleSelectorXL_20230727233754.py new file mode 100644 index 0000000..862ea4c --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727233754.py @@ -0,0 +1,122 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent, send_text_button] + + def process(self, p, is_enabled, text_to_be_sent, send_text_button): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234105.py b/.history/scripts/StyleSelectorXL_20230727234105.py new file mode 100644 index 0000000..9792074 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234105.py @@ -0,0 +1,122 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent,] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234108.py b/.history/scripts/StyleSelectorXL_20230727234108.py new file mode 100644 index 0000000..eff0cf6 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234108.py @@ -0,0 +1,122 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + print(styleNames) + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234115.py b/.history/scripts/StyleSelectorXL_20230727234115.py new file mode 100644 index 0000000..a3cb5e6 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234115.py @@ -0,0 +1,121 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + print(styles) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234120.py b/.history/scripts/StyleSelectorXL_20230727234120.py new file mode 100644 index 0000000..5c5c5e8 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234120.py @@ -0,0 +1,119 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + with contextlib.suppress(AttributeError): + if is_img2img: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox) + # Outputs: self.boxxIMG (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG]) + else: + # Bind the click event of the button to the send_text_to_prompt function + # Inputs: text_to_be_sent (textbox), self.boxx (textbox) + # Outputs: self.boxx (textbox) + send_text_button.click(fn=send_text_to_prompt, inputs=[ + text_to_be_sent, self.boxx], outputs=[self.boxx]) + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234140.py b/.history/scripts/StyleSelectorXL_20230727234140.py new file mode 100644 index 0000000..eb64676 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234140.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234218.py b/.history/scripts/StyleSelectorXL_20230727234218.py new file mode 100644 index 0000000..066c7d4 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234218.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent,style] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234223.py b/.history/scripts/StyleSelectorXL_20230727234223.py new file mode 100644 index 0000000..c0e6381 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234223.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent,style] + + def process(self, p, is_enabled, text_to_be_sent,style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234231.py b/.history/scripts/StyleSelectorXL_20230727234231.py new file mode 100644 index 0000000..ba2866f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234231.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234254.py b/.history/scripts/StyleSelectorXL_20230727234254.py new file mode 100644 index 0000000..bba8650 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234254.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234317.py b/.history/scripts/StyleSelectorXL_20230727234317.py new file mode 100644 index 0000000..5472662 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234317.py @@ -0,0 +1,107 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + print(style) + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234622.py b/.history/scripts/StyleSelectorXL_20230727234622.py new file mode 100644 index 0000000..eb64676 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234622.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=False): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234653.py b/.history/scripts/StyleSelectorXL_20230727234653.py new file mode 100644 index 0000000..c346ef6 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234653.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(self.styleNames, label="Location", + info="Where did they go?"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent] + + def process(self, p, is_enabled, text_to_be_sent): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234853.py b/.history/scripts/StyleSelectorXL_20230727234853.py new file mode 100644 index 0000000..1fa5bfe --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234853.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style =gr.Radio(label = 'Style', choices = self.styleNames, info="Select Your Style"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent,style] + + def process(self, p, is_enabled, text_to_be_sent,style): + if not is_enabled: + return + print(style) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727234911.py b/.history/scripts/StyleSelectorXL_20230727234911.py new file mode 100644 index 0000000..1f09832 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727234911.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector"), + style = gr.Radio( + label='Style', choices=self.styleNames, info="Select Your Style"), + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + print(style) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235044.py b/.history/scripts/StyleSelectorXL_20230727235044.py new file mode 100644 index 0000000..f1d3631 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235044.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + codec = gr.Radio(label = 'Codec', choices = ['x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value = 'x264') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + print(style) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235049.py b/.history/scripts/StyleSelectorXL_20230727235049.py new file mode 100644 index 0000000..3b1c5f4 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235049.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + codec = gr.Radio(label='Codec', choices=[ + 'x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value='x264') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, codec] + + def process(self, p, is_enabled, text_to_be_sent, codec): + if not is_enabled: + return + print(style) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235105.py b/.history/scripts/StyleSelectorXL_20230727235105.py new file mode 100644 index 0000000..20d4ad7 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235105.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + codec = gr.Radio(label='Codec', choices=[ + 'x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value='x264') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, codec] + + def process(self, p, is_enabled, text_to_be_sent, codec): + if not is_enabled: + return + print(codec) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235234.py b/.history/scripts/StyleSelectorXL_20230727235234.py new file mode 100644 index 0000000..efcf9fe --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235234.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio(label='Codec', choices=self.styleNames, value='sai-base') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + print(stylecodec) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235237.py b/.history/scripts/StyleSelectorXL_20230727235237.py new file mode 100644 index 0000000..c3e0829 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235237.py @@ -0,0 +1,106 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + text_to_be_sent = gr.Textbox(label="drop text") + + # Ignore the error if the attribute is not present + + return [is_enabled, text_to_be_sent, style] + + def process(self, p, is_enabled, text_to_be_sent, style): + if not is_enabled: + return + print(style) + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235322.py b/.history/scripts/StyleSelectorXL_20230727235322.py new file mode 100644 index 0000000..1b28e91 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235322.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235435.py b/.history/scripts/StyleSelectorXL_20230727235435.py new file mode 100644 index 0000000..b0b5675 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235435.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + print(p.all_prompts[i]) + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235527.py b/.history/scripts/StyleSelectorXL_20230727235527.py new file mode 100644 index 0000000..d7b9af0 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235527.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + print(p.all_prompts) + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235806.py b/.history/scripts/StyleSelectorXL_20230727235806.py new file mode 100644 index 0000000..d7b9af0 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235806.py @@ -0,0 +1,105 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + print(p.all_prompts) + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235810.py b/.history/scripts/StyleSelectorXL_20230727235810.py new file mode 100644 index 0000000..24c029f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235810.py @@ -0,0 +1,104 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235847.py b/.history/scripts/StyleSelectorXL_20230727235847.py new file mode 100644 index 0000000..fc469e2 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235847.py @@ -0,0 +1,110 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + for i, prompt in enumerate(p.all_negative_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230727235855.py b/.history/scripts/StyleSelectorXL_20230727235855.py new file mode 100644 index 0000000..4aca11f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230727235855.py @@ -0,0 +1,111 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + inserted_prompt = style + " ve negatif" + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000356.py b/.history/scripts/StyleSelectorXL_20230728000356.py new file mode 100644 index 0000000..0b97a46 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000356.py @@ -0,0 +1,143 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + +def createprompts(style,positive,negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError("Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError("Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == template_name: + positive_prompt = template['prompt'].replace('{prompt}', positive_prompt) + + json_negative_prompt = template.get('negative_prompt', "") + if negative_prompt: + negative_prompt = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt else negative_prompt + else: + negative_prompt = json_negative_prompt + + return positive_prompt, negative_prompt + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{template_name}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + inserted_prompt = style + " ve negatif" + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000429.py b/.history/scripts/StyleSelectorXL_20230728000429.py new file mode 100644 index 0000000..703197b --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000429.py @@ -0,0 +1,145 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive_prompt = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative_prompt: + negative_prompt = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt else negative_prompt + else: + negative_prompt = json_negative_prompt + + return positive_prompt, negative_prompt + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{template_name}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + inserted_prompt = style + " ve negatif" + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000535.py b/.history/scripts/StyleSelectorXL_20230728000535.py new file mode 100644 index 0000000..3001ad6 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000535.py @@ -0,0 +1,145 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{template_name}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + inserted_prompt = style + " ve negatif" + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000619.py b/.history/scripts/StyleSelectorXL_20230728000619.py new file mode 100644 index 0000000..156cd13 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000619.py @@ -0,0 +1,145 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + inserted_prompt = style + if inserted_prompt: + p.all_prompts[i] = inserted_prompt + ", " + prompt + + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + inserted_prompt = style + " ve negatif" + if inserted_prompt: + p.all_negative_prompts[i] = inserted_prompt + ", " + prompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000820.py b/.history/scripts/StyleSelectorXL_20230728000820.py new file mode 100644 index 0000000..42f87e2 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000820.py @@ -0,0 +1,140 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000827.py b/.history/scripts/StyleSelectorXL_20230728000827.py new file mode 100644 index 0000000..42f87e2 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000827.py @@ -0,0 +1,140 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728000935.py b/.history/scripts/StyleSelectorXL_20230728000935.py new file mode 100644 index 0000000..a165ad1 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728000935.py @@ -0,0 +1,140 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def send_text_to_prompt(new_text, old_text): + if old_text == "": # if text on the textbox text2img or img2img is empty, return new text + return new_text + # else join them together and send it to the textbox + return old_text + " " + new_text + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt,"") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style,"", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001229.py b/.history/scripts/StyleSelectorXL_20230728001229.py new file mode 100644 index 0000000..1f5577e --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001229.py @@ -0,0 +1,134 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt,"") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style,"", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001411.py b/.history/scripts/StyleSelectorXL_20230728001411.py new file mode 100644 index 0000000..5148223 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001411.py @@ -0,0 +1,135 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt,"") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style,"", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001414.py b/.history/scripts/StyleSelectorXL_20230728001414.py new file mode 100644 index 0000000..416ca62 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001414.py @@ -0,0 +1,134 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001524.py b/.history/scripts/StyleSelectorXL_20230728001524.py new file mode 100644 index 0000000..6de9a17 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001524.py @@ -0,0 +1,137 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001727.py b/.history/scripts/StyleSelectorXL_20230728001727.py new file mode 100644 index 0000000..8a66010 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001727.py @@ -0,0 +1,138 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001742.py b/.history/scripts/StyleSelectorXL_20230728001742.py new file mode 100644 index 0000000..ebdfd41 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001742.py @@ -0,0 +1,136 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = self.createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = self.createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728001928.py b/.history/scripts/StyleSelectorXL_20230728001928.py new file mode 100644 index 0000000..b9ffd94 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728001928.py @@ -0,0 +1,137 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + print(style, prompt, "") + positivePrompt = self.createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = self.createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002038.py b/.history/scripts/StyleSelectorXL_20230728002038.py new file mode 100644 index 0000000..49dda59 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002038.py @@ -0,0 +1,137 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def createprompts(self, style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + print(style, prompt, "") + positivePrompt = self.createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = self.createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002129.py b/.history/scripts/StyleSelectorXL_20230728002129.py new file mode 100644 index 0000000..6de9a17 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002129.py @@ -0,0 +1,137 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002356.py b/.history/scripts/StyleSelectorXL_20230728002356.py new file mode 100644 index 0000000..e04ec33 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002356.py @@ -0,0 +1,138 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath="" +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath=json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + print(json_path) + + json_data = get_json_content(json_path) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002406.py b/.history/scripts/StyleSelectorXL_20230728002406.py new file mode 100644 index 0000000..0521552 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002406.py @@ -0,0 +1,139 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + print(stylespath) + + json_data = get_json_content(stylespath) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002539.py b/.history/scripts/StyleSelectorXL_20230728002539.py new file mode 100644 index 0000000..1acfc18 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002539.py @@ -0,0 +1,140 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + print(stylespath) + + json_data = get_json_content(stylespath) + print(json_data) + print(type(json_data)) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002623.py b/.history/scripts/StyleSelectorXL_20230728002623.py new file mode 100644 index 0000000..a926859 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002623.py @@ -0,0 +1,139 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + print(stylespath) + + json_data = get_json_content(stylespath) + print(json_data) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002626.py b/.history/scripts/StyleSelectorXL_20230728002626.py new file mode 100644 index 0000000..c4ff080 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002626.py @@ -0,0 +1,137 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + print(stylespath) + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002629.py b/.history/scripts/StyleSelectorXL_20230728002629.py new file mode 100644 index 0000000..6234c33 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002629.py @@ -0,0 +1,136 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002725.py b/.history/scripts/StyleSelectorXL_20230728002725.py new file mode 100644 index 0000000..5b41a09 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002725.py @@ -0,0 +1,136 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002727.py b/.history/scripts/StyleSelectorXL_20230728002727.py new file mode 100644 index 0000000..860d6f0 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002727.py @@ -0,0 +1,136 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createprompts(style, positive, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002906.py b/.history/scripts/StyleSelectorXL_20230728002906.py new file mode 100644 index 0000000..8e57aeb --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002906.py @@ -0,0 +1,168 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002912.py b/.history/scripts/StyleSelectorXL_20230728002912.py new file mode 100644 index 0000000..5454007 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002912.py @@ -0,0 +1,163 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728002915.py b/.history/scripts/StyleSelectorXL_20230728002915.py new file mode 100644 index 0000000..9005e95 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728002915.py @@ -0,0 +1,163 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003009.py b/.history/scripts/StyleSelectorXL_20230728003009.py new file mode 100644 index 0000000..c58baf1 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003009.py @@ -0,0 +1,161 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return positive, negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003012.py b/.history/scripts/StyleSelectorXL_20230728003012.py new file mode 100644 index 0000000..7c02dda --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003012.py @@ -0,0 +1,161 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003059.py b/.history/scripts/StyleSelectorXL_20230728003059.py new file mode 100644 index 0000000..7c02dda --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003059.py @@ -0,0 +1,161 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003121.py b/.history/scripts/StyleSelectorXL_20230728003121.py new file mode 100644 index 0000000..17c5964 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003121.py @@ -0,0 +1,165 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + print(createPositive(style, "alihaydar")) + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + print(createNegative(style, "alihaydar")) + + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003231.py b/.history/scripts/StyleSelectorXL_20230728003231.py new file mode 100644 index 0000000..4066bab --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003231.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003315.py b/.history/scripts/StyleSelectorXL_20230728003315.py new file mode 100644 index 0000000..733843f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003315.py @@ -0,0 +1,165 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + ali = createPositive(style, "alihaydar") + print(ali) + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + # positivePrompt = createprompts(style, prompt, "") + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003359.py b/.history/scripts/StyleSelectorXL_20230728003359.py new file mode 100644 index 0000000..7c59ef3 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003359.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] = "positivePrompt" + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003403.py b/.history/scripts/StyleSelectorXL_20230728003403.py new file mode 100644 index 0000000..52fe23d --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003403.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] =positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + # a, negativePrompt = createprompts(style, "", prompt) + p.all_negative_prompts[i] = "negativePrompt" + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003424.py b/.history/scripts/StyleSelectorXL_20230728003424.py new file mode 100644 index 0000000..80ab049 --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003424.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("Select Style", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + negativePrompt = createNegative(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728003757.py b/.history/scripts/StyleSelectorXL_20230728003757.py new file mode 100644 index 0000000..7d3d16f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728003757.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("SDXL Styles", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + negativePrompt = createNegative(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/.history/scripts/StyleSelectorXL_20230728004143.py b/.history/scripts/StyleSelectorXL_20230728004143.py new file mode 100644 index 0000000..7d3d16f --- /dev/null +++ b/.history/scripts/StyleSelectorXL_20230728004143.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("SDXL Styles", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + negativePrompt = createNegative(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/README.md b/README.md new file mode 100644 index 0000000..0bf85fa --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +## Style Selector for SDXL 1.0 + +This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0. + +### Styles + +Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel. + +### Installation + +Enter this repo's URL in Automatic1111's extension tab "Install from Url": + +https://github.com/ahgsql/StyleSelectorXL.git + +### Usage + +Enable or Disable it On Extension's panel, Write your subject into Prompt field, +Select Style then hit Generate! +The selected style will be applied to your current prompts. + +### Thanks + +Huge thanks for https://github.com/twri/sdxl_prompt_styler as i got style json file's original structure from his repo. + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/scripts/StyleSelectorXL.py b/scripts/StyleSelectorXL.py new file mode 100644 index 0000000..7d3d16f --- /dev/null +++ b/scripts/StyleSelectorXL.py @@ -0,0 +1,164 @@ +import contextlib + +import gradio as gr +from modules import scripts +from modules import script_callbacks +import json +import os + +stylespath = "" + + +def get_json_content(file_path): + try: + with open(file_path, 'r') as file: + json_data = json.load(file) + return json_data + except Exception as e: + print(f"A Problem occurred: {str(e)}") + + +def read_sdxl_styles(json_data): + # Check that data is a list + if not isinstance(json_data, list): + print("Error: input data must be a list") + return None + + names = [] + + # Iterate over each item in the data list + for item in json_data: + # Check that the item is a dictionary + if isinstance(item, dict): + # Check that 'name' is a key in the dictionary + if 'name' in item: + # Append the value of 'name' to the names list + names.append(item['name']) + + return names + + +def getStyles(): + global stylespath + json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json') + stylespath = json_path + json_data = get_json_content(json_path) + styles = read_sdxl_styles(json_data) + return styles + + +def createPositive(style, positive): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + positive = template['prompt'].replace( + '{prompt}', positive) + + return positive + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +def createNegative(style, negative): + json_data = get_json_content(stylespath) + try: + # Check if json_data is a list + if not isinstance(json_data, list): + raise ValueError( + "Invalid JSON data. Expected a list of templates.") + + for template in json_data: + # Check if template contains 'name' and 'prompt' fields + if 'name' not in template or 'prompt' not in template: + raise ValueError( + "Invalid template. Missing 'name' or 'prompt' field.") + + # Replace {prompt} in the matching template + if template['name'] == style: + json_negative_prompt = template.get('negative_prompt', "") + if negative: + negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative + else: + negative = json_negative_prompt + + return negative + + # If function hasn't returned yet, no matching template was found + raise ValueError(f"No template found with name '{style}'.") + + except Exception as e: + print(f"An error occurred: {str(e)}") + + +class StyleSelectorXL(scripts.Script): + def __init__(self) -> None: + super().__init__() + + styleNames = getStyles() + + def title(self): + return "Style Selector for SDXL 1.0" + + def show(self, is_img2img): + return scripts.AlwaysVisible + + def ui(self, is_img2img): + with gr.Group(): + with gr.Accordion("SDXL Styles", open=True): + is_enabled = gr.Checkbox( + value=True, label="Enable Style Selector") + style = gr.Radio( + label='Codec', choices=self.styleNames, value='sai-base') + + # Ignore the error if the attribute is not present + + return [is_enabled, style] + + def process(self, p, is_enabled, style): + if not is_enabled: + return + + p.extra_generation_params["Style Selector Enabled"] = True + + for i, prompt in enumerate(p.all_prompts): # for each image in batch + + positivePrompt = createPositive(style, prompt) + p.all_prompts[i] = positivePrompt + # for each image in batch + for i, prompt in enumerate(p.all_negative_prompts): + + negativePrompt = createNegative(style, prompt) + p.all_negative_prompts[i] = negativePrompt + + def after_component(self, component, **kwargs): + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link + # Find the text2img textbox component + if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox + self.boxx = component + # Find the img2img textbox component + if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox + self.boxxIMG = component + + # this code below works aswell, you can send negative prompt text box,provided you change the code a little + # switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG + + # if kwargs.get("elem_id") == "txt2img_neg_prompt": + #self.neg_prompt_boxTXT = component + # if kwargs.get("elem_id") == "img2img_neg_prompt": + #self.neg_prompt_boxIMG = component diff --git a/scripts/__pycache__/SendtoTextImg.cpython-310.pyc b/scripts/__pycache__/SendtoTextImg.cpython-310.pyc new file mode 100644 index 0000000..e53cda6 Binary files /dev/null and b/scripts/__pycache__/SendtoTextImg.cpython-310.pyc differ diff --git a/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc b/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc new file mode 100644 index 0000000..e23ff31 Binary files /dev/null and b/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc differ diff --git a/sdxl_styles.json b/sdxl_styles.json new file mode 100644 index 0000000..401f560 --- /dev/null +++ b/sdxl_styles.json @@ -0,0 +1,522 @@ +[ + { + "name": "sai-base", + "prompt": "{prompt}", + "negative_prompt": "" + }, + { + "name": "sai-3d-model", + "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting", + "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting" + }, + { + "name": "sai-analog film", + "prompt": "analog film photo {prompt} . faded film, desaturated, 35mm photo, grainy, vignette, vintage, Kodachrome, Lomography, stained, highly detailed, found footage", + "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured" + }, + { + "name": "sai-anime", + "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed", + "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast" + }, + { + "name": "sai-cinematic", + "prompt": "cinematic film still {prompt} . shallow depth of field, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy", + "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured" + }, + { + "name": "sai-comic book", + "prompt": "comic {prompt} . graphic illustration, comic art, graphic novel art, vibrant, highly detailed", + "negative_prompt": "photograph, deformed, glitch, noisy, realistic, stock photo" + }, + { + "name": "sai-craft clay", + "prompt": "play-doh style {prompt} . sculpture, clay art, centered composition, Claymation", + "negative_prompt": "sloppy, messy, grainy, highly detailed, ultra textured, photo" + }, + { + "name": "sai-digital art", + "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed", + "negative_prompt": "photo, photorealistic, realism, ugly" + }, + { + "name": "sai-enhance", + "prompt": "breathtaking {prompt} . award-winning, professional, highly detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, distorted, grainy" + }, + { + "name": "sai-fantasy art", + "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy", + "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white" + }, + { + "name": "sai-isometric", + "prompt": "isometric style {prompt} . vibrant, beautiful, crisp, detailed, ultra detailed, intricate", + "negative_prompt": "deformed, mutated, ugly, disfigured, blur, blurry, noise, noisy, realistic, photographic" + }, + { + "name": "sai-line art", + "prompt": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics", + "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic" + }, + { + "name": "sai-lowpoly", + "prompt": "low-poly style {prompt} . low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition", + "negative_prompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo" + }, + { + "name": "sai-neonpunk", + "prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional", + "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured" + }, + { + "name": "sai-origami", + "prompt": "origami style {prompt} . paper art, pleated paper, folded, origami art, pleats, cut and fold, centered composition", + "negative_prompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo" + }, + { + "name": "sai-photographic", + "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed", + "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly" + }, + { + "name": "sai-pixel art", + "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics", + "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic" + }, + { + "name": "sai-texture", + "prompt": "texture {prompt} top down close-up", + "negative_prompt": "ugly, deformed, noisy, blurry" + }, + { + "name": "ads-advertising", + "prompt": "Advertising poster style {prompt} . Professional, modern, product-focused, commercial, eye-catching, highly detailed", + "negative_prompt": "noisy, blurry, amateurish, sloppy, unattractive" + }, + { + "name": "ads-automotive", + "prompt": "Automotive advertisement style {prompt} . Sleek, dynamic, professional, commercial, vehicle-focused, high-resolution, highly detailed", + "negative_prompt": "noisy, blurry, unattractive, sloppy, unprofessional" + }, + { + "name": "ads-corporate", + "prompt": "Corporate branding style {prompt} . Professional, clean, modern, sleek, minimalist, business-oriented, highly detailed", + "negative_prompt": "noisy, blurry, grungy, sloppy, cluttered, disorganized" + }, + { + "name": "ads-fashion editorial", + "prompt": "Fashion editorial style {prompt} . High fashion, trendy, stylish, editorial, magazine style, professional, highly detailed", + "negative_prompt": "outdated, blurry, noisy, unattractive, sloppy" + }, + { + "name": "ads-food photography", + "prompt": "Food photography style {prompt} . Appetizing, professional, culinary, high-resolution, commercial, highly detailed", + "negative_prompt": "unappetizing, sloppy, unprofessional, noisy, blurry" + }, + { + "name": "ads-luxury", + "prompt": "Luxury product style {prompt} . Elegant, sophisticated, high-end, luxurious, professional, highly detailed", + "negative_prompt": "cheap, noisy, blurry, unattractive, amateurish" + }, + { + "name": "ads-real estate", + "prompt": "Real estate photography style {prompt} . Professional, inviting, well-lit, high-resolution, property-focused, commercial, highly detailed", + "negative_prompt": "dark, blurry, unappealing, noisy, unprofessional" + }, + { + "name": "ads-retail", + "prompt": "Retail packaging style {prompt} . Vibrant, enticing, commercial, product-focused, eye-catching, professional, highly detailed", + "negative_prompt": "noisy, blurry, amateurish, sloppy, unattractive" + }, + { + "name": "artstyle-abstract", + "prompt": "abstract style {prompt} . non-representational, colors and shapes, expression of feelings, imaginative, highly detailed", + "negative_prompt": "realistic, photographic, figurative, concrete" + }, + { + "name": "artstyle-abstract expressionism", + "prompt": "abstract expressionist painting {prompt} . energetic brushwork, bold colors, abstract forms, expressive, emotional", + "negative_prompt": "realistic, photorealistic, low contrast, plain, simple, monochrome" + }, + { + "name": "artstyle-art deco", + "prompt": "Art Deco style {prompt} . geometric shapes, bold colors, luxurious, elegant, decorative, symmetrical, ornate, detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, modernist, minimalist" + }, + { + "name": "artstyle-art nouveau", + "prompt": "Art Nouveau style {prompt} . elegant, decorative, curvilinear forms, nature-inspired, ornate, detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, modernist, minimalist" + }, + { + "name": "artstyle-constructivist", + "prompt": "constructivist style {prompt} . geometric shapes, bold colors, dynamic composition, propaganda art style", + "negative_prompt": "realistic, photorealistic, low contrast, plain, simple, abstract expressionism" + }, + { + "name": "artstyle-cubist", + "prompt": "cubist artwork {prompt} . geometric shapes, abstract, innovative, revolutionary", + "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy" + }, + { + "name": "artstyle-expressionist", + "prompt": "expressionist {prompt} . raw, emotional, dynamic, distortion for emotional effect, vibrant, use of unusual colors, detailed", + "negative_prompt": "realism, symmetry, quiet, calm, photo" + }, + { + "name": "artstyle-graffiti", + "prompt": "graffiti style {prompt} . street art, vibrant, urban, detailed, tag, mural", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic" + }, + { + "name": "artstyle-hyperrealism", + "prompt": "hyperrealistic art {prompt} . extremely high-resolution details, photographic, realism pushed to extreme, fine texture, incredibly lifelike", + "negative_prompt": "simplified, abstract, unrealistic, impressionistic, low resolution" + }, + { + "name": "artstyle-impressionist", + "prompt": "impressionist painting {prompt} . loose brushwork, vibrant color, light and shadow play, captures feeling over form", + "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy" + }, + { + "name": "artstyle-pointillism", + "prompt": "pointillism style {prompt} . composed entirely of small, distinct dots of color, vibrant, highly detailed", + "negative_prompt": "line drawing, smooth shading, large color fields, simplistic" + }, + { + "name": "artstyle-pop art", + "prompt": "Pop Art style {prompt} . bright colors, bold outlines, popular culture themes, ironic or kitsch", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, minimalist" + }, + { + "name": "artstyle-psychedelic", + "prompt": "psychedelic style {prompt} . vibrant colors, swirling patterns, abstract forms, surreal, trippy", + "negative_prompt": "monochrome, black and white, low contrast, realistic, photorealistic, plain, simple" + }, + { + "name": "artstyle-renaissance", + "prompt": "Renaissance style {prompt} . realistic, perspective, light and shadow, religious or mythological themes, highly detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, modernist, minimalist, abstract" + }, + { + "name": "artstyle-steampunk", + "prompt": "steampunk style {prompt} . antique, mechanical, brass and copper tones, gears, intricate, detailed", + "negative_prompt": "deformed, glitch, noisy, low contrast, anime, photorealistic" + }, + { + "name": "artstyle-surrealist", + "prompt": "surrealist art {prompt} . dreamlike, mysterious, provocative, symbolic, intricate, detailed", + "negative_prompt": "anime, photorealistic, realistic, deformed, glitch, noisy, low contrast" + }, + { + "name": "artstyle-typography", + "prompt": "typographic art {prompt} . stylized, intricate, detailed, artistic, text-based", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic" + }, + { + "name": "artstyle-watercolor", + "prompt": "watercolor painting {prompt} . vibrant, beautiful, painterly, detailed, textural, artistic", + "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy" + }, + { + "name": "futuristic-biomechanical", + "prompt": "biomechanical style {prompt} . blend of organic and mechanical elements, futuristic, cybernetic, detailed, intricate", + "negative_prompt": "natural, rustic, primitive, organic, simplistic" + }, + { + "name": "futuristic-biomechanical cyberpunk", + "prompt": "biomechanical cyberpunk {prompt} . cybernetics, human-machine fusion, dystopian, organic meets artificial, dark, intricate, highly detailed", + "negative_prompt": "natural, colorful, deformed, sketch, low contrast, watercolor" + }, + { + "name": "futuristic-cybernetic", + "prompt": "cybernetic style {prompt} . futuristic, technological, cybernetic enhancements, robotics, artificial intelligence themes", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval" + }, + { + "name": "futuristic-cybernetic robot", + "prompt": "cybernetic robot {prompt} . android, AI, machine, metal, wires, tech, futuristic, highly detailed", + "negative_prompt": "organic, natural, human, sketch, watercolor, low contrast" + }, + { + "name": "futuristic-cyberpunk cityscape", + "prompt": "cyberpunk cityscape {prompt} . neon lights, dark alleys, skyscrapers, futuristic, vibrant colors, high contrast, highly detailed", + "negative_prompt": "natural, rural, deformed, low contrast, black and white, sketch, watercolor" + }, + { + "name": "futuristic-futuristic", + "prompt": "futuristic style {prompt} . sleek, modern, ultramodern, high tech, detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, vintage, antique" + }, + { + "name": "futuristic-retro cyberpunk", + "prompt": "retro cyberpunk {prompt} . 80's inspired, synthwave, neon, vibrant, detailed, retro futurism", + "negative_prompt": "modern, desaturated, black and white, realism, low contrast" + }, + { + "name": "futuristic-retro futurism", + "prompt": "retro-futuristic {prompt} . vintage sci-fi, 50s and 60s style, atomic age, vibrant, highly detailed", + "negative_prompt": "contemporary, realistic, rustic, primitive" + }, + { + "name": "futuristic-sci-fi", + "prompt": "sci-fi style {prompt} . futuristic, technological, alien worlds, space themes, advanced civilizations", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval" + }, + { + "name": "futuristic-vaporwave", + "prompt": "vaporwave style {prompt} . retro aesthetic, cyberpunk, vibrant, neon colors, vintage 80s and 90s style, highly detailed", + "negative_prompt": "monochrome, muted colors, realism, rustic, minimalist, dark" + }, + { + "name": "game-bubble bobble", + "prompt": "Bubble Bobble style {prompt} . 8-bit, cute, pixelated, fantasy, vibrant, reminiscent of Bubble Bobble game", + "negative_prompt": "realistic, modern, photorealistic, violent, horror" + }, + { + "name": "game-cyberpunk game", + "prompt": "cyberpunk game style {prompt} . neon, dystopian, futuristic, digital, vibrant, detailed, high contrast, reminiscent of cyberpunk genre video games", + "negative_prompt": "historical, natural, rustic, low detailed" + }, + { + "name": "game-fighting game", + "prompt": "fighting game style {prompt} . dynamic, vibrant, action-packed, detailed character design, reminiscent of fighting video games", + "negative_prompt": "peaceful, calm, minimalist, photorealistic" + }, + { + "name": "game-gta", + "prompt": "GTA-style artwork {prompt} . satirical, exaggerated, pop art style, vibrant colors, iconic characters, action-packed", + "negative_prompt": "realistic, black and white, low contrast, impressionist, cubist, noisy, blurry, deformed" + }, + { + "name": "game-mario", + "prompt": "Super Mario style {prompt} . vibrant, cute, cartoony, fantasy, playful, reminiscent of Super Mario series", + "negative_prompt": "realistic, modern, horror, dystopian, violent" + }, + { + "name": "game-minecraft", + "prompt": "Minecraft style {prompt} . blocky, pixelated, vibrant colors, recognizable characters and objects, game assets", + "negative_prompt": "smooth, realistic, detailed, photorealistic, noise, blurry, deformed" + }, + { + "name": "game-pokemon", + "prompt": "Pokémon style {prompt} . vibrant, cute, anime, fantasy, reminiscent of Pokémon series", + "negative_prompt": "realistic, modern, horror, dystopian, violent" + }, + { + "name": "game-retro arcade", + "prompt": "retro arcade style {prompt} . 8-bit, pixelated, vibrant, classic video game, old school gaming, reminiscent of 80s and 90s arcade games", + "negative_prompt": "modern, ultra-high resolution, photorealistic, 3D" + }, + { + "name": "game-retro game", + "prompt": "retro game art {prompt} . 16-bit, vibrant colors, pixelated, nostalgic, charming, fun", + "negative_prompt": "realistic, photorealistic, 35mm film, deformed, glitch, low contrast, noisy" + }, + { + "name": "game-rpg fantasy game", + "prompt": "role-playing game (RPG) style fantasy {prompt} . detailed, vibrant, immersive, reminiscent of high fantasy RPG games", + "negative_prompt": "sci-fi, modern, urban, futuristic, low detailed" + }, + { + "name": "game-strategy game", + "prompt": "strategy game style {prompt} . overhead view, detailed map, units, reminiscent of real-time strategy video games", + "negative_prompt": "first-person view, modern, photorealistic" + }, + { + "name": "game-streetfighter", + "prompt": "Street Fighter style {prompt} . vibrant, dynamic, arcade, 2D fighting game, highly detailed, reminiscent of Street Fighter series", + "negative_prompt": "3D, realistic, modern, photorealistic, turn-based strategy" + }, + { + "name": "game-zelda", + "prompt": "Legend of Zelda style {prompt} . vibrant, fantasy, detailed, epic, heroic, reminiscent of The Legend of Zelda series", + "negative_prompt": "sci-fi, modern, realistic, horror" + }, + { + "name": "misc-architectural", + "prompt": "architectural style {prompt} . clean lines, geometric shapes, minimalist, modern, architectural drawing, highly detailed", + "negative_prompt": "curved lines, ornate, baroque, abstract, grunge" + }, + { + "name": "misc-disco", + "prompt": "disco-themed {prompt} . vibrant, groovy, retro 70s style, shiny disco balls, neon lights, dance floor, highly detailed", + "negative_prompt": "minimalist, rustic, monochrome, contemporary, simplistic" + }, + { + "name": "misc-dreamscape", + "prompt": "dreamscape {prompt} . surreal, ethereal, dreamy, mysterious, fantasy, highly detailed", + "negative_prompt": "realistic, concrete, ordinary, mundane" + }, + { + "name": "misc-dystopian", + "prompt": "dystopian style {prompt} . bleak, post-apocalyptic, somber, dramatic, highly detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, cheerful, optimistic, vibrant, colorful" + }, + { + "name": "misc-fairy tale", + "prompt": "fairy tale {prompt} . magical, fantastical, enchanting, storybook style, highly detailed", + "negative_prompt": "realistic, modern, ordinary, mundane" + }, + { + "name": "misc-gothic", + "prompt": "gothic style {prompt} . dark, mysterious, haunting, dramatic, ornate, detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, cheerful, optimistic" + }, + { + "name": "misc-grunge", + "prompt": "grunge style {prompt} . textured, distressed, vintage, edgy, punk rock vibe, dirty, noisy", + "negative_prompt": "smooth, clean, minimalist, sleek, modern, photorealistic" + }, + { + "name": "misc-horror", + "prompt": "horror-themed {prompt} . eerie, unsettling, dark, spooky, suspenseful, grim, highly detailed", + "negative_prompt": "cheerful, bright, vibrant, light-hearted, cute" + }, + { + "name": "misc-kawaii", + "prompt": "kawaii style {prompt} . cute, adorable, brightly colored, cheerful, anime influence, highly detailed", + "negative_prompt": "dark, scary, realistic, monochrome, abstract" + }, + { + "name": "misc-lovecraftian", + "prompt": "lovecraftian horror {prompt} . eldritch, cosmic horror, unknown, mysterious, surreal, highly detailed", + "negative_prompt": "light-hearted, mundane, familiar, simplistic, realistic" + }, + { + "name": "misc-macabre", + "prompt": "macabre style {prompt} . dark, gothic, grim, haunting, highly detailed", + "negative_prompt": "bright, cheerful, light-hearted, cartoonish, cute" + }, + { + "name": "misc-manga", + "prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style" + }, + { + "name": "misc-metropolis", + "prompt": "metropolis-themed {prompt} . urban, cityscape, skyscrapers, modern, futuristic, highly detailed", + "negative_prompt": "rural, natural, rustic, historical, simple" + }, + { + "name": "misc-minimalist", + "prompt": "minimalist style {prompt} . simple, clean, uncluttered, modern, elegant", + "negative_prompt": "ornate, complicated, highly detailed, cluttered, disordered, messy, noisy" + }, + { + "name": "misc-monochrome", + "prompt": "monochrome {prompt} . black and white, contrast, tone, texture, detailed", + "negative_prompt": "colorful, vibrant, noisy, blurry, deformed" + }, + { + "name": "misc-nautical", + "prompt": "nautical-themed {prompt} . sea, ocean, ships, maritime, beach, marine life, highly detailed", + "negative_prompt": "landlocked, desert, mountains, urban, rustic" + }, + { + "name": "misc-space", + "prompt": "space-themed {prompt} . cosmic, celestial, stars, galaxies, nebulas, planets, science fiction, highly detailed", + "negative_prompt": "earthly, mundane, ground-based, realism" + }, + { + "name": "misc-stained glass", + "prompt": "stained glass style {prompt} . vibrant, beautiful, translucent, intricate, detailed", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic" + }, + { + "name": "misc-techwear fashion", + "prompt": "techwear fashion {prompt} . futuristic, cyberpunk, urban, tactical, sleek, dark, highly detailed", + "negative_prompt": "vintage, rural, colorful, low contrast, realism, sketch, watercolor" + }, + { + "name": "misc-tribal", + "prompt": "tribal style {prompt} . indigenous, ethnic, traditional patterns, bold, natural colors, highly detailed", + "negative_prompt": "modern, futuristic, minimalist, pastel" + }, + { + "name": "misc-zentangle", + "prompt": "zentangle {prompt} . intricate, abstract, monochrome, patterns, meditative, highly detailed", + "negative_prompt": "colorful, representative, simplistic, large fields of color" + }, + { + "name": "papercraft-collage", + "prompt": "collage style {prompt} . mixed media, layered, textural, detailed, artistic", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic" + }, + { + "name": "papercraft-flat papercut", + "prompt": "flat papercut style {prompt} . silhouette, clean cuts, paper, sharp edges, minimalist, color block", + "negative_prompt": "3D, high detail, noise, grainy, blurry, painting, drawing, photo, disfigured" + }, + { + "name": "papercraft-kirigami", + "prompt": "kirigami representation of {prompt} . 3D, paper folding, paper cutting, Japanese, intricate, symmetrical, precision, clean lines", + "negative_prompt": "painting, drawing, 2D, noisy, blurry, deformed" + }, + { + "name": "papercraft-paper mache", + "prompt": "paper mache representation of {prompt} . 3D, sculptural, textured, handmade, vibrant, fun", + "negative_prompt": "2D, flat, photo, sketch, digital art, deformed, noisy, blurry" + }, + { + "name": "papercraft-paper quilling", + "prompt": "paper quilling art of {prompt} . intricate, delicate, curling, rolling, shaping, coiling, loops, 3D, dimensional, ornamental", + "negative_prompt": "photo, painting, drawing, 2D, flat, deformed, noisy, blurry" + }, + { + "name": "papercraft-papercut collage", + "prompt": "papercut collage of {prompt} . mixed media, textured paper, overlapping, asymmetrical, abstract, vibrant", + "negative_prompt": "photo, 3D, realistic, drawing, painting, high detail, disfigured" + }, + { + "name": "papercraft-papercut shadow box", + "prompt": "3D papercut shadow box of {prompt} . layered, dimensional, depth, silhouette, shadow, papercut, handmade, high contrast", + "negative_prompt": "painting, drawing, photo, 2D, flat, high detail, blurry, noisy, disfigured" + }, + { + "name": "papercraft-stacked papercut", + "prompt": "stacked papercut art of {prompt} . 3D, layered, dimensional, depth, precision cut, stacked layers, papercut, high contrast", + "negative_prompt": "2D, flat, noisy, blurry, painting, drawing, photo, deformed" + }, + { + "name": "papercraft-thick layered papercut", + "prompt": "thick layered papercut art of {prompt} . deep 3D, volumetric, dimensional, depth, thick paper, high stack, heavy texture, tangible layers", + "negative_prompt": "2D, flat, thin paper, low stack, smooth texture, painting, drawing, photo, deformed" + }, + { + "name": "photo-alien", + "prompt": "alien-themed {prompt} . extraterrestrial, cosmic, otherworldly, mysterious, sci-fi, highly detailed", + "negative_prompt": "earthly, mundane, common, realistic, simple" + }, + { + "name": "photo-film noir", + "prompt": "film noir style {prompt} . monochrome, high contrast, dramatic shadows, 1940s style, mysterious, cinematic", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, vibrant, colorful" + }, + { + "name": "photo-hdr", + "prompt": "HDR photo of {prompt} . High dynamic range, vivid, rich details, clear shadows and highlights, realistic, intense, enhanced contrast, highly detailed", + "negative_prompt": "flat, low contrast, oversaturated, underexposed, overexposed, blurred, noisy" + }, + { + "name": "photo-long exposure", + "prompt": "long exposure photo of {prompt} . Blurred motion, streaks of light, surreal, dreamy, ghosting effect, highly detailed", + "negative_prompt": "static, noisy, deformed, shaky, abrupt, flat, low contrast" + }, + { + "name": "photo-neon noir", + "prompt": "neon noir {prompt} . cyberpunk, dark, rainy streets, neon signs, high contrast, low light, vibrant, highly detailed", + "negative_prompt": "bright, sunny, daytime, low contrast, black and white, sketch, watercolor" + }, + { + "name": "photo-silhouette", + "prompt": "silhouette style {prompt} . high contrast, minimalistic, black and white, stark, dramatic", + "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, color, realism, photorealistic" + }, + { + "name": "photo-tilt-shift", + "prompt": "tilt-shift photo of {prompt} . Selective focus, miniature effect, blurred background, highly detailed, vibrant, perspective control", + "negative_prompt": "blurry, noisy, deformed, flat, low contrast, unrealistic, oversaturated, underexposed" + } +] \ No newline at end of file