diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22402c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.history +__pycache__ \ No newline at end of file diff --git a/.history/README_20230709123111.md b/.history/README_20230709123111.md deleted file mode 100644 index bed5d0e..0000000 --- a/.history/README_20230709123111.md +++ /dev/null @@ -1,38 +0,0 @@ -# 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 deleted file mode 100644 index 320d79a..0000000 --- a/.history/README_20230728003913.md +++ /dev/null @@ -1,106 +0,0 @@ -## 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 deleted file mode 100644 index a9e648a..0000000 --- a/.history/README_20230728004004.md +++ /dev/null @@ -1,26 +0,0 @@ -## 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 deleted file mode 100644 index 72b3942..0000000 --- a/.history/README_20230728004120.md +++ /dev/null @@ -1,27 +0,0 @@ -## 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 deleted file mode 100644 index 0bf85fa..0000000 --- a/.history/README_20230728004134.md +++ /dev/null @@ -1,27 +0,0 @@ -## 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 deleted file mode 100644 index 3ef71fc..0000000 --- a/.history/scripts/SendtoTextImg_20230709123111.py +++ /dev/null @@ -1,65 +0,0 @@ -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 deleted file mode 100644 index b3fb272..0000000 --- a/.history/scripts/SendtoTextImg_20230727230227.py +++ /dev/null @@ -1,65 +0,0 @@ -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 deleted file mode 100644 index 65033db..0000000 --- a/.history/scripts/SendtoTextImg_20230727230407.py +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index d1985df..0000000 --- a/.history/scripts/SendtoTextImg_20230727230414.py +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index d1985df..0000000 --- a/.history/scripts/SendtoTextImg_20230727230903.py +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index d1985df..0000000 --- a/.history/scripts/StyleSelectorXL_20230727230902.py +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index d3934ce..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231505.py +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index e73cd6f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231535.py +++ /dev/null @@ -1,150 +0,0 @@ -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 deleted file mode 100644 index 9e60c4f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231708.py +++ /dev/null @@ -1,118 +0,0 @@ -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 deleted file mode 100644 index acf3492..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231728.py +++ /dev/null @@ -1,114 +0,0 @@ -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 deleted file mode 100644 index 2d3c5e0..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231803.py +++ /dev/null @@ -1,79 +0,0 @@ -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 deleted file mode 100644 index 6691b5f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231809.py +++ /dev/null @@ -1,79 +0,0 @@ -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 deleted file mode 100644 index 9a32fa9..0000000 --- a/.history/scripts/StyleSelectorXL_20230727231918.py +++ /dev/null @@ -1,79 +0,0 @@ -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 deleted file mode 100644 index 7b1c228..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232247.py +++ /dev/null @@ -1,90 +0,0 @@ -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 deleted file mode 100644 index 07135d9..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232356.py +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index 6d14ba3..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232544.py +++ /dev/null @@ -1,118 +0,0 @@ -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 deleted file mode 100644 index f7624e7..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232637.py +++ /dev/null @@ -1,122 +0,0 @@ -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 deleted file mode 100644 index b70cb5e..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232827.py +++ /dev/null @@ -1,119 +0,0 @@ -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 deleted file mode 100644 index 4f6799c..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232832.py +++ /dev/null @@ -1,119 +0,0 @@ -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 deleted file mode 100644 index 515ce2e..0000000 --- a/.history/scripts/StyleSelectorXL_20230727232939.py +++ /dev/null @@ -1,115 +0,0 @@ -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 deleted file mode 100644 index 99a1b54..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233047.py +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index f101cb5..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233056.py +++ /dev/null @@ -1,118 +0,0 @@ -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 deleted file mode 100644 index 4aec456..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233110.py +++ /dev/null @@ -1,120 +0,0 @@ -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 deleted file mode 100644 index 5327aef..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233114.py +++ /dev/null @@ -1,119 +0,0 @@ -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 deleted file mode 100644 index ad5e380..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233237.py +++ /dev/null @@ -1,124 +0,0 @@ -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 deleted file mode 100644 index 43d5592..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233428.py +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index 1bf4d01..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233450.py +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index dd4dfb5..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233452.py +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index 03b33ad..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233502.py +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index 03b33ad..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233525.py +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index 383a85e..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233536.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 862ea4c..0000000 --- a/.history/scripts/StyleSelectorXL_20230727233754.py +++ /dev/null @@ -1,122 +0,0 @@ -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 deleted file mode 100644 index 9792074..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234105.py +++ /dev/null @@ -1,122 +0,0 @@ -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 deleted file mode 100644 index eff0cf6..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234108.py +++ /dev/null @@ -1,122 +0,0 @@ -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 deleted file mode 100644 index a3cb5e6..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234115.py +++ /dev/null @@ -1,121 +0,0 @@ -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 deleted file mode 100644 index 5c5c5e8..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234120.py +++ /dev/null @@ -1,119 +0,0 @@ -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 deleted file mode 100644 index eb64676..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234140.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 066c7d4..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234218.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index c0e6381..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234223.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index ba2866f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234231.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index bba8650..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234254.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 5472662..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234317.py +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index eb64676..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234622.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index c346ef6..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234653.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 1fa5bfe..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234853.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index 1f09832..0000000 --- a/.history/scripts/StyleSelectorXL_20230727234911.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index f1d3631..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235044.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index 3b1c5f4..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235049.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 20d4ad7..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235105.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index efcf9fe..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235234.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index c3e0829..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235237.py +++ /dev/null @@ -1,106 +0,0 @@ -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 deleted file mode 100644 index 1b28e91..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235322.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index b0b5675..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235435.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index d7b9af0..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235527.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index d7b9af0..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235806.py +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index 24c029f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235810.py +++ /dev/null @@ -1,104 +0,0 @@ -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 deleted file mode 100644 index fc469e2..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235847.py +++ /dev/null @@ -1,110 +0,0 @@ -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 deleted file mode 100644 index 4aca11f..0000000 --- a/.history/scripts/StyleSelectorXL_20230727235855.py +++ /dev/null @@ -1,111 +0,0 @@ -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 deleted file mode 100644 index 0b97a46..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000356.py +++ /dev/null @@ -1,143 +0,0 @@ -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 deleted file mode 100644 index 703197b..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000429.py +++ /dev/null @@ -1,145 +0,0 @@ -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 deleted file mode 100644 index 3001ad6..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000535.py +++ /dev/null @@ -1,145 +0,0 @@ -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 deleted file mode 100644 index 156cd13..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000619.py +++ /dev/null @@ -1,145 +0,0 @@ -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 deleted file mode 100644 index 42f87e2..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000820.py +++ /dev/null @@ -1,140 +0,0 @@ -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 deleted file mode 100644 index 42f87e2..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000827.py +++ /dev/null @@ -1,140 +0,0 @@ -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 deleted file mode 100644 index a165ad1..0000000 --- a/.history/scripts/StyleSelectorXL_20230728000935.py +++ /dev/null @@ -1,140 +0,0 @@ -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 deleted file mode 100644 index 1f5577e..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001229.py +++ /dev/null @@ -1,134 +0,0 @@ -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 deleted file mode 100644 index 5148223..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001411.py +++ /dev/null @@ -1,135 +0,0 @@ -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 deleted file mode 100644 index 416ca62..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001414.py +++ /dev/null @@ -1,134 +0,0 @@ -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 deleted file mode 100644 index 6de9a17..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001524.py +++ /dev/null @@ -1,137 +0,0 @@ -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 deleted file mode 100644 index 8a66010..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001727.py +++ /dev/null @@ -1,138 +0,0 @@ -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 deleted file mode 100644 index ebdfd41..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001742.py +++ /dev/null @@ -1,136 +0,0 @@ -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 deleted file mode 100644 index b9ffd94..0000000 --- a/.history/scripts/StyleSelectorXL_20230728001928.py +++ /dev/null @@ -1,137 +0,0 @@ -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 deleted file mode 100644 index 49dda59..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002038.py +++ /dev/null @@ -1,137 +0,0 @@ -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 deleted file mode 100644 index 6de9a17..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002129.py +++ /dev/null @@ -1,137 +0,0 @@ -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 deleted file mode 100644 index e04ec33..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002356.py +++ /dev/null @@ -1,138 +0,0 @@ -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 deleted file mode 100644 index 0521552..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002406.py +++ /dev/null @@ -1,139 +0,0 @@ -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 deleted file mode 100644 index 1acfc18..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002539.py +++ /dev/null @@ -1,140 +0,0 @@ -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 deleted file mode 100644 index a926859..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002623.py +++ /dev/null @@ -1,139 +0,0 @@ -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 deleted file mode 100644 index c4ff080..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002626.py +++ /dev/null @@ -1,137 +0,0 @@ -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 deleted file mode 100644 index 6234c33..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002629.py +++ /dev/null @@ -1,136 +0,0 @@ -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 deleted file mode 100644 index 5b41a09..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002725.py +++ /dev/null @@ -1,136 +0,0 @@ -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 deleted file mode 100644 index 860d6f0..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002727.py +++ /dev/null @@ -1,136 +0,0 @@ -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 deleted file mode 100644 index 8e57aeb..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002906.py +++ /dev/null @@ -1,168 +0,0 @@ -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 deleted file mode 100644 index 5454007..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002912.py +++ /dev/null @@ -1,163 +0,0 @@ -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 deleted file mode 100644 index 9005e95..0000000 --- a/.history/scripts/StyleSelectorXL_20230728002915.py +++ /dev/null @@ -1,163 +0,0 @@ -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 deleted file mode 100644 index c58baf1..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003009.py +++ /dev/null @@ -1,161 +0,0 @@ -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 deleted file mode 100644 index 7c02dda..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003012.py +++ /dev/null @@ -1,161 +0,0 @@ -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 deleted file mode 100644 index 7c02dda..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003059.py +++ /dev/null @@ -1,161 +0,0 @@ -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 deleted file mode 100644 index 17c5964..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003121.py +++ /dev/null @@ -1,165 +0,0 @@ -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 deleted file mode 100644 index 4066bab..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003231.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index 733843f..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003315.py +++ /dev/null @@ -1,165 +0,0 @@ -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 deleted file mode 100644 index 7c59ef3..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003359.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index 52fe23d..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003403.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index 80ab049..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003424.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index 7d3d16f..0000000 --- a/.history/scripts/StyleSelectorXL_20230728003757.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index 7d3d16f..0000000 --- a/.history/scripts/StyleSelectorXL_20230728004143.py +++ /dev/null @@ -1,164 +0,0 @@ -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 deleted file mode 100644 index e53cda6..0000000 Binary files a/scripts/__pycache__/SendtoTextImg.cpython-310.pyc and /dev/null differ diff --git a/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc b/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc deleted file mode 100644 index e23ff31..0000000 Binary files a/scripts/__pycache__/StyleSelectorXL.cpython-310.pyc and /dev/null differ