Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,3 @@
|
|
| 1 |
-
#!/usr/bin/env python
|
| 2 |
-
#patch 1.0()
|
| 3 |
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
-
# of this software and associated documentation files (the "Software"), to deal
|
| 5 |
-
# in the Software without restriction, including without limitation the rights
|
| 6 |
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
-
# copies of the Software, and to permit persons to whom the Software is
|
| 8 |
-
# furnished to do so, subject to the following conditions:
|
| 9 |
-
#
|
| 10 |
-
# ...
|
| 11 |
import os
|
| 12 |
import random
|
| 13 |
import uuid
|
|
@@ -19,9 +9,18 @@ import spaces
|
|
| 19 |
import torch
|
| 20 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 21 |
|
| 22 |
-
DESCRIPTIONz= """## SDXL-LoRA-DLC β‘
|
| 23 |
"""
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def save_image(img):
|
| 26 |
unique_name = str(uuid.uuid4()) + ".png"
|
| 27 |
img.save(unique_name)
|
|
@@ -40,34 +39,36 @@ if not torch.cuda.is_available():
|
|
| 40 |
USE_TORCH_COMPILE = 0
|
| 41 |
ENABLE_CPU_OFFLOAD = 0
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
style_list = [
|
| 73 |
{
|
|
@@ -119,6 +120,7 @@ def generate(
|
|
| 119 |
randomize_seed: bool = False,
|
| 120 |
style_name: str = DEFAULT_STYLE_NAME,
|
| 121 |
lora_model: str = "Realism (face/character)π¦π»",
|
|
|
|
| 122 |
progress=gr.Progress(track_tqdm=True),
|
| 123 |
):
|
| 124 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
|
@@ -126,8 +128,9 @@ def generate(
|
|
| 126 |
positive_prompt, effective_negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 127 |
|
| 128 |
if not use_negative_prompt:
|
| 129 |
-
effective_negative_prompt = ""
|
| 130 |
|
|
|
|
| 131 |
model_name, weight_name, adapter_name = LORA_OPTIONS[lora_model]
|
| 132 |
pipe.set_adapters(adapter_name)
|
| 133 |
|
|
@@ -158,10 +161,9 @@ footer {
|
|
| 158 |
visibility: hidden
|
| 159 |
}
|
| 160 |
'''
|
|
|
|
| 161 |
def load_predefined_images():
|
| 162 |
-
|
| 163 |
predefined_images = [
|
| 164 |
-
|
| 165 |
"assets/1.png",
|
| 166 |
"assets/2.png",
|
| 167 |
"assets/3.png",
|
|
@@ -171,7 +173,6 @@ def load_predefined_images():
|
|
| 171 |
"assets/7.png",
|
| 172 |
"assets/8.png",
|
| 173 |
"assets/9.png",
|
| 174 |
-
|
| 175 |
]
|
| 176 |
return predefined_images
|
| 177 |
|
|
@@ -243,6 +244,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 243 |
label="Quality Style",
|
| 244 |
)
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
with gr.Row(visible=True):
|
| 247 |
model_choice = gr.Dropdown(
|
| 248 |
label="LoRA Selection",
|
|
@@ -283,15 +292,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 283 |
randomize_seed,
|
| 284 |
style_selection,
|
| 285 |
model_choice,
|
|
|
|
| 286 |
],
|
| 287 |
outputs=[result, seed],
|
| 288 |
api_name="run",
|
| 289 |
)
|
| 290 |
|
| 291 |
-
|
| 292 |
with gr.Column(scale=3):
|
| 293 |
gr.Markdown("### Image Gallery")
|
| 294 |
predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
|
| 295 |
-
|
| 296 |
if __name__ == "__main__":
|
| 297 |
demo.queue(max_size=30).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import random
|
| 3 |
import uuid
|
|
|
|
| 9 |
import torch
|
| 10 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 11 |
|
| 12 |
+
DESCRIPTIONz = """## SDXL-LoRA-DLC β‘
|
| 13 |
"""
|
| 14 |
|
| 15 |
+
# Define model options
|
| 16 |
+
MODEL_OPTIONS = {
|
| 17 |
+
"RealVisXL V4.0 Lightning": "SG161222/RealVisXL_V4.0_Lightning",
|
| 18 |
+
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Dictionary to cache pipelines
|
| 22 |
+
pipelines = {}
|
| 23 |
+
|
| 24 |
def save_image(img):
|
| 25 |
unique_name = str(uuid.uuid4()) + ".png"
|
| 26 |
img.save(unique_name)
|
|
|
|
| 39 |
USE_TORCH_COMPILE = 0
|
| 40 |
ENABLE_CPU_OFFLOAD = 0
|
| 41 |
|
| 42 |
+
# Define LoRA options
|
| 43 |
+
LORA_OPTIONS = {
|
| 44 |
+
"Realism (face/character)π¦π»": ("prithivMLmods/Canopus-Realism-LoRA", "Canopus-Realism-LoRA.safetensors", "rlms"),
|
| 45 |
+
"Pixar (art/toons)π": ("prithivMLmods/Canopus-Pixar-Art", "Canopus-Pixar-Art.safetensors", "pixar"),
|
| 46 |
+
"Photoshoot (camera/film)πΈ": ("prithivMLmods/Canopus-Photo-Shoot-Mini-LoRA", "Canopus-Photo-Shoot-Mini-LoRA.safetensors", "photo"),
|
| 47 |
+
"Clothing (hoodies/pant/shirts)π": ("prithivMLmods/Canopus-Clothing-Adp-LoRA", "Canopus-Dress-Clothing-LoRA.safetensors", "clth"),
|
| 48 |
+
"Interior Architecture (house/hotel)π ": ("prithivMLmods/Canopus-Interior-Architecture-0.1", "Canopus-Interior-Architecture-0.1Ξ΄.safetensors", "arch"),
|
| 49 |
+
"Fashion Product (wearing/usable)π": ("prithivMLmods/Canopus-Fashion-Product-Dilation", "Canopus-Fashion-Product-Dilation.safetensors", "fashion"),
|
| 50 |
+
"Minimalistic Image (minimal/detailed)ποΈ": ("prithivMLmods/Pegasi-Minimalist-Image-Style", "Pegasi-Minimalist-Image-Style.safetensors", "minimalist"),
|
| 51 |
+
"Modern Clothing (trend/new)π": ("prithivMLmods/Canopus-Modern-Clothing-Design", "Canopus-Modern-Clothing-Design.safetensors", "mdrnclth"),
|
| 52 |
+
"Animaliea (farm/wild)π«": ("prithivMLmods/Canopus-Animaliea-Artism", "Canopus-Animaliea-Artism.safetensors", "Animaliea"),
|
| 53 |
+
"Liquid Wallpaper (minimal/illustration)πΌοΈ": ("prithivMLmods/Canopus-Liquid-Wallpaper-Art", "Canopus-Liquid-Wallpaper-Minimalize-LoRA.safetensors", "liquid"),
|
| 54 |
+
"Canes Cars (realistic/futurecars)π": ("prithivMLmods/Canes-Cars-Model-LoRA", "Canes-Cars-Model-LoRA.safetensors", "car"),
|
| 55 |
+
"Pencil Art (characteristic/creative)βοΈ": ("prithivMLmods/Canopus-Pencil-Art-LoRA", "Canopus-Pencil-Art-LoRA.safetensors", "Pencil Art"),
|
| 56 |
+
"Art Minimalistic (paint/semireal)π¨": ("prithivMLmods/Canopus-Art-Medium-LoRA", "Canopus-Art-Medium-LoRA.safetensors", "mdm"),
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Function to load or retrieve a pipeline
|
| 60 |
+
def get_pipeline(model_name):
|
| 61 |
+
if model_name not in pipelines:
|
| 62 |
+
pipelines[model_name] = StableDiffusionXLPipeline.from_pretrained(
|
| 63 |
+
MODEL_OPTIONS[model_name],
|
| 64 |
+
torch_dtype=torch.float16,
|
| 65 |
+
use_safetensors=True,
|
| 66 |
+
)
|
| 67 |
+
pipelines[model_name].scheduler = EulerAncestralDiscreteScheduler.from_config(pipelines[model_name].scheduler.config)
|
| 68 |
+
for lora_model_name, lora_weight_name, lora_adapter_name in LORA_OPTIONS.values():
|
| 69 |
+
pipelines[model_name].load_lora_weights(lora_model_name, weight_name=lora_weight_name, adapter_name=lora_adapter_name)
|
| 70 |
+
pipelines[model_name].to("cuda")
|
| 71 |
+
return pipelines[model_name]
|
| 72 |
|
| 73 |
style_list = [
|
| 74 |
{
|
|
|
|
| 120 |
randomize_seed: bool = False,
|
| 121 |
style_name: str = DEFAULT_STYLE_NAME,
|
| 122 |
lora_model: str = "Realism (face/character)π¦π»",
|
| 123 |
+
base_model: str = "RealVisXL V4.0 Lightning",
|
| 124 |
progress=gr.Progress(track_tqdm=True),
|
| 125 |
):
|
| 126 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
|
|
|
| 128 |
positive_prompt, effective_negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 129 |
|
| 130 |
if not use_negative_prompt:
|
| 131 |
+
effective_negative_prompt = ""
|
| 132 |
|
| 133 |
+
pipe = get_pipeline(base_model)
|
| 134 |
model_name, weight_name, adapter_name = LORA_OPTIONS[lora_model]
|
| 135 |
pipe.set_adapters(adapter_name)
|
| 136 |
|
|
|
|
| 161 |
visibility: hidden
|
| 162 |
}
|
| 163 |
'''
|
| 164 |
+
|
| 165 |
def load_predefined_images():
|
|
|
|
| 166 |
predefined_images = [
|
|
|
|
| 167 |
"assets/1.png",
|
| 168 |
"assets/2.png",
|
| 169 |
"assets/3.png",
|
|
|
|
| 173 |
"assets/7.png",
|
| 174 |
"assets/8.png",
|
| 175 |
"assets/9.png",
|
|
|
|
| 176 |
]
|
| 177 |
return predefined_images
|
| 178 |
|
|
|
|
| 244 |
label="Quality Style",
|
| 245 |
)
|
| 246 |
|
| 247 |
+
# Add base model selection dropdown
|
| 248 |
+
with gr.Row():
|
| 249 |
+
base_model_choice = gr.Dropdown(
|
| 250 |
+
label="Base Model",
|
| 251 |
+
choices=list(MODEL_OPTIONS.keys()),
|
| 252 |
+
value="RealVisXL V4.0 Lightning",
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
with gr.Row(visible=True):
|
| 256 |
model_choice = gr.Dropdown(
|
| 257 |
label="LoRA Selection",
|
|
|
|
| 292 |
randomize_seed,
|
| 293 |
style_selection,
|
| 294 |
model_choice,
|
| 295 |
+
base_model_choice,
|
| 296 |
],
|
| 297 |
outputs=[result, seed],
|
| 298 |
api_name="run",
|
| 299 |
)
|
| 300 |
|
|
|
|
| 301 |
with gr.Column(scale=3):
|
| 302 |
gr.Markdown("### Image Gallery")
|
| 303 |
predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
|
| 304 |
+
|
| 305 |
if __name__ == "__main__":
|
| 306 |
demo.queue(max_size=30).launch()
|