Files
StyleSelectorXL/.history/README_20230728003913.md
2023-07-28 00:42:52 +03:00

107 lines
2.5 KiB
Markdown

## 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.