Spaces:
Runtime error
Runtime error
Asko Relas commited on
Commit Β·
4f87138
1
Parent(s): c6b7d5e
UI controls
Browse files
app.py
CHANGED
|
@@ -37,7 +37,6 @@ MODELS = {
|
|
| 37 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
| 38 |
"Playground v2.5": "playgroundai/playground-v2.5-1024px-aesthetic",
|
| 39 |
"Juggernaut XL Lightning": "RunDiffusion/Juggernaut-XL-Lightning",
|
| 40 |
-
"LEOSAM HelloWorld XL": "Leosam/HelloWorld-SDXL-Lightning",
|
| 41 |
}
|
| 42 |
|
| 43 |
DEFAULT_MODEL = "DreamShaper XL Turbo"
|
|
@@ -65,15 +64,27 @@ def load_pipeline(model_name):
|
|
| 65 |
|
| 66 |
current_model = DEFAULT_MODEL
|
| 67 |
pipe = load_pipeline(current_model)
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
@spaces.GPU(duration=24)
|
| 71 |
-
def fill_image(prompt, negative_prompt, image, model_selection, paste_back):
|
| 72 |
-
global pipe, current_model
|
| 73 |
|
| 74 |
if model_selection != current_model:
|
| 75 |
pipe = load_pipeline(model_selection)
|
| 76 |
current_model = model_selection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
(
|
| 79 |
prompt_embeds,
|
|
@@ -98,8 +109,8 @@ def fill_image(prompt, negative_prompt, image, model_selection, paste_back):
|
|
| 98 |
control_image=[cnet_image],
|
| 99 |
controlnet_conditioning_scale=[1.0],
|
| 100 |
control_mode=[7],
|
| 101 |
-
num_inference_steps=
|
| 102 |
-
guidance_scale=
|
| 103 |
callback_on_step_end=callback_cfg_cutoff,
|
| 104 |
callback_on_step_end_tensor_inputs=[
|
| 105 |
"prompt_embeds",
|
|
@@ -149,6 +160,13 @@ with gr.Blocks() as demo:
|
|
| 149 |
with gr.Column():
|
| 150 |
paste_back = gr.Checkbox(True, label="Paste back original")
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
with gr.Row():
|
| 153 |
input_image = gr.ImageMask(
|
| 154 |
type="pil",
|
|
@@ -182,7 +200,7 @@ with gr.Blocks() as demo:
|
|
| 182 |
outputs=use_as_input_button,
|
| 183 |
).then(
|
| 184 |
fn=fill_image,
|
| 185 |
-
inputs=[prompt, negative_prompt, input_image, model_selection, paste_back],
|
| 186 |
outputs=result,
|
| 187 |
).then(
|
| 188 |
fn=lambda: gr.update(visible=True),
|
|
@@ -200,7 +218,7 @@ with gr.Blocks() as demo:
|
|
| 200 |
outputs=use_as_input_button,
|
| 201 |
).then(
|
| 202 |
fn=fill_image,
|
| 203 |
-
inputs=[prompt, negative_prompt, input_image, model_selection, paste_back],
|
| 204 |
outputs=result,
|
| 205 |
).then(
|
| 206 |
fn=lambda: gr.update(visible=True),
|
|
|
|
| 37 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
| 38 |
"Playground v2.5": "playgroundai/playground-v2.5-1024px-aesthetic",
|
| 39 |
"Juggernaut XL Lightning": "RunDiffusion/Juggernaut-XL-Lightning",
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
DEFAULT_MODEL = "DreamShaper XL Turbo"
|
|
|
|
| 64 |
|
| 65 |
current_model = DEFAULT_MODEL
|
| 66 |
pipe = load_pipeline(current_model)
|
| 67 |
+
lora_loaded = False
|
| 68 |
|
| 69 |
|
| 70 |
@spaces.GPU(duration=24)
|
| 71 |
+
def fill_image(prompt, negative_prompt, image, model_selection, paste_back, guidance_scale, num_steps, use_detail_lora, detail_lora_weight):
|
| 72 |
+
global pipe, current_model, lora_loaded
|
| 73 |
|
| 74 |
if model_selection != current_model:
|
| 75 |
pipe = load_pipeline(model_selection)
|
| 76 |
current_model = model_selection
|
| 77 |
+
lora_loaded = False
|
| 78 |
+
|
| 79 |
+
if use_detail_lora and not lora_loaded:
|
| 80 |
+
pipe.load_lora_weights("LyliaEngine/add-detail-xl", adapter_name="add-detail-xl")
|
| 81 |
+
lora_loaded = True
|
| 82 |
+
|
| 83 |
+
if lora_loaded:
|
| 84 |
+
if use_detail_lora:
|
| 85 |
+
pipe.set_adapters(["add-detail-xl"], adapter_weights=[detail_lora_weight])
|
| 86 |
+
else:
|
| 87 |
+
pipe.set_adapters(["add-detail-xl"], adapter_weights=[0.0])
|
| 88 |
|
| 89 |
(
|
| 90 |
prompt_embeds,
|
|
|
|
| 109 |
control_image=[cnet_image],
|
| 110 |
controlnet_conditioning_scale=[1.0],
|
| 111 |
control_mode=[7],
|
| 112 |
+
num_inference_steps=int(num_steps),
|
| 113 |
+
guidance_scale=guidance_scale,
|
| 114 |
callback_on_step_end=callback_cfg_cutoff,
|
| 115 |
callback_on_step_end_tensor_inputs=[
|
| 116 |
"prompt_embeds",
|
|
|
|
| 160 |
with gr.Column():
|
| 161 |
paste_back = gr.Checkbox(True, label="Paste back original")
|
| 162 |
|
| 163 |
+
with gr.Row():
|
| 164 |
+
guidance_scale = gr.Slider(minimum=0.0, maximum=10.0, value=1.5, step=0.1, label="Guidance Scale")
|
| 165 |
+
num_steps = gr.Slider(minimum=1, maximum=50, value=8, step=1, label="Number of Steps")
|
| 166 |
+
with gr.Row():
|
| 167 |
+
use_detail_lora = gr.Checkbox(False, label="Add Detail XL LoRA")
|
| 168 |
+
detail_lora_weight = gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Detail LoRA Weight")
|
| 169 |
+
|
| 170 |
with gr.Row():
|
| 171 |
input_image = gr.ImageMask(
|
| 172 |
type="pil",
|
|
|
|
| 200 |
outputs=use_as_input_button,
|
| 201 |
).then(
|
| 202 |
fn=fill_image,
|
| 203 |
+
inputs=[prompt, negative_prompt, input_image, model_selection, paste_back, guidance_scale, num_steps, use_detail_lora, detail_lora_weight],
|
| 204 |
outputs=result,
|
| 205 |
).then(
|
| 206 |
fn=lambda: gr.update(visible=True),
|
|
|
|
| 218 |
outputs=use_as_input_button,
|
| 219 |
).then(
|
| 220 |
fn=fill_image,
|
| 221 |
+
inputs=[prompt, negative_prompt, input_image, model_selection, paste_back, guidance_scale, num_steps, use_detail_lora, detail_lora_weight],
|
| 222 |
outputs=result,
|
| 223 |
).then(
|
| 224 |
fn=lambda: gr.update(visible=True),
|