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

2.5 KiB

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:
import contextlib
import gradio as gr
from modules import scripts
from modules import script_callbacks
import json
import os
  1. Define a function to read JSON content from a file:
def get_json_content(file_path):
    # ...
    return json_data
  1. Define a function to extract style names from the JSON data:
def read_sdxl_styles(json_data):
    # ...
    return names
  1. Define a function to get the available styles:
def getStyles():
    # ...
    return styles
  1. Define functions to create positive and negative prompts based on the selected style:
def createPositive(style, positive):
    # ...
    return positive

def createNegative(style, negative):
    # ...
    return negative
  1. Create a class StyleSelectorXL that extends the scripts.Script class:
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):
        # ...
  1. In the __main__ section, create an instance of the StyleSelectorXL class and use the gr.Interface to expose the UI:
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 file for details.