Spaces:
Running
on
Zero
Running
on
Zero
add lora gallery (#1)
Browse files- add lora gallery (3823e025aae3b3d33c58f9e1ed2bf5716641e656)
- Upload flux_loras.json (31a7460ef4dcf1888602129484309b7b6a5a4f19)
- app.py +344 -81
- flux_loras.json +234 -0
app.py
CHANGED
|
@@ -1,116 +1,379 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
-
|
| 4 |
import spaces
|
| 5 |
import torch
|
| 6 |
import random
|
|
|
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
-
|
| 9 |
-
#from kontext_pipeline import FluxKontextPipeline
|
| 10 |
-
from pipeline_flux_kontext import FluxKontextPipeline
|
| 11 |
from diffusers import FluxTransformer2DModel
|
| 12 |
from diffusers.utils import load_image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
kontext_path = hf_hub_download(repo_id="diffusers/kontext-v2", filename="dev-opt-2-a-3.safetensors")
|
| 18 |
-
|
| 19 |
MAX_SEED = np.iinfo(np.int32).max
|
| 20 |
|
| 21 |
transformer = FluxTransformer2DModel.from_single_file(kontext_path, torch_dtype=torch.bfloat16)
|
| 22 |
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16).to("cuda")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
# width=new_width,
|
| 48 |
-
# height=new_height,
|
| 49 |
-
generator=torch.Generator().manual_seed(seed),
|
| 50 |
-
).images[0]
|
| 51 |
-
return image, seed, gr.update(visible=True)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
"""
|
| 59 |
|
|
|
|
| 60 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
"""
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
label="Guidance Scale",
|
| 92 |
-
minimum=1,
|
| 93 |
-
maximum=10,
|
| 94 |
-
step=0.1,
|
| 95 |
-
value=2.5,
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
with gr.Column():
|
| 99 |
-
result = gr.Image(label="Result", show_label=False, interactive=False)
|
| 100 |
-
reuse_button = gr.Button("Reuse this image", visible=False)
|
| 101 |
-
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
gr.on(
|
| 105 |
triggers=[run_button.click, prompt.submit],
|
| 106 |
-
fn
|
| 107 |
-
inputs
|
| 108 |
-
outputs
|
| 109 |
)
|
|
|
|
| 110 |
reuse_button.click(
|
| 111 |
-
fn
|
| 112 |
-
inputs
|
| 113 |
-
outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
)
|
| 115 |
|
|
|
|
| 116 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
|
|
|
| 3 |
import spaces
|
| 4 |
import torch
|
| 5 |
import random
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
from PIL import Image
|
| 9 |
+
from kontext_pipeline import FluxKontextPipeline
|
|
|
|
|
|
|
| 10 |
from diffusers import FluxTransformer2DModel
|
| 11 |
from diffusers.utils import load_image
|
| 12 |
+
from huggingface_hub import hf_hub_download, HfFileSystem, ModelCard
|
| 13 |
+
from safetensors.torch import load_file
|
| 14 |
+
import requests
|
| 15 |
+
import re
|
| 16 |
|
| 17 |
+
# Load Kontext model
|
|
|
|
|
|
|
| 18 |
kontext_path = hf_hub_download(repo_id="diffusers/kontext-v2", filename="dev-opt-2-a-3.safetensors")
|
|
|
|
| 19 |
MAX_SEED = np.iinfo(np.int32).max
|
| 20 |
|
| 21 |
transformer = FluxTransformer2DModel.from_single_file(kontext_path, torch_dtype=torch.bfloat16)
|
| 22 |
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16).to("cuda")
|
| 23 |
|
| 24 |
+
# Load LoRA data (you'll need to create this JSON file or modify to load your LoRAs)
|
| 25 |
+
try:
|
| 26 |
+
with open("flux_loras.json", "r") as file:
|
| 27 |
+
data = json.load(file)
|
| 28 |
+
flux_loras_raw = [
|
| 29 |
+
{
|
| 30 |
+
"image": item["image"],
|
| 31 |
+
"title": item["title"],
|
| 32 |
+
"repo": item["repo"],
|
| 33 |
+
"trigger_word": item.get("trigger_word", ""),
|
| 34 |
+
"weights": item.get("weights", "pytorch_lora_weights.safetensors"),
|
| 35 |
+
"likes": item.get("likes", 0),
|
| 36 |
+
"downloads": item.get("downloads", 0),
|
| 37 |
+
}
|
| 38 |
+
for item in data
|
| 39 |
+
]
|
| 40 |
+
except FileNotFoundError:
|
| 41 |
+
# Default LoRAs if JSON file doesn't exist
|
| 42 |
+
flux_loras_raw = [
|
| 43 |
+
{
|
| 44 |
+
"image": "https://via.placeholder.com/300x300?text=LoRA+1",
|
| 45 |
+
"title": "Example LoRA 1",
|
| 46 |
+
"repo": "example/lora1",
|
| 47 |
+
"trigger_word": "style1",
|
| 48 |
+
"weights": "pytorch_lora_weights.safetensors",
|
| 49 |
+
"likes": 100,
|
| 50 |
+
"downloads": 500,
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"image": "https://via.placeholder.com/300x300?text=LoRA+2",
|
| 54 |
+
"title": "Example LoRA 2",
|
| 55 |
+
"repo": "example/lora2",
|
| 56 |
+
"trigger_word": "style2",
|
| 57 |
+
"weights": "pytorch_lora_weights.safetensors",
|
| 58 |
+
"likes": 80,
|
| 59 |
+
"downloads": 300,
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
# Global variables for LoRA management
|
| 64 |
+
current_lora = None
|
| 65 |
+
lora_cache = {}
|
| 66 |
+
|
| 67 |
+
def load_lora_weights(repo_id, weights_filename):
|
| 68 |
+
"""Load LoRA weights from HuggingFace"""
|
| 69 |
+
try:
|
| 70 |
+
if repo_id not in lora_cache:
|
| 71 |
+
lora_path = hf_hub_download(repo_id=repo_id, filename=weights_filename)
|
| 72 |
+
lora_cache[repo_id] = lora_path
|
| 73 |
+
return lora_cache[repo_id]
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"Error loading LoRA from {repo_id}: {e}")
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
def update_selection(selected_state: gr.SelectData, flux_loras):
|
| 79 |
+
"""Update UI when a LoRA is selected"""
|
| 80 |
+
if selected_state.index >= len(flux_loras):
|
| 81 |
+
return "### No LoRA selected", gr.update(), selected_state
|
| 82 |
+
|
| 83 |
+
lora_repo = flux_loras[selected_state.index]["repo"]
|
| 84 |
+
trigger_word = flux_loras[selected_state.index]["trigger_word"]
|
| 85 |
+
|
| 86 |
+
updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo})"
|
| 87 |
+
new_placeholder = f"Enter your editing prompt{f' (use {trigger_word} for best results)' if trigger_word else ''}"
|
| 88 |
+
|
| 89 |
+
return updated_text, gr.update(placeholder=new_placeholder), selected_state
|
| 90 |
+
|
| 91 |
+
def get_huggingface_lora(link):
|
| 92 |
+
"""Download LoRA from HuggingFace link"""
|
| 93 |
+
split_link = link.split("/")
|
| 94 |
+
if len(split_link) == 2:
|
| 95 |
+
try:
|
| 96 |
+
model_card = ModelCard.load(link)
|
| 97 |
+
trigger_word = model_card.data.get("instance_prompt", "")
|
| 98 |
+
|
| 99 |
+
fs = HfFileSystem()
|
| 100 |
+
list_of_files = fs.ls(link, detail=False)
|
| 101 |
+
safetensors_file = None
|
| 102 |
+
|
| 103 |
+
for file in list_of_files:
|
| 104 |
+
if file.endswith(".safetensors") and "lora" in file.lower():
|
| 105 |
+
safetensors_file = file.split("/")[-1]
|
| 106 |
+
break
|
| 107 |
+
|
| 108 |
+
if not safetensors_file:
|
| 109 |
+
safetensors_file = "pytorch_lora_weights.safetensors"
|
| 110 |
+
|
| 111 |
+
return split_link[1], safetensors_file, trigger_word
|
| 112 |
+
except Exception as e:
|
| 113 |
+
raise Exception(f"Error loading LoRA: {e}")
|
| 114 |
+
else:
|
| 115 |
+
raise Exception("Invalid HuggingFace repository format")
|
| 116 |
+
|
| 117 |
+
def load_custom_lora(link):
|
| 118 |
+
"""Load custom LoRA from user input"""
|
| 119 |
+
if not link:
|
| 120 |
+
return gr.update(visible=False), "", gr.update(visible=False), None, gr.Gallery(selected_index=None), "### Click on a LoRA in the gallery to select it"
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
repo_name, weights_file, trigger_word = get_huggingface_lora(link)
|
| 124 |
+
|
| 125 |
+
card = f'''
|
| 126 |
+
<div style="border: 1px solid #ddd; padding: 10px; border-radius: 8px; margin: 10px 0;">
|
| 127 |
+
<span><strong>Loaded custom LoRA:</strong></span>
|
| 128 |
+
<div style="margin-top: 8px;">
|
| 129 |
+
<h4>{repo_name}</h4>
|
| 130 |
+
<small>{"Using: <code><b>"+trigger_word+"</b></code> as trigger word" if trigger_word else "No trigger word found"}</small>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
'''
|
| 134 |
+
|
| 135 |
+
custom_lora_data = {
|
| 136 |
+
"repo": link,
|
| 137 |
+
"weights": weights_file,
|
| 138 |
+
"trigger_word": trigger_word
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return gr.update(visible=True), card, gr.update(visible=True), custom_lora_data, gr.Gallery(selected_index=None), f"Custom: {repo_name}"
|
| 142 |
+
|
| 143 |
+
except Exception as e:
|
| 144 |
+
return gr.update(visible=True), f"Error: {str(e)}", gr.update(visible=False), None, gr.update(), "### Click on a LoRA in the gallery to select it"
|
| 145 |
+
|
| 146 |
+
def remove_custom_lora():
|
| 147 |
+
"""Remove custom LoRA"""
|
| 148 |
+
return "", gr.update(visible=False), gr.update(visible=False), None
|
| 149 |
+
|
| 150 |
+
def classify_gallery(flux_loras):
|
| 151 |
+
"""Sort gallery by likes"""
|
| 152 |
+
sorted_gallery = sorted(flux_loras, key=lambda x: x.get("likes", 0), reverse=True)
|
| 153 |
+
return [(item["image"], item["title"]) for item in sorted_gallery], sorted_gallery
|
| 154 |
+
|
| 155 |
@spaces.GPU
|
| 156 |
+
def infer_with_lora(input_image, prompt, selected_state, custom_lora, seed=42, randomize_seed=False, guidance_scale=2.5, lora_scale=1.0, flux_loras=None, progress=gr.Progress(track_tqdm=True)):
|
| 157 |
+
"""Generate image with selected LoRA"""
|
| 158 |
+
global current_lora, pipe
|
| 159 |
|
| 160 |
if randomize_seed:
|
| 161 |
seed = random.randint(0, MAX_SEED)
|
| 162 |
+
|
| 163 |
+
# Determine which LoRA to use
|
| 164 |
+
lora_to_use = None
|
| 165 |
+
if custom_lora:
|
| 166 |
+
lora_to_use = custom_lora
|
| 167 |
+
elif selected_state and flux_loras:
|
| 168 |
+
selected_index = selected_state.index if hasattr(selected_state, 'index') else None
|
| 169 |
+
if selected_index is not None and selected_index < len(flux_loras):
|
| 170 |
+
lora_to_use = flux_loras[selected_index]
|
| 171 |
+
|
| 172 |
+
# Load LoRA if needed
|
| 173 |
+
if lora_to_use and lora_to_use != current_lora:
|
| 174 |
+
try:
|
| 175 |
+
# Unload current LoRA
|
| 176 |
+
if current_lora:
|
| 177 |
+
pipe.unload_lora_weights()
|
| 178 |
+
|
| 179 |
+
# Load new LoRA
|
| 180 |
+
lora_path = load_lora_weights(lora_to_use["repo"], lora_to_use["weights"])
|
| 181 |
+
if lora_path:
|
| 182 |
+
pipe.load_lora_weights(lora_path, adapter_name="selected_lora")
|
| 183 |
+
current_lora = lora_to_use
|
| 184 |
+
|
| 185 |
+
# Add trigger word to prompt if available
|
| 186 |
+
trigger_word = lora_to_use.get("trigger_word", "")
|
| 187 |
+
if trigger_word and trigger_word not in prompt:
|
| 188 |
+
prompt = f"{trigger_word} {prompt}"
|
| 189 |
+
|
| 190 |
+
except Exception as e:
|
| 191 |
+
print(f"Error loading LoRA: {e}")
|
| 192 |
+
# Continue without LoRA
|
| 193 |
+
|
| 194 |
+
# Set LoRA scale if LoRA is loaded
|
| 195 |
+
if current_lora and hasattr(pipe, 'set_adapters'):
|
| 196 |
+
try:
|
| 197 |
+
pipe.set_adapters("selected_lora", adapter_weights=[lora_scale])
|
| 198 |
+
except:
|
| 199 |
+
# Fallback for older diffusers versions
|
| 200 |
+
pass
|
| 201 |
+
|
| 202 |
input_image = input_image.convert("RGB")
|
| 203 |
+
|
| 204 |
+
try:
|
| 205 |
+
image = pipe(
|
| 206 |
+
image=input_image,
|
| 207 |
+
prompt=prompt,
|
| 208 |
+
guidance_scale=guidance_scale,
|
| 209 |
+
generator=torch.Generator().manual_seed(seed),
|
| 210 |
+
).images[0]
|
| 211 |
+
|
| 212 |
+
return image, seed, gr.update(visible=True)
|
| 213 |
+
|
| 214 |
+
except Exception as e:
|
| 215 |
+
print(f"Error during inference: {e}")
|
| 216 |
+
return None, seed, gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
# CSS styling
|
| 219 |
+
css = """
|
| 220 |
+
#main_app {
|
| 221 |
+
display: flex;
|
| 222 |
+
gap: 20px;
|
| 223 |
+
}
|
| 224 |
+
#box_column {
|
| 225 |
+
min-width: 400px;
|
| 226 |
+
}
|
| 227 |
+
#gallery_box {
|
| 228 |
+
border: 1px solid #ddd;
|
| 229 |
+
border-radius: 8px;
|
| 230 |
+
padding: 15px;
|
| 231 |
+
}
|
| 232 |
+
#gallery {
|
| 233 |
+
height: 400px;
|
| 234 |
+
}
|
| 235 |
+
#selected_lora {
|
| 236 |
+
color: #2563eb;
|
| 237 |
+
font-weight: bold;
|
| 238 |
+
}
|
| 239 |
+
#prompt {
|
| 240 |
+
flex-grow: 1;
|
| 241 |
+
}
|
| 242 |
+
#run_button {
|
| 243 |
+
background: linear-gradient(45deg, #2563eb, #3b82f6);
|
| 244 |
+
color: white;
|
| 245 |
+
border: none;
|
| 246 |
+
padding: 8px 16px;
|
| 247 |
+
border-radius: 6px;
|
| 248 |
+
font-weight: bold;
|
| 249 |
+
}
|
| 250 |
+
.custom_lora_card {
|
| 251 |
+
background: #f8fafc;
|
| 252 |
+
border: 1px solid #e2e8f0;
|
| 253 |
+
border-radius: 8px;
|
| 254 |
+
padding: 12px;
|
| 255 |
+
margin: 8px 0;
|
| 256 |
}
|
| 257 |
"""
|
| 258 |
|
| 259 |
+
# Create Gradio interface
|
| 260 |
with gr.Blocks(css=css) as demo:
|
| 261 |
+
gr_flux_loras = gr.State(value=flux_loras_raw)
|
| 262 |
|
| 263 |
+
title = gr.HTML(
|
| 264 |
+
"""<h1> FLUX.1 Kontext Portrait 👩🏻🎤
|
| 265 |
+
<br><small style="font-size: 13px; opacity: 0.75;"></small></h1>""",
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
selected_state = gr.State()
|
| 269 |
+
custom_loaded_lora = gr.State()
|
| 270 |
+
|
| 271 |
+
with gr.Row(elem_id="main_app"):
|
| 272 |
+
with gr.Column(scale=4, elem_id="box_column"):
|
| 273 |
+
with gr.Group(elem_id="gallery_box"):
|
| 274 |
+
input_image = gr.Image(label="Upload image for editing", type="pil", height=250)
|
| 275 |
+
|
| 276 |
+
gallery = gr.Gallery(
|
| 277 |
+
label="Pick a LoRA style from the gallery",
|
| 278 |
+
allow_preview=False,
|
| 279 |
+
columns=3,
|
| 280 |
+
elem_id="gallery",
|
| 281 |
+
show_share_button=False,
|
| 282 |
+
height=400
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
custom_model = gr.Textbox(
|
| 286 |
+
label="Or enter a custom HuggingFace FLUX LoRA",
|
| 287 |
+
placeholder="e.g., username/lora-name",
|
| 288 |
+
visible=False
|
| 289 |
+
)
|
| 290 |
+
custom_model_card = gr.HTML(visible=False)
|
| 291 |
+
custom_model_button = gr.Button("Remove custom LoRA", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
+
with gr.Column(scale=5):
|
| 294 |
+
with gr.Row():
|
| 295 |
+
prompt = gr.Textbox(
|
| 296 |
+
label="Editing Prompt",
|
| 297 |
+
show_label=False,
|
| 298 |
+
lines=1,
|
| 299 |
+
max_lines=1,
|
| 300 |
+
placeholder="Enter your editing prompt (e.g., 'Remove glasses', 'Add a hat')",
|
| 301 |
+
elem_id="prompt"
|
| 302 |
+
)
|
| 303 |
+
run_button = gr.Button("Generate", elem_id="run_button")
|
| 304 |
+
|
| 305 |
+
result = gr.Image(label="Generated Image", interactive=False)
|
| 306 |
+
reuse_button = gr.Button("Reuse this image", visible=False)
|
| 307 |
+
|
| 308 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 309 |
+
lora_scale = gr.Slider(
|
| 310 |
+
label="LoRA Scale",
|
| 311 |
+
minimum=0,
|
| 312 |
+
maximum=2,
|
| 313 |
+
step=0.1,
|
| 314 |
+
value=1.0,
|
| 315 |
+
info="Controls the strength of the LoRA effect"
|
| 316 |
+
)
|
| 317 |
+
seed = gr.Slider(
|
| 318 |
+
label="Seed",
|
| 319 |
+
minimum=0,
|
| 320 |
+
maximum=MAX_SEED,
|
| 321 |
+
step=1,
|
| 322 |
+
value=0,
|
| 323 |
+
)
|
| 324 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 325 |
+
guidance_scale = gr.Slider(
|
| 326 |
+
label="Guidance Scale",
|
| 327 |
+
minimum=1,
|
| 328 |
+
maximum=10,
|
| 329 |
+
step=0.1,
|
| 330 |
+
value=2.5,
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
prompt_title = gr.Markdown(
|
| 334 |
+
value="### Click on a LoRA in the gallery to select it",
|
| 335 |
+
visible=True,
|
| 336 |
+
elem_id="selected_lora",
|
| 337 |
+
)
|
| 338 |
|
| 339 |
+
# Event handlers
|
| 340 |
+
custom_model.input(
|
| 341 |
+
fn=load_custom_lora,
|
| 342 |
+
inputs=[custom_model],
|
| 343 |
+
outputs=[custom_model_card, custom_model_card, custom_model_button, custom_loaded_lora, gallery, prompt_title],
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
custom_model_button.click(
|
| 347 |
+
fn=remove_custom_lora,
|
| 348 |
+
outputs=[custom_model, custom_model_button, custom_model_card, custom_loaded_lora]
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
gallery.select(
|
| 352 |
+
fn=update_selection,
|
| 353 |
+
inputs=[gr_flux_loras],
|
| 354 |
+
outputs=[prompt_title, prompt, selected_state],
|
| 355 |
+
show_progress=False
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
gr.on(
|
| 359 |
triggers=[run_button.click, prompt.submit],
|
| 360 |
+
fn=infer_with_lora,
|
| 361 |
+
inputs=[input_image, prompt, selected_state, custom_loaded_lora, seed, randomize_seed, guidance_scale, lora_scale, gr_flux_loras],
|
| 362 |
+
outputs=[result, seed, reuse_button]
|
| 363 |
)
|
| 364 |
+
|
| 365 |
reuse_button.click(
|
| 366 |
+
fn=lambda image: image,
|
| 367 |
+
inputs=[result],
|
| 368 |
+
outputs=[input_image]
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
# Initialize gallery
|
| 372 |
+
demo.load(
|
| 373 |
+
fn=classify_gallery,
|
| 374 |
+
inputs=[gr_flux_loras],
|
| 375 |
+
outputs=[gallery, gr_flux_loras]
|
| 376 |
)
|
| 377 |
|
| 378 |
+
demo.queue(default_concurrency_limit=None)
|
| 379 |
demo.launch()
|
flux_loras.json
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"repo": "Purz/choose-your-own-adventure",
|
| 4 |
+
"image": "https://huggingface.co/Purz/choose-your-own-adventure/resolve/main/34584570.jpeg",
|
| 5 |
+
"trigger_word": "cy04,",
|
| 6 |
+
"trigger_position": "prepend",
|
| 7 |
+
"title": "choose your own adventure",
|
| 8 |
+
"aspect": "portrait"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"image": "https://huggingface.co/renderartist/retrocomicflux/resolve/main/images/ComfyUI_temp_ipugi_00131_.png",
|
| 12 |
+
"repo": "renderartist/retrocomicflux",
|
| 13 |
+
"trigger_word": "c0m1c style vintage 1930s style comic strip panel of",
|
| 14 |
+
"title": "Retro Comic",
|
| 15 |
+
"trigger_position": "prepend"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"image": "https://huggingface.co/glif/l0w-r3z/resolve/main/images/a19d658b-5d4c-45bc-9df6-f2bec54462a5.png",
|
| 19 |
+
"repo": "glif/l0w-r3z",
|
| 20 |
+
"trigger_word": ", l0w-r3z",
|
| 21 |
+
"title": "Low Res 3D"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"repo": "Purz/vhs-box",
|
| 25 |
+
"image": "https://huggingface.co/Purz/vhs-box/resolve/main/33726559.jpeg",
|
| 26 |
+
"trigger_word": ", vhs_box",
|
| 27 |
+
"title": "VHS Box"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"image": "https://huggingface.co/renderartist/simplevectorflux/resolve/main/images/ComfyUI_09477_.jpeg",
|
| 31 |
+
"title": "Simple Vector",
|
| 32 |
+
"repo": "renderartist/simplevectorflux",
|
| 33 |
+
"trigger_word": "v3ct0r style, simple flat vector art, isolated on white bg,",
|
| 34 |
+
"trigger_position": "prepend"
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"image": "https://huggingface.co/glif/anime-blockprint-style/resolve/main/images/glif-block-print-anime-flux-dev-araminta-k-lora-araminta-k-kbde06qyovrmvsv65ubfyhn1.jpg",
|
| 38 |
+
"repo": "glif/anime-blockprint-style",
|
| 39 |
+
"trigger_word": ", blockprint style",
|
| 40 |
+
"title": "Blockprint Style"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"image": "https://huggingface.co/Purz/face-projection/resolve/main/34031841.jpeg",
|
| 44 |
+
"repo": "Purz/face-projection",
|
| 45 |
+
"trigger_word": "f4c3_p40j3ct10n,",
|
| 46 |
+
"trigger_position": "prepend",
|
| 47 |
+
"title": "face projection"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"image": "https://huggingface.co/multimodalart/flux-tarot-v1/resolve/main/images/e5f2761e5d474e6ba492d20dca0fa26f_e78f1524074b42b6ac49643ffad50ac6.png",
|
| 51 |
+
"title": "Tarot v1",
|
| 52 |
+
"repo": "multimodalart/flux-tarot-v1",
|
| 53 |
+
"trigger_word": "in the style of TOK a trtcrd, tarot style",
|
| 54 |
+
"aspect": "portrait"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"repo": "alvdansen/pola-photo-flux",
|
| 58 |
+
"image": "https://huggingface.co/alvdansen/pola-photo-flux/resolve/main/images/out-2%20(83).webp",
|
| 59 |
+
"trigger_word": ", polaroid style",
|
| 60 |
+
"title": "Polaroid Style"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"image": "https://huggingface.co/dvyio/flux-lora-the-sims/resolve/main/images/dunBAVBsALOepaE_dsWFI_6b0fef6b0fc4472aa07d00edea7c75b3.jpg",
|
| 64 |
+
"repo": "dvyio/flux-lora-the-sims",
|
| 65 |
+
"trigger_word": ", video game screenshot in the style of THSMS",
|
| 66 |
+
"title": "The Sims style"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"image": "https://huggingface.co/alvdansen/softpasty-flux-dev/resolve/main/images/ComfyUI_00814_%20(2).png",
|
| 70 |
+
"title": "SoftPasty",
|
| 71 |
+
"repo": "alvdansen/softpasty-flux-dev",
|
| 72 |
+
"trigger_word": "araminta_illus illustration style"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"image": "https://huggingface.co/dvyio/flux-lora-film-noir/resolve/main/images/S8iWMa0GamEcFkanHHmI8_a232d8b83bb043808742d661dac257f7.jpg",
|
| 76 |
+
"title": "Film Noir",
|
| 77 |
+
"repo": "dvyio/flux-lora-film-noir",
|
| 78 |
+
"trigger_word": "in the style of FLMNR"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"image": "https://huggingface.co/AIWarper/RubberCore1920sCartoonStyle/resolve/main/images/Rub_00006_.png",
|
| 82 |
+
"title": "1920s cartoon",
|
| 83 |
+
"repo": "AIWarper/RubberCore1920sCartoonStyle",
|
| 84 |
+
"trigger_word": "RU883R style",
|
| 85 |
+
"trigger_position": "prepend"
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"image": "https://huggingface.co/Norod78/JojosoStyle-flux-lora/resolve/main/samples/1725244218477__000004255_1.jpg",
|
| 89 |
+
"title": "JoJo Style",
|
| 90 |
+
"repo": "Norod78/JojosoStyle-flux-lora",
|
| 91 |
+
"trigger_word": "JojosoStyle",
|
| 92 |
+
"trigger_position": "prepend"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/picture-6-rev1.png?raw=true",
|
| 96 |
+
"title": "flux-Realism",
|
| 97 |
+
"repo": "XLabs-AI/flux-RealismLora",
|
| 98 |
+
"trigger_word": ""
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"image": "https://huggingface.co/multimodalart/vintage-ads-flux/resolve/main/samples/j_XNU6Oe0mgttyvf9uPb3_dc244dd3d6c246b4aff8351444868d66.png",
|
| 102 |
+
"title": "Vintage Ads",
|
| 103 |
+
"repo":"multimodalart/vintage-ads-flux",
|
| 104 |
+
"trigger_word": "a vintage ad of",
|
| 105 |
+
"trigger_position": "prepend"
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"image": "https://huggingface.co/glif/how2draw/resolve/main/images/glif-how2draw-araminta-k-vbnvy94npt8m338r2vm02m50.jpg",
|
| 109 |
+
"repo": "glif/how2draw",
|
| 110 |
+
"trigger_word": ", How2Draw",
|
| 111 |
+
"title": "How2Draw"
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"image": "https://huggingface.co/mgwr/Cine-Aesthetic/resolve/main/images/00030-1333633802.png",
|
| 115 |
+
"title": "Cine Aesthetic",
|
| 116 |
+
"repo": "mgwr/Cine-Aesthetic",
|
| 117 |
+
"trigger_word": "mgwr/cine",
|
| 118 |
+
"trigger_position": "prepend"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"image": "https://huggingface.co/sWizad/pokemon-trainer-sprites-pixelart-flux/resolve/main/26578915.jpeg",
|
| 122 |
+
"repo": "sWizad/pokemon-trainer-sprites-pixelart-flux",
|
| 123 |
+
"title": "Pokemon Trainer Sprites",
|
| 124 |
+
"trigger_word": "white background, a pixel image of",
|
| 125 |
+
"trigger_position": "prepend"
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"image": "https://huggingface.co/nerijs/animation2k-flux/resolve/main/images/Q8-oVxNnXvZ9HNrgbNpGw_02762aaaba3b47859ee5fe9403a371e3.png",
|
| 129 |
+
"title": "animation2k",
|
| 130 |
+
"repo": "nerijs/animation2k-flux",
|
| 131 |
+
"trigger_word": ""
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"image":"https://huggingface.co/alvdansen/softserve_anime/resolve/main/images/ComfyUI_00062_.png",
|
| 135 |
+
"title":"SoftServe Anime",
|
| 136 |
+
"repo": "alvdansen/softserve_anime",
|
| 137 |
+
"trigger_word": ""
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"image": "https://huggingface.co/veryVANYA/ps1-style-flux/resolve/main/24439220.jpeg",
|
| 141 |
+
"title": "PS1 style",
|
| 142 |
+
"repo": "veryVANYA/ps1-style-flux",
|
| 143 |
+
"trigger_word": "ps1 game screenshot,",
|
| 144 |
+
"trigger_position": "prepend"
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
"image": "https://huggingface.co/alvdansen/flux-koda/resolve/main/images/ComfyUI_00566_%20(2).png",
|
| 148 |
+
"title": "flux koda",
|
| 149 |
+
"repo": "alvdansen/flux-koda",
|
| 150 |
+
"trigger_word": "flmft style"
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"image": "https://huggingface.co/alvdansen/frosting_lane_flux/resolve/main/images/content%20-%202024-08-11T005936.346.jpeg",
|
| 154 |
+
"title": "Frosting Lane Flux",
|
| 155 |
+
"repo": "alvdansen/frosting_lane_flux",
|
| 156 |
+
"trigger_word": ""
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
"image": "https://huggingface.co/davisbro/half_illustration/resolve/main/images/example3.webp",
|
| 160 |
+
"title": "Half Illustration",
|
| 161 |
+
"repo": "davisbro/half_illustration",
|
| 162 |
+
"trigger_word": "in the style of TOK"
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"image":"https://pbs.twimg.com/media/GVRiSH7WgAAnI4P?format=jpg&name=medium",
|
| 166 |
+
"title":"wrong",
|
| 167 |
+
"repo": "fofr/flux-wrong",
|
| 168 |
+
"trigger_word": "WRNG"
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"image":"https://huggingface.co/linoyts/yarn_art_Flux_LoRA/resolve/main/yarn_art_2.png",
|
| 172 |
+
"title":"Yarn Art",
|
| 173 |
+
"repo": "linoyts/yarn_art_Flux_LoRA",
|
| 174 |
+
"trigger_word": ", yarn art style"
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"image": "https://huggingface.co/Norod78/Flux_1_Dev_LoRA_Paper-Cutout-Style/resolve/main/08a19840b6214b76b0607b2f9d5a7e28_63159b9d98124c008efb1d36446a615c.png",
|
| 178 |
+
"title": "Paper Cutout",
|
| 179 |
+
"repo": "Norod78/Flux_1_Dev_LoRA_Paper-Cutout-Style",
|
| 180 |
+
"trigger_word": ", Paper Cutout Style"
|
| 181 |
+
},
|
| 182 |
+
{
|
| 183 |
+
"image": "https://huggingface.co/SebastianBodza/flux_lora_aquarel_watercolor/resolve/main/images/ascend.webp",
|
| 184 |
+
"title": "Aquarell Watercolor",
|
| 185 |
+
"repo": "SebastianBodza/Flux_Aquarell_Watercolor_v2",
|
| 186 |
+
"trigger_word": "in a watercolor style, AQUACOLTOK. White background."
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"image": "https://huggingface.co/dataautogpt3/FLUX-SyntheticAnime/resolve/main/assets/angel.png",
|
| 190 |
+
"title": "SyntheticAnime",
|
| 191 |
+
"repo": "dataautogpt3/FLUX-SyntheticAnime",
|
| 192 |
+
"trigger_word": "1980s anime screengrab, VHS quality"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_14.png?raw=true",
|
| 196 |
+
"title": "flux-anime",
|
| 197 |
+
"repo": "XLabs-AI/flux-lora-collection",
|
| 198 |
+
"weights": "anime_lora.safetensors",
|
| 199 |
+
"trigger_word": ", anime"
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"image": "https://replicate.delivery/yhqm/QD8Ioy5NExqSCtBS8hG04XIRQZFaC9pxJemINT1bibyjZfSTA/out-0.webp",
|
| 203 |
+
"title": "80s Cyberpunk",
|
| 204 |
+
"repo": "fofr/flux-80s-cyberpunk",
|
| 205 |
+
"trigger_word": "style of 80s cyberpunk",
|
| 206 |
+
"trigger_position": "prepend"
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"image": "https://huggingface.co/kudzueye/Boreal/resolve/main/images/ComfyUI_00845_.png",
|
| 210 |
+
"title": "Boreal",
|
| 211 |
+
"repo": "kudzueye/boreal-flux-dev-v2",
|
| 212 |
+
"trigger_word": "phone photo"
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_18.png?raw=true",
|
| 216 |
+
"title": "flux-disney",
|
| 217 |
+
"repo": "XLabs-AI/flux-lora-collection",
|
| 218 |
+
"weights": "disney_lora.safetensors",
|
| 219 |
+
"trigger_word": ", disney style"
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_23.png?raw=true",
|
| 223 |
+
"title": "flux-art",
|
| 224 |
+
"repo": "XLabs-AI/flux-lora-collection",
|
| 225 |
+
"weights": "art_lora.safetensors",
|
| 226 |
+
"trigger_word": ", art"
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"image": "https://huggingface.co/martintomov/retrofuturism-flux/resolve/main/images/2e40deba-858e-454f-ae1c-d1ba2adb6a65.jpeg",
|
| 230 |
+
"title": "Retrofuturism Flux",
|
| 231 |
+
"repo": "martintomov/retrofuturism-flux",
|
| 232 |
+
"trigger_word": ", retrofuturism"
|
| 233 |
+
}
|
| 234 |
+
]
|