Spaces:
Running
on
A100
Running
on
A100
Commit
•
b888bcf
1
Parent(s):
f1f7ebd
cleanup
Browse files- .gitignore +1 -0
- app.py +84 -56
- 3d_style_4.jpeg → images/3d_style_4.jpeg +0 -0
- LineAni.Redmond.png → images/LineAni.Redmond.png +0 -0
- LogoRedmond-LogoLoraForSDXL.jpeg → images/LogoRedmond-LogoLoraForSDXL.jpeg +0 -0
- ToyRedmond-ToyLoraForSDXL10.png → images/ToyRedmond-ToyLoraForSDXL10.png +0 -0
- corgi_brick.jpeg → images/corgi_brick.jpeg +0 -0
- crayon.png → images/crayon.png +0 -0
- dog.png → images/dog.png +0 -0
- embroid.png → images/embroid.png +0 -0
- josef_koudelka.webp → images/josef_koudelka.webp +0 -0
- lego-minifig-xl.jpeg → images/lego-minifig-xl.jpeg +0 -0
- papercut_SDXL.jpeg → images/papercut_SDXL.jpeg +0 -0
- pikachu.webp → images/pikachu.webp +0 -0
- pixel-art-xl.jpeg → images/pixel-art-xl.jpeg +0 -0
- voxel-xl-lora.png → images/voxel-xl-lora.png +0 -0
- watercolor.png → images/watercolor.png +0 -0
- william_eggleston.webp → images/william_eggleston.webp +0 -0
- sdxl_loras.json +130 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.vscode
|
app.py
CHANGED
@@ -1,39 +1,40 @@
|
|
1 |
-
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
import lora
|
6 |
from time import sleep
|
7 |
import copy
|
|
|
8 |
|
9 |
-
sdxl_loras
|
10 |
-
|
11 |
-
(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
("josef_koudelka.webp", "Josef Koudelka Style", "TheLastBen/Josef_Koudelka_Style_SDXL", "by josef koudelka", "koud.safetensors", False),
|
25 |
-
("corgi_brick.jpeg", "Lego BrickHeadz", "nerijs/lego-brickheadz-xl", "lego brickheadz", "legobrickheadz-v1.0-000004.safetensors", True)
|
26 |
]
|
27 |
|
28 |
-
|
29 |
-
|
30 |
def update_selection(selected_state: gr.SelectData):
|
31 |
lora_repo = sdxl_loras[selected_state.index][2]
|
32 |
instance_prompt = sdxl_loras[selected_state.index][3]
|
33 |
updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo})"
|
34 |
return updated_text, instance_prompt, selected_state
|
35 |
|
36 |
-
|
|
|
|
|
|
|
37 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
38 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
39 |
vae=vae,
|
@@ -45,24 +46,25 @@ pipe.to("cuda")
|
|
45 |
last_lora = ""
|
46 |
last_merged = False
|
47 |
|
|
|
48 |
def run_lora(prompt, negative, weight, selected_state):
|
49 |
global last_lora, last_merged, pipe
|
50 |
-
if
|
51 |
raise gr.Error("You must select a LoRA")
|
52 |
repo_name = sdxl_loras[selected_state.index][2]
|
53 |
weight_name = sdxl_loras[selected_state.index][4]
|
54 |
full_path_lora = saved_names[selected_state.index]
|
55 |
cross_attention_kwargs = None
|
56 |
-
if
|
57 |
-
if
|
58 |
pipe = copy.deepcopy(original_pipe)
|
59 |
pipe.to("cuda")
|
60 |
else:
|
61 |
pipe.unload_lora_weights()
|
62 |
is_compatible = sdxl_loras[selected_state.index][5]
|
63 |
-
if
|
64 |
pipe.load_lora_weights(full_path_lora)
|
65 |
-
cross_attention_kwargs={"scale": weight}
|
66 |
else:
|
67 |
for weights_file in [full_path_lora]:
|
68 |
if ";" in weights_file:
|
@@ -72,17 +74,31 @@ def run_lora(prompt, negative, weight, selected_state):
|
|
72 |
multiplier = 1.0
|
73 |
|
74 |
lora_model, weights_sd = lora.create_network_from_weights(
|
75 |
-
multiplier,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
-
lora_model.merge_to(pipe.text_encoder, pipe.unet, weights_sd, torch.float16, "cuda")
|
78 |
last_merged = True
|
79 |
-
|
80 |
image = pipe(
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
82 |
last_lora = repo_name
|
83 |
return image
|
84 |
-
|
85 |
-
|
|
|
86 |
#title{text-align: center;margin-bottom: 0.5em}
|
87 |
#title h1{font-size: 3em}
|
88 |
#prompt textarea{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
@@ -90,19 +106,22 @@ css = '''
|
|
90 |
border-top-left-radius: 0px;}
|
91 |
#gallery{display:flex}
|
92 |
#gallery .grid-wrap{min-height: 100%;}
|
93 |
-
|
94 |
|
95 |
with gr.Blocks(css=css) as demo:
|
96 |
title = gr.Markdown("# LoRA the Explorer 🔎", elem_id="title")
|
97 |
with gr.Row():
|
98 |
-
gallery = gr.Gallery(
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
104 |
with gr.Column():
|
105 |
-
prompt_title = gr.Markdown(
|
|
|
|
|
106 |
with gr.Row():
|
107 |
prompt = gr.Textbox(label="Prompt", elem_id="prompt")
|
108 |
button = gr.Button("Run", elem_id="run_button")
|
@@ -111,20 +130,29 @@ with gr.Blocks(css=css) as demo:
|
|
111 |
negative = gr.Textbox(label="Negative Prompt")
|
112 |
weight = gr.Slider(0, 1, value=1, step=0.1, label="LoRA weight")
|
113 |
with gr.Column():
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
selected_state = gr.State()
|
125 |
-
gallery.select(
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
import lora
|
6 |
from time import sleep
|
7 |
import copy
|
8 |
+
import json
|
9 |
|
10 |
+
with open("sdxl_loras.json", "r") as file:
|
11 |
+
sdxl_loras = [
|
12 |
+
(
|
13 |
+
item["image"],
|
14 |
+
item["title"],
|
15 |
+
item["repo"],
|
16 |
+
item["trigger_word"],
|
17 |
+
item["weights"],
|
18 |
+
item["is_compatible"],
|
19 |
+
)
|
20 |
+
for item in json.load(file)
|
21 |
+
]
|
22 |
+
|
23 |
+
saved_names = [
|
24 |
+
hf_hub_download(repo_id, filename) for _, _, repo_id, _, filename, _ in sdxl_loras
|
|
|
|
|
25 |
]
|
26 |
|
27 |
+
|
|
|
28 |
def update_selection(selected_state: gr.SelectData):
|
29 |
lora_repo = sdxl_loras[selected_state.index][2]
|
30 |
instance_prompt = sdxl_loras[selected_state.index][3]
|
31 |
updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo})"
|
32 |
return updated_text, instance_prompt, selected_state
|
33 |
|
34 |
+
|
35 |
+
vae = AutoencoderKL.from_pretrained(
|
36 |
+
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
|
37 |
+
)
|
38 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
39 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
40 |
vae=vae,
|
|
|
46 |
last_lora = ""
|
47 |
last_merged = False
|
48 |
|
49 |
+
|
50 |
def run_lora(prompt, negative, weight, selected_state):
|
51 |
global last_lora, last_merged, pipe
|
52 |
+
if not selected_state:
|
53 |
raise gr.Error("You must select a LoRA")
|
54 |
repo_name = sdxl_loras[selected_state.index][2]
|
55 |
weight_name = sdxl_loras[selected_state.index][4]
|
56 |
full_path_lora = saved_names[selected_state.index]
|
57 |
cross_attention_kwargs = None
|
58 |
+
if last_lora != repo_name:
|
59 |
+
if last_merged:
|
60 |
pipe = copy.deepcopy(original_pipe)
|
61 |
pipe.to("cuda")
|
62 |
else:
|
63 |
pipe.unload_lora_weights()
|
64 |
is_compatible = sdxl_loras[selected_state.index][5]
|
65 |
+
if is_compatible:
|
66 |
pipe.load_lora_weights(full_path_lora)
|
67 |
+
cross_attention_kwargs = {"scale": weight}
|
68 |
else:
|
69 |
for weights_file in [full_path_lora]:
|
70 |
if ";" in weights_file:
|
|
|
74 |
multiplier = 1.0
|
75 |
|
76 |
lora_model, weights_sd = lora.create_network_from_weights(
|
77 |
+
multiplier,
|
78 |
+
full_path_lora,
|
79 |
+
pipe.vae,
|
80 |
+
pipe.text_encoder,
|
81 |
+
pipe.unet,
|
82 |
+
for_inference=True,
|
83 |
+
)
|
84 |
+
lora_model.apply_to(pipe.text_encoder, pipe.unet)
|
85 |
+
lora_model.merge_to(
|
86 |
+
pipe.text_encoder, pipe.unet, weights_sd, torch.float16, "cuda"
|
87 |
)
|
|
|
88 |
last_merged = True
|
89 |
+
|
90 |
image = pipe(
|
91 |
+
prompt=prompt,
|
92 |
+
negative_prompt=negative,
|
93 |
+
num_inference_steps=20,
|
94 |
+
guidance_scale=7.5,
|
95 |
+
cross_attention_kwargs=cross_attention_kwargs,
|
96 |
+
).images[0]
|
97 |
last_lora = repo_name
|
98 |
return image
|
99 |
+
|
100 |
+
|
101 |
+
css = """
|
102 |
#title{text-align: center;margin-bottom: 0.5em}
|
103 |
#title h1{font-size: 3em}
|
104 |
#prompt textarea{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
|
|
106 |
border-top-left-radius: 0px;}
|
107 |
#gallery{display:flex}
|
108 |
#gallery .grid-wrap{min-height: 100%;}
|
109 |
+
"""
|
110 |
|
111 |
with gr.Blocks(css=css) as demo:
|
112 |
title = gr.Markdown("# LoRA the Explorer 🔎", elem_id="title")
|
113 |
with gr.Row():
|
114 |
+
gallery = gr.Gallery(
|
115 |
+
value=[(a, b) for a, b, _, _, _, _ in sdxl_loras],
|
116 |
+
label="SDXL LoRA Gallery",
|
117 |
+
allow_preview=False,
|
118 |
+
columns=3,
|
119 |
+
elem_id="gallery",
|
120 |
+
)
|
121 |
with gr.Column():
|
122 |
+
prompt_title = gr.Markdown(
|
123 |
+
value="### Click on a LoRA in the gallery to select it", visible=True
|
124 |
+
)
|
125 |
with gr.Row():
|
126 |
prompt = gr.Textbox(label="Prompt", elem_id="prompt")
|
127 |
button = gr.Button("Run", elem_id="run_button")
|
|
|
130 |
negative = gr.Textbox(label="Negative Prompt")
|
131 |
weight = gr.Slider(0, 1, value=1, step=0.1, label="LoRA weight")
|
132 |
with gr.Column():
|
133 |
+
gr.Markdown("Use it with:")
|
134 |
+
with gr.Row():
|
135 |
+
with gr.Accordion("🧨 diffusers", open=False):
|
136 |
+
gr.Markdown("")
|
137 |
+
with gr.Accordion("ComfyUI", open=False):
|
138 |
+
gr.Markdown("")
|
139 |
+
with gr.Accordion("Invoke AI", open=False):
|
140 |
+
gr.Markdown("")
|
141 |
+
with gr.Accordion("SD.Next (AUTO1111 fork)", open=False):
|
142 |
+
gr.Markdown("")
|
143 |
selected_state = gr.State()
|
144 |
+
gallery.select(
|
145 |
+
update_selection,
|
146 |
+
outputs=[prompt_title, prompt, selected_state],
|
147 |
+
queue=False,
|
148 |
+
show_progress=False,
|
149 |
+
)
|
150 |
+
prompt.submit(
|
151 |
+
fn=run_lora, inputs=[prompt, negative, weight, selected_state], outputs=result
|
152 |
+
)
|
153 |
+
button.click(
|
154 |
+
fn=run_lora, inputs=[prompt, negative, weight, selected_state], outputs=result
|
155 |
+
)
|
156 |
+
|
157 |
+
|
158 |
+
demo.launch()
|
3d_style_4.jpeg → images/3d_style_4.jpeg
RENAMED
File without changes
|
LineAni.Redmond.png → images/LineAni.Redmond.png
RENAMED
File without changes
|
LogoRedmond-LogoLoraForSDXL.jpeg → images/LogoRedmond-LogoLoraForSDXL.jpeg
RENAMED
File without changes
|
ToyRedmond-ToyLoraForSDXL10.png → images/ToyRedmond-ToyLoraForSDXL10.png
RENAMED
File without changes
|
corgi_brick.jpeg → images/corgi_brick.jpeg
RENAMED
File without changes
|
crayon.png → images/crayon.png
RENAMED
File without changes
|
dog.png → images/dog.png
RENAMED
File without changes
|
embroid.png → images/embroid.png
RENAMED
File without changes
|
josef_koudelka.webp → images/josef_koudelka.webp
RENAMED
File without changes
|
lego-minifig-xl.jpeg → images/lego-minifig-xl.jpeg
RENAMED
File without changes
|
papercut_SDXL.jpeg → images/papercut_SDXL.jpeg
RENAMED
File without changes
|
pikachu.webp → images/pikachu.webp
RENAMED
File without changes
|
pixel-art-xl.jpeg → images/pixel-art-xl.jpeg
RENAMED
File without changes
|
voxel-xl-lora.png → images/voxel-xl-lora.png
RENAMED
File without changes
|
watercolor.png → images/watercolor.png
RENAMED
File without changes
|
william_eggleston.webp → images/william_eggleston.webp
RENAMED
File without changes
|
sdxl_loras.json
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"image": "images/pixel-art-xl.jpeg",
|
4 |
+
"title": "Pixel Art XL",
|
5 |
+
"repo": "nerijs/pixel-art-xl",
|
6 |
+
"trigger_word": "pixel art",
|
7 |
+
"weights": "pixel-art-xl.safetensors",
|
8 |
+
"is_compatible": true
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"image": "images/papercut_SDXL.jpeg",
|
12 |
+
"title": "Papercut SDXL",
|
13 |
+
"repo": "TheLastBen/Papercut_SDXL",
|
14 |
+
"trigger_word": "papercut",
|
15 |
+
"weights": "papercut.safetensors",
|
16 |
+
"is_compatible": false
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"image": "images/lego-minifig-xl.jpeg",
|
20 |
+
"title": "Lego Minifig XL",
|
21 |
+
"repo": "nerijs/lego-minifig-xl",
|
22 |
+
"trigger_word": "lego minifig",
|
23 |
+
"weights": "legominifig-v1.0-000003.safetensors",
|
24 |
+
"is_compatible": true
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"image": "images/embroid.png",
|
28 |
+
"title": "Embroidery Style",
|
29 |
+
"repo": "ostris/embroidery_style_lora_sdxl",
|
30 |
+
"trigger_word": "",
|
31 |
+
"weights": "embroidered_style_v1_sdxl.safetensors",
|
32 |
+
"is_compatible": false
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"image": "images/3d_style_4.jpeg",
|
36 |
+
"title": "3D Render Style",
|
37 |
+
"repo": "goofyai/3d_render_style_xl",
|
38 |
+
"trigger_word": "3d style",
|
39 |
+
"weights": "3d_render_style_xl.safetensors",
|
40 |
+
"is_compatible": true
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"image": "images/LogoRedmond-LogoLoraForSDXL.jpeg",
|
44 |
+
"title": "Logo.Redmond",
|
45 |
+
"repo": "artificialguybr/LogoRedmond-LogoLoraForSDXL",
|
46 |
+
"trigger_word": "LogoRedAF",
|
47 |
+
"weights": "LogoRedmond_LogoRedAF.safetensors",
|
48 |
+
"is_compatible": true
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"image": "images/LineAni.Redmond.png",
|
52 |
+
"title": "LinearManga.Redmond",
|
53 |
+
"repo": "artificialguybr/LineAniRedmond-LinearMangaSDXL",
|
54 |
+
"trigger_word": "LineAniAF",
|
55 |
+
"weights": "LineAniRedmond-LineAniAF.safetensors",
|
56 |
+
"is_compatible": true
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"image": "images/watercolor.png",
|
60 |
+
"title": "Watercolor Style",
|
61 |
+
"repo": "ostris/watercolor_style_lora_sdxl",
|
62 |
+
"trigger_word": "",
|
63 |
+
"weights": "watercolor_v1_sdxl.safetensors",
|
64 |
+
"is_compatible": false
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"image": "images/dog.png",
|
68 |
+
"title": "Cyborg Style",
|
69 |
+
"repo": "goofyai/cyborg_style_xl",
|
70 |
+
"trigger_word": "cyborg style",
|
71 |
+
"weights": "cyborg_style_xl-off.safetensors",
|
72 |
+
"is_compatible": true
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"image": "images/ToyRedmond-ToyLoraForSDXL10.png",
|
76 |
+
"title": "Toy.Redmond",
|
77 |
+
"repo": "artificialguybr/ToyRedmond-ToyLoraForSDXL10",
|
78 |
+
"trigger_word": "FnkRedmAF",
|
79 |
+
"weights": "ToyRedmond-FnkRedmAF.safetensors",
|
80 |
+
"is_compatible": true
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"image": "images/voxel-xl-lora.png",
|
84 |
+
"title": "Voxel XL",
|
85 |
+
"repo": "Fictiverse/Voxel_XL_Lora",
|
86 |
+
"trigger_word": "voxel style",
|
87 |
+
"weights": "VoxelXL_v1.safetensors",
|
88 |
+
"is_compatible": true
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"image": "images/crayon.png",
|
92 |
+
"title": "Crayon Style",
|
93 |
+
"repo": "ostris/crayon_style_lora_sdxl",
|
94 |
+
"trigger_word": "",
|
95 |
+
"weights": "crayons_v1_sdxl.safetensors",
|
96 |
+
"is_compatible": false
|
97 |
+
},
|
98 |
+
{
|
99 |
+
"image": "images/pikachu.webp",
|
100 |
+
"title": "Pikachu XL",
|
101 |
+
"repo": "TheLastBen/Pikachu_SDXL",
|
102 |
+
"trigger_word": "pikachu",
|
103 |
+
"weights": "pikachu.safetensors",
|
104 |
+
"is_compatible": false
|
105 |
+
},
|
106 |
+
{
|
107 |
+
"image": "images/william_eggleston.webp",
|
108 |
+
"title": "William Eggleston Style",
|
109 |
+
"repo": "TheLastBen/William_Eggleston_Style_SDXL",
|
110 |
+
"trigger_word": "by william eggleston",
|
111 |
+
"weights": "wegg.safetensors",
|
112 |
+
"is_compatible": false
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"image": "images/josef_koudelka.webp",
|
116 |
+
"title": "Josef Koudelka Style",
|
117 |
+
"repo": "TheLastBen/Josef_Koudelka_Style_SDXL",
|
118 |
+
"trigger_word": "by josef koudelka",
|
119 |
+
"weights": "koud.safetensors",
|
120 |
+
"is_compatible": false
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"image": "images/corgi_brick.jpeg",
|
124 |
+
"title": "Lego BrickHeadz",
|
125 |
+
"repo": "nerijs/lego-brickheadz-xl",
|
126 |
+
"trigger_word": "lego brickheadz",
|
127 |
+
"weights": "legobrickheadz-v1.0-000004.safetensors",
|
128 |
+
"is_compatible": true
|
129 |
+
}
|
130 |
+
]
|