mirror of
https://github.com/ahgsql/StyleSelectorXL.git
synced 2026-01-26 11:09:53 +00:00
Release
This commit is contained in:
38
.history/README_20230709123111.md
Normal file
38
.history/README_20230709123111.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# ExampleSendText
|
||||
## what is this?
|
||||
This is an extension for https://github.com/AUTOMATIC1111/stable-diffusion-webui
|
||||
|
||||
## Goal
|
||||
It's goal is to show extension developers how to send text to the textprompt textbox,
|
||||
The code is contains comments to clarify some aspects. Feel free to play around with it!!
|
||||
|
||||
## How to use it?
|
||||
|
||||
locate Send centrum
|
||||

|
||||
|
||||
Afterwards, input your text and click on send text.
|
||||
The result will be as follows
|
||||
> 
|
||||
|
||||
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
106
.history/README_20230728003913.md
Normal file
106
.history/README_20230728003913.md
Normal file
@@ -0,0 +1,106 @@
|
||||
## Style Selector for SDXL 1.0
|
||||
|
||||
This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0.
|
||||
|
||||
### Styles
|
||||
|
||||
Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel.
|
||||
|
||||
### Installation
|
||||
|
||||
Enter this repo's URL in Automatic1111's extension tab "Install from Url":
|
||||
|
||||
https://github.com/ahgsql/StyleSelectorXL.git
|
||||
|
||||
### Usage
|
||||
|
||||
1. Import the required libraries and modules:
|
||||
|
||||
```python
|
||||
import contextlib
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
```
|
||||
|
||||
2. Define a function to read JSON content from a file:
|
||||
|
||||
```python
|
||||
def get_json_content(file_path):
|
||||
# ...
|
||||
return json_data
|
||||
```
|
||||
|
||||
3. Define a function to extract style names from the JSON data:
|
||||
|
||||
```python
|
||||
def read_sdxl_styles(json_data):
|
||||
# ...
|
||||
return names
|
||||
```
|
||||
|
||||
4. Define a function to get the available styles:
|
||||
|
||||
```python
|
||||
def getStyles():
|
||||
# ...
|
||||
return styles
|
||||
```
|
||||
|
||||
5. Define functions to create positive and negative prompts based on the selected style:
|
||||
|
||||
```python
|
||||
def createPositive(style, positive):
|
||||
# ...
|
||||
return positive
|
||||
|
||||
def createNegative(style, negative):
|
||||
# ...
|
||||
return negative
|
||||
```
|
||||
|
||||
6. Create a class `StyleSelectorXL` that extends the `scripts.Script` class:
|
||||
|
||||
```python
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
# ... (omitting other methods for brevity)
|
||||
|
||||
def ui(self, is_img2img):
|
||||
# ...
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
# ...
|
||||
```
|
||||
|
||||
7. In the `__main__` section, create an instance of the `StyleSelectorXL` class and use the `gr.Interface` to expose the UI:
|
||||
|
||||
```python
|
||||
if __name__ == "__main__":
|
||||
style_selector = StyleSelectorXL()
|
||||
|
||||
iface = gr.Interface(
|
||||
fn=style_selector,
|
||||
inputs=["text" if is_img2img else gr.Image(), "checkbox", "radio"],
|
||||
outputs=None,
|
||||
title="Style Selector for SDXL 1.0",
|
||||
description="Select a style to apply to the input.",
|
||||
)
|
||||
|
||||
iface.launch()
|
||||
```
|
||||
|
||||
Note: Make sure to replace "text" with "image" for the text-to-image scenario.
|
||||
|
||||
### Example
|
||||
|
||||
For a complete example on how to use the `StyleSelectorXL` class, refer to the provided code and integrate it with your existing project or application.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
26
.history/README_20230728004004.md
Normal file
26
.history/README_20230728004004.md
Normal file
@@ -0,0 +1,26 @@
|
||||
## Style Selector for SDXL 1.0
|
||||
|
||||
This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0.
|
||||
|
||||
### Styles
|
||||
|
||||
Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel.
|
||||
|
||||
### Installation
|
||||
|
||||
Enter this repo's URL in Automatic1111's extension tab "Install from Url":
|
||||
|
||||
https://github.com/ahgsql/StyleSelectorXL.git
|
||||
|
||||
### Usage
|
||||
|
||||
Enable or Disable it On Extension's panel, Select Style then hit Generate!
|
||||
The selected style will be applied to your current prompts.
|
||||
|
||||
### Example
|
||||
|
||||
For a complete example on how to use the `StyleSelectorXL` class, refer to the provided code and integrate it with your existing project or application.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
27
.history/README_20230728004120.md
Normal file
27
.history/README_20230728004120.md
Normal file
@@ -0,0 +1,27 @@
|
||||
## Style Selector for SDXL 1.0
|
||||
|
||||
This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0.
|
||||
|
||||
### Styles
|
||||
|
||||
Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel.
|
||||
|
||||
### Installation
|
||||
|
||||
Enter this repo's URL in Automatic1111's extension tab "Install from Url":
|
||||
|
||||
https://github.com/ahgsql/StyleSelectorXL.git
|
||||
|
||||
### Usage
|
||||
|
||||
Enable or Disable it On Extension's panel, Write your subject into Prompt field,
|
||||
Select Style then hit Generate!
|
||||
The selected style will be applied to your current prompts.
|
||||
|
||||
### Thanks
|
||||
|
||||
Huge thanks for https://github.com/twri/sdxl_prompt_styler as i got style json file from his repo.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
27
.history/README_20230728004134.md
Normal file
27
.history/README_20230728004134.md
Normal file
@@ -0,0 +1,27 @@
|
||||
## Style Selector for SDXL 1.0
|
||||
|
||||
This repository contains a Automatic1111 Extension allows users to select and apply different styles to their inputs using SDXL 1.0.
|
||||
|
||||
### Styles
|
||||
|
||||
Released positive and negative templates are used to generate stylized prompts. Just install extension, then SDXL Styles will appear in the panel.
|
||||
|
||||
### Installation
|
||||
|
||||
Enter this repo's URL in Automatic1111's extension tab "Install from Url":
|
||||
|
||||
https://github.com/ahgsql/StyleSelectorXL.git
|
||||
|
||||
### Usage
|
||||
|
||||
Enable or Disable it On Extension's panel, Write your subject into Prompt field,
|
||||
Select Style then hit Generate!
|
||||
The selected style will be applied to your current prompts.
|
||||
|
||||
### Thanks
|
||||
|
||||
Huge thanks for https://github.com/twri/sdxl_prompt_styler as i got style json file's original structure from his repo.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
65
.history/scripts/SendtoTextImg_20230709123111.py
Normal file
65
.history/scripts/SendtoTextImg_20230709123111.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
return old_text + " " + new_text # else join them together and send it to the textbox
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Example"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Send centrum", open=False):
|
||||
send_text_button = gr.Button(value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
with contextlib.suppress(AttributeError): # Ignore the error if the attribute is not present
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
#https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": #postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": #postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
#this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
#switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
#if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
#if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
65
.history/scripts/SendtoTextImg_20230727230227.py
Normal file
65
.history/scripts/SendtoTextImg_20230727230227.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
return old_text + " " + new_text # else join them together and send it to the textbox
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Send centrum", open=False):
|
||||
send_text_button = gr.Button(value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
with contextlib.suppress(AttributeError): # Ignore the error if the attribute is not present
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
#https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": #postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": #postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
#this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
#switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
#if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
#if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
64
.history/scripts/SendtoTextImg_20230727230407.py
Normal file
64
.history/scripts/SendtoTextImg_20230727230407.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Send centrum", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
64
.history/scripts/SendtoTextImg_20230727230414.py
Normal file
64
.history/scripts/SendtoTextImg_20230727230414.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
64
.history/scripts/SendtoTextImg_20230727230903.py
Normal file
64
.history/scripts/SendtoTextImg_20230727230903.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
64
.history/scripts/StyleSelectorXL_20230727230902.py
Normal file
64
.history/scripts/StyleSelectorXL_20230727230902.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class ExampleScript(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
64
.history/scripts/StyleSelectorXL_20230727231505.py
Normal file
64
.history/scripts/StyleSelectorXL_20230727231505.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
150
.history/scripts/StyleSelectorXL_20230727231535.py
Normal file
150
.history/scripts/StyleSelectorXL_20230727231535.py
Normal file
@@ -0,0 +1,150 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
if use_main_seed:
|
||||
declone_seed = p.all_seeds[0]
|
||||
elif declone_seed == -1:
|
||||
declone_seed = int(random.randrange(4294967294))
|
||||
else:
|
||||
declone_seed = int(declone_seed)
|
||||
|
||||
# original_prompt = p.all_prompts[0]
|
||||
# settings = f"gender={gender}, beginning={insert_start}, declone_weight={declone_weight}, main_seed={use_main_seed}, " + \
|
||||
# f"declone_seed={declone_seed}, exclude_regions={exclude_regions}"
|
||||
p.extra_generation_params["CloneCleaner enabled"] = True
|
||||
p.extra_generation_params["CC_gender"] = gender
|
||||
p.extra_generation_params["CC_insert_start"] = insert_start
|
||||
p.extra_generation_params["CC_declone_weight"] = declone_weight
|
||||
p.extra_generation_params["CC_use_main_seed"] = use_main_seed
|
||||
p.extra_generation_params["CC_declone_seed"] = declone_seed
|
||||
if exclude_regions:
|
||||
p.extra_generation_params["CC_exclude_regions"] = ",".join(exclude_regions)
|
||||
if exclude_hairlength:
|
||||
p.extra_generation_params["CC_exclude_hairlength"] = ",".join(exclude_hairlength)
|
||||
if exclude_haircolor:
|
||||
p.extra_generation_params["CC_exclude_haircolor"] = ",".join(exclude_haircolor)
|
||||
|
||||
countrytree = self.prompt_tree["country"]
|
||||
hairtree = self.prompt_tree["hair"]
|
||||
|
||||
regions = sorted_difference(countrytree.keys(), exclude_regions)
|
||||
hairlengths = sorted_difference(hairtree["length"].keys(), exclude_hairlength)
|
||||
haircolors = sorted_difference(hairtree["color"].keys(), exclude_haircolor)
|
||||
|
||||
use_name = "name" in use_components
|
||||
use_country = "country" in use_components
|
||||
use_length = "hair length" in use_components
|
||||
use_style = "hair style" in use_components
|
||||
use_color = "hair color" in use_components
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
rng = random.Random()
|
||||
seed = p.all_seeds[i] if use_main_seed else declone_seed + i
|
||||
rng.seed(seed)
|
||||
|
||||
region = rng.choice(regions)
|
||||
countries = list(countrytree[region].keys())
|
||||
countryweights = [countrytree[region][cty]["weight"] for cty in countries]
|
||||
country = rng.choices(countries, weights=countryweights)[0]
|
||||
|
||||
countrydata = countrytree[region][country]
|
||||
hairdata = countrydata.get("hair", hairtree["defaultweight"][region])
|
||||
maincolor = rng.choices(haircolors, weights=[hairdata[col] for col in haircolors])[0]
|
||||
color = rng.choice(hairtree["color"][maincolor])
|
||||
mainlength = rng.choice(hairlengths)
|
||||
length = rng.choice(hairtree["length"][mainlength])
|
||||
style = rng.choice(hairtree["style"][mainlength])
|
||||
name = rng.choice(countrydata["names"])
|
||||
|
||||
inserted_prompt = ""
|
||||
|
||||
if use_name or use_country:
|
||||
inserted_prompt += name if use_name else "person"
|
||||
inserted_prompt += " from " + country if use_country else ""
|
||||
|
||||
if use_length or use_style or use_color:
|
||||
if inserted_prompt:
|
||||
inserted_prompt += ", "
|
||||
if use_length:
|
||||
inserted_prompt += length + " "
|
||||
if use_style:
|
||||
inserted_prompt += style + " "
|
||||
if use_color:
|
||||
inserted_prompt += color + " "
|
||||
inserted_prompt += "hair"
|
||||
|
||||
if inserted_prompt:
|
||||
if declone_weight != 1:
|
||||
inserted_prompt = f"({inserted_prompt}:{declone_weight})"
|
||||
|
||||
if insert_start:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
else:
|
||||
p.all_prompts[i] = prompt + ", " + inserted_prompt
|
||||
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
118
.history/scripts/StyleSelectorXL_20230727231708.py
Normal file
118
.history/scripts/StyleSelectorXL_20230727231708.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
rng = random.Random()
|
||||
seed = p.all_seeds[i] if use_main_seed else declone_seed + i
|
||||
rng.seed(seed)
|
||||
|
||||
region = rng.choice(regions)
|
||||
countries = list(countrytree[region].keys())
|
||||
countryweights = [countrytree[region][cty]["weight"]
|
||||
for cty in countries]
|
||||
country = rng.choices(countries, weights=countryweights)[0]
|
||||
|
||||
countrydata = countrytree[region][country]
|
||||
hairdata = countrydata.get(
|
||||
"hair", hairtree["defaultweight"][region])
|
||||
maincolor = rng.choices(haircolors, weights=[
|
||||
hairdata[col] for col in haircolors])[0]
|
||||
color = rng.choice(hairtree["color"][maincolor])
|
||||
mainlength = rng.choice(hairlengths)
|
||||
length = rng.choice(hairtree["length"][mainlength])
|
||||
style = rng.choice(hairtree["style"][mainlength])
|
||||
name = rng.choice(countrydata["names"])
|
||||
|
||||
inserted_prompt = ""
|
||||
|
||||
if use_name or use_country:
|
||||
inserted_prompt += name if use_name else "person"
|
||||
inserted_prompt += " from " + country if use_country else ""
|
||||
|
||||
if use_length or use_style or use_color:
|
||||
if inserted_prompt:
|
||||
inserted_prompt += ", "
|
||||
if use_length:
|
||||
inserted_prompt += length + " "
|
||||
if use_style:
|
||||
inserted_prompt += style + " "
|
||||
if use_color:
|
||||
inserted_prompt += color + " "
|
||||
inserted_prompt += "hair"
|
||||
|
||||
if inserted_prompt:
|
||||
|
||||
if insert_start:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
else:
|
||||
p.all_prompts[i] = prompt + ", " + inserted_prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
114
.history/scripts/StyleSelectorXL_20230727231728.py
Normal file
114
.history/scripts/StyleSelectorXL_20230727231728.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
rng = random.Random()
|
||||
seed = p.all_seeds[i] if use_main_seed else declone_seed + i
|
||||
rng.seed(seed)
|
||||
|
||||
region = rng.choice(regions)
|
||||
countries = list(countrytree[region].keys())
|
||||
countryweights = [countrytree[region][cty]["weight"]
|
||||
for cty in countries]
|
||||
country = rng.choices(countries, weights=countryweights)[0]
|
||||
|
||||
countrydata = countrytree[region][country]
|
||||
hairdata = countrydata.get(
|
||||
"hair", hairtree["defaultweight"][region])
|
||||
maincolor = rng.choices(haircolors, weights=[
|
||||
hairdata[col] for col in haircolors])[0]
|
||||
color = rng.choice(hairtree["color"][maincolor])
|
||||
mainlength = rng.choice(hairlengths)
|
||||
length = rng.choice(hairtree["length"][mainlength])
|
||||
style = rng.choice(hairtree["style"][mainlength])
|
||||
name = rng.choice(countrydata["names"])
|
||||
|
||||
inserted_prompt = ""
|
||||
|
||||
if use_name or use_country:
|
||||
inserted_prompt += name if use_name else "person"
|
||||
inserted_prompt += " from " + country if use_country else ""
|
||||
|
||||
if use_length or use_style or use_color:
|
||||
if inserted_prompt:
|
||||
inserted_prompt += ", "
|
||||
if use_length:
|
||||
inserted_prompt += length + " "
|
||||
if use_style:
|
||||
inserted_prompt += style + " "
|
||||
if use_color:
|
||||
inserted_prompt += color + " "
|
||||
inserted_prompt += "hair"
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
79
.history/scripts/StyleSelectorXL_20230727231803.py
Normal file
79
.history/scripts/StyleSelectorXL_20230727231803.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ"
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
79
.history/scripts/StyleSelectorXL_20230727231809.py
Normal file
79
.history/scripts/StyleSelectorXL_20230727231809.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
79
.history/scripts/StyleSelectorXL_20230727231918.py
Normal file
79
.history/scripts/StyleSelectorXL_20230727231918.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
90
.history/scripts/StyleSelectorXL_20230727232247.py
Normal file
90
.history/scripts/StyleSelectorXL_20230727232247.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def read_json_file(file_path):
|
||||
try:
|
||||
# Open file, load JSON content into python dictionary, and return it.
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
107
.history/scripts/StyleSelectorXL_20230727232356.py
Normal file
107
.history/scripts/StyleSelectorXL_20230727232356.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def read_json_file(file_path):
|
||||
try:
|
||||
# Open file, load JSON content into python dictionary, and return it.
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
118
.history/scripts/StyleSelectorXL_20230727232544.py
Normal file
118
.history/scripts/StyleSelectorXL_20230727232544.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def read_json_file(file_path):
|
||||
try:
|
||||
# Open file, load JSON content into python dictionary, and return it.
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
# Construct 'sdxl_styles.json' path
|
||||
file_path = os.path.join(path, 'sdxl_styles.json')
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
122
.history/scripts/StyleSelectorXL_20230727232637.py
Normal file
122
.history/scripts/StyleSelectorXL_20230727232637.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def read_json_file(file_path):
|
||||
try:
|
||||
# Open file, load JSON content into python dictionary, and return it.
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
print(path)
|
||||
# Construct 'sdxl_styles.json' path
|
||||
file_path = os.path.join(path, 'sdxl_styles.json')
|
||||
print(file_path)
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
119
.history/scripts/StyleSelectorXL_20230727232827.py
Normal file
119
.history/scripts/StyleSelectorXL_20230727232827.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
print(path)
|
||||
# Construct 'sdxl_styles.json' path
|
||||
file_path = os.path.join(path, 'sdxl_styles.json')
|
||||
print(file_path)
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
119
.history/scripts/StyleSelectorXL_20230727232832.py
Normal file
119
.history/scripts/StyleSelectorXL_20230727232832.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
print(path)
|
||||
# Construct 'sdxl_styles.json' path
|
||||
file_path = os.path.join(path, 'sdxl_styles.json')
|
||||
print(file_path)
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
115
.history/scripts/StyleSelectorXL_20230727232939.py
Normal file
115
.history/scripts/StyleSelectorXL_20230727232939.py
Normal file
@@ -0,0 +1,115 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(file_path)
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
117
.history/scripts/StyleSelectorXL_20230727233047.py
Normal file
117
.history/scripts/StyleSelectorXL_20230727233047.py
Normal file
@@ -0,0 +1,117 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
def getStyles():
|
||||
json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
print(styles)
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
|
||||
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
118
.history/scripts/StyleSelectorXL_20230727233056.py
Normal file
118
.history/scripts/StyleSelectorXL_20230727233056.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
def getStyles():
|
||||
json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
|
||||
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
120
.history/scripts/StyleSelectorXL_20230727233110.py
Normal file
120
.history/scripts/StyleSelectorXL_20230727233110.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
def getStyles():
|
||||
json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames=getStyles();
|
||||
print(styleNames)
|
||||
|
||||
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
119
.history/scripts/StyleSelectorXL_20230727233114.py
Normal file
119
.history/scripts/StyleSelectorXL_20230727233114.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
def getStyles():
|
||||
json_path=os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames=getStyles();
|
||||
print(styleNames)
|
||||
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable CloneCleaner")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
124
.history/scripts/StyleSelectorXL_20230727233237.py
Normal file
124
.history/scripts/StyleSelectorXL_20230727233237.py
Normal file
@@ -0,0 +1,124 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
send_text_button = gr.Button(
|
||||
value='send text', variant='primary')
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
109
.history/scripts/StyleSelectorXL_20230727233428.py
Normal file
109
.history/scripts/StyleSelectorXL_20230727233428.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
109
.history/scripts/StyleSelectorXL_20230727233450.py
Normal file
109
.history/scripts/StyleSelectorXL_20230727233450.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
109
.history/scripts/StyleSelectorXL_20230727233452.py
Normal file
109
.history/scripts/StyleSelectorXL_20230727233452.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
107
.history/scripts/StyleSelectorXL_20230727233502.py
Normal file
107
.history/scripts/StyleSelectorXL_20230727233502.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
107
.history/scripts/StyleSelectorXL_20230727233525.py
Normal file
107
.history/scripts/StyleSelectorXL_20230727233525.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727233536.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727233536.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
122
.history/scripts/StyleSelectorXL_20230727233754.py
Normal file
122
.history/scripts/StyleSelectorXL_20230727233754.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent, send_text_button]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, send_text_button):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
122
.history/scripts/StyleSelectorXL_20230727234105.py
Normal file
122
.history/scripts/StyleSelectorXL_20230727234105.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent,]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
122
.history/scripts/StyleSelectorXL_20230727234108.py
Normal file
122
.history/scripts/StyleSelectorXL_20230727234108.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
print(styleNames)
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
121
.history/scripts/StyleSelectorXL_20230727234115.py
Normal file
121
.history/scripts/StyleSelectorXL_20230727234115.py
Normal file
@@ -0,0 +1,121 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
print(styles)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
119
.history/scripts/StyleSelectorXL_20230727234120.py
Normal file
119
.history/scripts/StyleSelectorXL_20230727234120.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
with contextlib.suppress(AttributeError):
|
||||
if is_img2img:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxxIMG (textbox)
|
||||
# Outputs: self.boxxIMG (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxxIMG], outputs=[self.boxxIMG])
|
||||
else:
|
||||
# Bind the click event of the button to the send_text_to_prompt function
|
||||
# Inputs: text_to_be_sent (textbox), self.boxx (textbox)
|
||||
# Outputs: self.boxx (textbox)
|
||||
send_text_button.click(fn=send_text_to_prompt, inputs=[
|
||||
text_to_be_sent, self.boxx], outputs=[self.boxx])
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234140.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234140.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234218.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234218.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent,style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234223.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234223.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent,style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent,style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234231.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234231.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234254.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234254.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
107
.history/scripts/StyleSelectorXL_20230727234317.py
Normal file
107
.history/scripts/StyleSelectorXL_20230727234317.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
print(style)
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234622.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234622.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=False):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234653.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234653.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(self.styleNames, label="Location",
|
||||
info="Where did they go?"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727234853.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727234853.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style =gr.Radio(label = 'Style', choices = self.styleNames, info="Select Your Style"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent,style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent,style):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(style)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727234911.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727234911.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector"),
|
||||
style = gr.Radio(
|
||||
label='Style', choices=self.styleNames, info="Select Your Style"),
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(style)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235044.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235044.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
codec = gr.Radio(label = 'Codec', choices = ['x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value = 'x264')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(style)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727235049.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727235049.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
codec = gr.Radio(label='Codec', choices=[
|
||||
'x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value='x264')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, codec]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, codec):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(style)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727235105.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727235105.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
codec = gr.Radio(label='Codec', choices=[
|
||||
'x264', 'x265', 'vpx-vp9', 'aom-av1', 'prores_ks'], value='x264')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, codec]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, codec):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(codec)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235234.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235234.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(label='Codec', choices=self.styleNames, value='sai-base')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(stylecodec)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
106
.history/scripts/StyleSelectorXL_20230727235237.py
Normal file
106
.history/scripts/StyleSelectorXL_20230727235237.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
text_to_be_sent = gr.Textbox(label="drop text")
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, text_to_be_sent, style]
|
||||
|
||||
def process(self, p, is_enabled, text_to_be_sent, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
print(style)
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = "ALİ HAYDAR GÜLEÇ" + text_to_be_sent
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235322.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235322.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235435.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235435.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
print(p.all_prompts[i])
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235527.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235527.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
print(p.all_prompts)
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
105
.history/scripts/StyleSelectorXL_20230727235806.py
Normal file
105
.history/scripts/StyleSelectorXL_20230727235806.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
print(p.all_prompts)
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
104
.history/scripts/StyleSelectorXL_20230727235810.py
Normal file
104
.history/scripts/StyleSelectorXL_20230727235810.py
Normal file
@@ -0,0 +1,104 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
110
.history/scripts/StyleSelectorXL_20230727235847.py
Normal file
110
.history/scripts/StyleSelectorXL_20230727235847.py
Normal file
@@ -0,0 +1,110 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
for i, prompt in enumerate(p.all_negative_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
111
.history/scripts/StyleSelectorXL_20230727235855.py
Normal file
111
.history/scripts/StyleSelectorXL_20230727235855.py
Normal file
@@ -0,0 +1,111 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
inserted_prompt = style + " ve negatif"
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
143
.history/scripts/StyleSelectorXL_20230728000356.py
Normal file
143
.history/scripts/StyleSelectorXL_20230728000356.py
Normal file
@@ -0,0 +1,143 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
def createprompts(style,positive,negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError("Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError("Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == template_name:
|
||||
positive_prompt = template['prompt'].replace('{prompt}', positive_prompt)
|
||||
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative_prompt:
|
||||
negative_prompt = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt else negative_prompt
|
||||
else:
|
||||
negative_prompt = json_negative_prompt
|
||||
|
||||
return positive_prompt, negative_prompt
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{template_name}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
inserted_prompt = style + " ve negatif"
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
145
.history/scripts/StyleSelectorXL_20230728000429.py
Normal file
145
.history/scripts/StyleSelectorXL_20230728000429.py
Normal file
@@ -0,0 +1,145 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive_prompt = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative_prompt:
|
||||
negative_prompt = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt else negative_prompt
|
||||
else:
|
||||
negative_prompt = json_negative_prompt
|
||||
|
||||
return positive_prompt, negative_prompt
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{template_name}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
inserted_prompt = style + " ve negatif"
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
145
.history/scripts/StyleSelectorXL_20230728000535.py
Normal file
145
.history/scripts/StyleSelectorXL_20230728000535.py
Normal file
@@ -0,0 +1,145 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{template_name}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
inserted_prompt = style + " ve negatif"
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
145
.history/scripts/StyleSelectorXL_20230728000619.py
Normal file
145
.history/scripts/StyleSelectorXL_20230728000619.py
Normal file
@@ -0,0 +1,145 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
inserted_prompt = style
|
||||
if inserted_prompt:
|
||||
p.all_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
inserted_prompt = style + " ve negatif"
|
||||
if inserted_prompt:
|
||||
p.all_negative_prompts[i] = inserted_prompt + ", " + prompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
140
.history/scripts/StyleSelectorXL_20230728000820.py
Normal file
140
.history/scripts/StyleSelectorXL_20230728000820.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt)
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
140
.history/scripts/StyleSelectorXL_20230728000827.py
Normal file
140
.history/scripts/StyleSelectorXL_20230728000827.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt)
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
140
.history/scripts/StyleSelectorXL_20230728000935.py
Normal file
140
.history/scripts/StyleSelectorXL_20230728000935.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def send_text_to_prompt(new_text, old_text):
|
||||
if old_text == "": # if text on the textbox text2img or img2img is empty, return new text
|
||||
return new_text
|
||||
# else join them together and send it to the textbox
|
||||
return old_text + " " + new_text
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt,"")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style,"", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
134
.history/scripts/StyleSelectorXL_20230728001229.py
Normal file
134
.history/scripts/StyleSelectorXL_20230728001229.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt,"")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style,"", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
135
.history/scripts/StyleSelectorXL_20230728001411.py
Normal file
135
.history/scripts/StyleSelectorXL_20230728001411.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt,"")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style,"", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
134
.history/scripts/StyleSelectorXL_20230728001414.py
Normal file
134
.history/scripts/StyleSelectorXL_20230728001414.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
137
.history/scripts/StyleSelectorXL_20230728001524.py
Normal file
137
.history/scripts/StyleSelectorXL_20230728001524.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
138
.history/scripts/StyleSelectorXL_20230728001727.py
Normal file
138
.history/scripts/StyleSelectorXL_20230728001727.py
Normal file
@@ -0,0 +1,138 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
136
.history/scripts/StyleSelectorXL_20230728001742.py
Normal file
136
.history/scripts/StyleSelectorXL_20230728001742.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = self.createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = self.createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
137
.history/scripts/StyleSelectorXL_20230728001928.py
Normal file
137
.history/scripts/StyleSelectorXL_20230728001928.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
print(style, prompt, "")
|
||||
positivePrompt = self.createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = self.createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
137
.history/scripts/StyleSelectorXL_20230728002038.py
Normal file
137
.history/scripts/StyleSelectorXL_20230728002038.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def createprompts(self, style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
print(style, prompt, "")
|
||||
positivePrompt = self.createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = self.createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
137
.history/scripts/StyleSelectorXL_20230728002129.py
Normal file
137
.history/scripts/StyleSelectorXL_20230728002129.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
138
.history/scripts/StyleSelectorXL_20230728002356.py
Normal file
138
.history/scripts/StyleSelectorXL_20230728002356.py
Normal file
@@ -0,0 +1,138 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath=""
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath=json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
print(json_path)
|
||||
|
||||
json_data = get_json_content(json_path)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
139
.history/scripts/StyleSelectorXL_20230728002406.py
Normal file
139
.history/scripts/StyleSelectorXL_20230728002406.py
Normal file
@@ -0,0 +1,139 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
print(stylespath)
|
||||
|
||||
json_data = get_json_content(stylespath)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
140
.history/scripts/StyleSelectorXL_20230728002539.py
Normal file
140
.history/scripts/StyleSelectorXL_20230728002539.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
print(stylespath)
|
||||
|
||||
json_data = get_json_content(stylespath)
|
||||
print(json_data)
|
||||
print(type(json_data))
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
139
.history/scripts/StyleSelectorXL_20230728002623.py
Normal file
139
.history/scripts/StyleSelectorXL_20230728002623.py
Normal file
@@ -0,0 +1,139 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
print(stylespath)
|
||||
|
||||
json_data = get_json_content(stylespath)
|
||||
print(json_data)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
137
.history/scripts/StyleSelectorXL_20230728002626.py
Normal file
137
.history/scripts/StyleSelectorXL_20230728002626.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
print(stylespath)
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
136
.history/scripts/StyleSelectorXL_20230728002629.py
Normal file
136
.history/scripts/StyleSelectorXL_20230728002629.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
136
.history/scripts/StyleSelectorXL_20230728002725.py
Normal file
136
.history/scripts/StyleSelectorXL_20230728002725.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
136
.history/scripts/StyleSelectorXL_20230728002727.py
Normal file
136
.history/scripts/StyleSelectorXL_20230728002727.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createprompts(style, positive, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
168
.history/scripts/StyleSelectorXL_20230728002906.py
Normal file
168
.history/scripts/StyleSelectorXL_20230728002906.py
Normal file
@@ -0,0 +1,168 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
163
.history/scripts/StyleSelectorXL_20230728002912.py
Normal file
163
.history/scripts/StyleSelectorXL_20230728002912.py
Normal file
@@ -0,0 +1,163 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
163
.history/scripts/StyleSelectorXL_20230728002915.py
Normal file
163
.history/scripts/StyleSelectorXL_20230728002915.py
Normal file
@@ -0,0 +1,163 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
161
.history/scripts/StyleSelectorXL_20230728003009.py
Normal file
161
.history/scripts/StyleSelectorXL_20230728003009.py
Normal file
@@ -0,0 +1,161 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return positive, negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
161
.history/scripts/StyleSelectorXL_20230728003012.py
Normal file
161
.history/scripts/StyleSelectorXL_20230728003012.py
Normal file
@@ -0,0 +1,161 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
161
.history/scripts/StyleSelectorXL_20230728003059.py
Normal file
161
.history/scripts/StyleSelectorXL_20230728003059.py
Normal file
@@ -0,0 +1,161 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
165
.history/scripts/StyleSelectorXL_20230728003121.py
Normal file
165
.history/scripts/StyleSelectorXL_20230728003121.py
Normal file
@@ -0,0 +1,165 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
print(createPositive(style, "alihaydar"))
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
print(createNegative(style, "alihaydar"))
|
||||
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
164
.history/scripts/StyleSelectorXL_20230728003231.py
Normal file
164
.history/scripts/StyleSelectorXL_20230728003231.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
165
.history/scripts/StyleSelectorXL_20230728003315.py
Normal file
165
.history/scripts/StyleSelectorXL_20230728003315.py
Normal file
@@ -0,0 +1,165 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
ali = createPositive(style, "alihaydar")
|
||||
print(ali)
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
# positivePrompt = createprompts(style, prompt, "")
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
164
.history/scripts/StyleSelectorXL_20230728003359.py
Normal file
164
.history/scripts/StyleSelectorXL_20230728003359.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
positivePrompt = createPositive(style, prompt)
|
||||
p.all_prompts[i] = "positivePrompt"
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
164
.history/scripts/StyleSelectorXL_20230728003403.py
Normal file
164
.history/scripts/StyleSelectorXL_20230728003403.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
positivePrompt = createPositive(style, prompt)
|
||||
p.all_prompts[i] =positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
# a, negativePrompt = createprompts(style, "", prompt)
|
||||
p.all_negative_prompts[i] = "negativePrompt"
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
164
.history/scripts/StyleSelectorXL_20230728003424.py
Normal file
164
.history/scripts/StyleSelectorXL_20230728003424.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("Select Style", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
positivePrompt = createPositive(style, prompt)
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
negativePrompt = createNegative(style, prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
164
.history/scripts/StyleSelectorXL_20230728003757.py
Normal file
164
.history/scripts/StyleSelectorXL_20230728003757.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import contextlib
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts
|
||||
from modules import script_callbacks
|
||||
import json
|
||||
import os
|
||||
|
||||
stylespath = ""
|
||||
|
||||
|
||||
def get_json_content(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
print(f"A Problem occurred: {str(e)}")
|
||||
|
||||
|
||||
def read_sdxl_styles(json_data):
|
||||
# Check that data is a list
|
||||
if not isinstance(json_data, list):
|
||||
print("Error: input data must be a list")
|
||||
return None
|
||||
|
||||
names = []
|
||||
|
||||
# Iterate over each item in the data list
|
||||
for item in json_data:
|
||||
# Check that the item is a dictionary
|
||||
if isinstance(item, dict):
|
||||
# Check that 'name' is a key in the dictionary
|
||||
if 'name' in item:
|
||||
# Append the value of 'name' to the names list
|
||||
names.append(item['name'])
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def getStyles():
|
||||
global stylespath
|
||||
json_path = os.path.join(scripts.basedir(), 'sdxl_styles.json')
|
||||
stylespath = json_path
|
||||
json_data = get_json_content(json_path)
|
||||
styles = read_sdxl_styles(json_data)
|
||||
return styles
|
||||
|
||||
|
||||
def createPositive(style, positive):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
positive = template['prompt'].replace(
|
||||
'{prompt}', positive)
|
||||
|
||||
return positive
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
def createNegative(style, negative):
|
||||
json_data = get_json_content(stylespath)
|
||||
try:
|
||||
# Check if json_data is a list
|
||||
if not isinstance(json_data, list):
|
||||
raise ValueError(
|
||||
"Invalid JSON data. Expected a list of templates.")
|
||||
|
||||
for template in json_data:
|
||||
# Check if template contains 'name' and 'prompt' fields
|
||||
if 'name' not in template or 'prompt' not in template:
|
||||
raise ValueError(
|
||||
"Invalid template. Missing 'name' or 'prompt' field.")
|
||||
|
||||
# Replace {prompt} in the matching template
|
||||
if template['name'] == style:
|
||||
json_negative_prompt = template.get('negative_prompt', "")
|
||||
if negative:
|
||||
negative = f"{json_negative_prompt}, {negative}" if json_negative_prompt else negative
|
||||
else:
|
||||
negative = json_negative_prompt
|
||||
|
||||
return negative
|
||||
|
||||
# If function hasn't returned yet, no matching template was found
|
||||
raise ValueError(f"No template found with name '{style}'.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
|
||||
class StyleSelectorXL(scripts.Script):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
styleNames = getStyles()
|
||||
|
||||
def title(self):
|
||||
return "Style Selector for SDXL 1.0"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with gr.Group():
|
||||
with gr.Accordion("SDXL Styles", open=True):
|
||||
is_enabled = gr.Checkbox(
|
||||
value=True, label="Enable Style Selector")
|
||||
style = gr.Radio(
|
||||
label='Codec', choices=self.styleNames, value='sai-base')
|
||||
|
||||
# Ignore the error if the attribute is not present
|
||||
|
||||
return [is_enabled, style]
|
||||
|
||||
def process(self, p, is_enabled, style):
|
||||
if not is_enabled:
|
||||
return
|
||||
|
||||
p.extra_generation_params["Style Selector Enabled"] = True
|
||||
|
||||
for i, prompt in enumerate(p.all_prompts): # for each image in batch
|
||||
|
||||
positivePrompt = createPositive(style, prompt)
|
||||
p.all_prompts[i] = positivePrompt
|
||||
# for each image in batch
|
||||
for i, prompt in enumerate(p.all_negative_prompts):
|
||||
|
||||
negativePrompt = createNegative(style, prompt)
|
||||
p.all_negative_prompts[i] = negativePrompt
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7456#issuecomment-1414465888 helpfull link
|
||||
# Find the text2img textbox component
|
||||
if kwargs.get("elem_id") == "txt2img_prompt": # postive prompt textbox
|
||||
self.boxx = component
|
||||
# Find the img2img textbox component
|
||||
if kwargs.get("elem_id") == "img2img_prompt": # postive prompt textbox
|
||||
self.boxxIMG = component
|
||||
|
||||
# this code below works aswell, you can send negative prompt text box,provided you change the code a little
|
||||
# switch self.boxx with self.neg_prompt_boxTXT and self.boxxIMG with self.neg_prompt_boxIMG
|
||||
|
||||
# if kwargs.get("elem_id") == "txt2img_neg_prompt":
|
||||
#self.neg_prompt_boxTXT = component
|
||||
# if kwargs.get("elem_id") == "img2img_neg_prompt":
|
||||
#self.neg_prompt_boxIMG = component
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user