mirror of
https://github.com/ahgsql/StyleSelectorXL.git
synced 2026-01-26 11:09:53 +00:00
2.5 KiB
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
- 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
- Define a function to read JSON content from a file:
def get_json_content(file_path):
# ...
return json_data
- Define a function to extract style names from the JSON data:
def read_sdxl_styles(json_data):
# ...
return names
- Define a function to get the available styles:
def getStyles():
# ...
return styles
- 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
- Create a class
StyleSelectorXLthat extends thescripts.Scriptclass:
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):
# ...
- In the
__main__section, create an instance of theStyleSelectorXLclass and use thegr.Interfaceto 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.