Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,14 @@ def infer(
|
|
| 34 |
height,
|
| 35 |
guidance_scale,
|
| 36 |
num_inference_steps,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
progress=gr.Progress(track_tqdm=True),
|
| 38 |
):
|
| 39 |
if randomize_seed:
|
|
@@ -42,7 +50,9 @@ def infer(
|
|
| 42 |
generator = torch.Generator().manual_seed(seed)
|
| 43 |
|
| 44 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
| 45 |
-
if (model_repo_id=="stable-diffusion-v1-5/stable-diffusion-v1-5"):
|
|
|
|
|
|
|
| 46 |
pipe = pipe.to(device)
|
| 47 |
|
| 48 |
image = pipe(
|
|
@@ -81,7 +91,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 81 |
show_label=True,
|
| 82 |
placeholder="Enter model",
|
| 83 |
)
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
with gr.Row():
|
|
@@ -92,7 +109,45 @@ with gr.Blocks(css=css) as demo:
|
|
| 92 |
placeholder="Enter your prompt",
|
| 93 |
container=False,
|
| 94 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 97 |
|
| 98 |
result = gr.Image(label="Result", show_label=False)
|
|
@@ -102,7 +157,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 102 |
label="Negative prompt",
|
| 103 |
max_lines=1,
|
| 104 |
placeholder="Enter a negative prompt",
|
| 105 |
-
visible=
|
| 106 |
)
|
| 107 |
|
| 108 |
seed = gr.Slider(
|
|
@@ -163,6 +218,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 163 |
height,
|
| 164 |
guidance_scale,
|
| 165 |
num_inference_steps,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
],
|
| 167 |
outputs=[result, seed],
|
| 168 |
)
|
|
|
|
| 34 |
height,
|
| 35 |
guidance_scale,
|
| 36 |
num_inference_steps,
|
| 37 |
+
lscale,
|
| 38 |
+
controlnet_enabled,
|
| 39 |
+
control_strength,
|
| 40 |
+
control_mode,
|
| 41 |
+
control_image,
|
| 42 |
+
ip_adapter_enabled,
|
| 43 |
+
ip_adapter_scale,
|
| 44 |
+
ip_adapter_image,
|
| 45 |
progress=gr.Progress(track_tqdm=True),
|
| 46 |
):
|
| 47 |
if randomize_seed:
|
|
|
|
| 50 |
generator = torch.Generator().manual_seed(seed)
|
| 51 |
|
| 52 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
| 53 |
+
if (model_repo_id=="stable-diffusion-v1-5/stable-diffusion-v1-5"):
|
| 54 |
+
pipe.unet = PeftModel.from_pretrained(pipe.unet,"um235/cartoon_cat_stickers")
|
| 55 |
+
pipe.scale_lora(lscale)
|
| 56 |
pipe = pipe.to(device)
|
| 57 |
|
| 58 |
image = pipe(
|
|
|
|
| 91 |
show_label=True,
|
| 92 |
placeholder="Enter model",
|
| 93 |
)
|
| 94 |
+
with gr.Row():
|
| 95 |
+
lscale = gr.Slider(
|
| 96 |
+
label="Lora scale",
|
| 97 |
+
minimum=0,
|
| 98 |
+
maximum=2,
|
| 99 |
+
step=0.05,
|
| 100 |
+
value=1, # Replace with defaults that work for your model
|
| 101 |
+
)
|
| 102 |
|
| 103 |
|
| 104 |
with gr.Row():
|
|
|
|
| 109 |
placeholder="Enter your prompt",
|
| 110 |
container=False,
|
| 111 |
)
|
| 112 |
+
with gr.Accordion("ControlNet Settings", open=False):
|
| 113 |
+
controlnet_enabled = gr.Checkbox(label="Enable ControlNet", value=False)
|
| 114 |
+
|
| 115 |
+
with gr.Row():
|
| 116 |
+
control_strength = gr.Slider(
|
| 117 |
+
label="ControlNet Strength",
|
| 118 |
+
minimum=0.0,
|
| 119 |
+
maximum=1.0,
|
| 120 |
+
step=0.05,
|
| 121 |
+
value=0.75,
|
| 122 |
+
visible=False,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
control_mode = gr.Dropdown(
|
| 126 |
+
label="ControlNet Mode",
|
| 127 |
+
choices=["edge_detection", "pose_estimation", "depth_estimation"],
|
| 128 |
+
value="edge_detection",
|
| 129 |
+
visible=False,
|
| 130 |
+
)
|
| 131 |
|
| 132 |
+
control_image = gr.Image(label="ControlNet Image", type="pil", visible=False)
|
| 133 |
+
|
| 134 |
+
with gr.Accordion("IP-Adapter Settings", open=False):
|
| 135 |
+
ip_adapter_enabled = gr.Checkbox(label="Enable IP-Adapter", value=False)
|
| 136 |
+
|
| 137 |
+
with gr.Row():
|
| 138 |
+
ip_adapter_scale = gr.Slider(
|
| 139 |
+
label="IP-Adapter Scale",
|
| 140 |
+
minimum=0.0,
|
| 141 |
+
maximum=2.0,
|
| 142 |
+
step=0.05,
|
| 143 |
+
value=1.0,
|
| 144 |
+
visible=False,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
ip_adapter_image = gr.Image(label="IP-Adapter Image", type="pil", visible=False)
|
| 148 |
+
|
| 149 |
+
with gr.Row():
|
| 150 |
+
|
| 151 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 152 |
|
| 153 |
result = gr.Image(label="Result", show_label=False)
|
|
|
|
| 157 |
label="Negative prompt",
|
| 158 |
max_lines=1,
|
| 159 |
placeholder="Enter a negative prompt",
|
| 160 |
+
visible=True,
|
| 161 |
)
|
| 162 |
|
| 163 |
seed = gr.Slider(
|
|
|
|
| 218 |
height,
|
| 219 |
guidance_scale,
|
| 220 |
num_inference_steps,
|
| 221 |
+
lscale,
|
| 222 |
+
controlnet_enabled,
|
| 223 |
+
control_strength,
|
| 224 |
+
control_mode,
|
| 225 |
+
control_image,
|
| 226 |
+
ip_adapter_enabled,
|
| 227 |
+
ip_adapter_scale,
|
| 228 |
+
ip_adapter_image,
|
| 229 |
],
|
| 230 |
outputs=[result, seed],
|
| 231 |
)
|