Spaces:
Runtime error
Runtime error
zeel sheladiya commited on
Commit Β·
71185cb
1
Parent(s): 8dd266f
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,6 @@ import io
|
|
| 9 |
import os
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
-
# Added the test which has been completed
|
| 13 |
from diffusers import (
|
| 14 |
StableDiffusionPipeline,
|
| 15 |
StableDiffusionControlNetImg2ImgPipeline,
|
|
@@ -62,21 +61,20 @@ SAMPLER_MAP = {
|
|
| 62 |
"DEIS": lambda config: DEISMultistepScheduler.from_config(config),
|
| 63 |
}
|
| 64 |
|
| 65 |
-
guidance_scale: float = 7.5
|
| 66 |
-
controlnet_conditioning_scale: float = 1.3
|
| 67 |
-
strength: float = 0.9
|
| 68 |
-
seed: int = 5392011833
|
| 69 |
-
init_image: Image.Image
|
| 70 |
-
qrcode_image: Image.Image
|
| 71 |
-
use_qr_code_as_init_image = True
|
| 72 |
-
|
| 73 |
|
| 74 |
def inference(
|
| 75 |
qr_code_content: str,
|
| 76 |
prompt: str,
|
| 77 |
negative_prompt: str,
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
if prompt is None or prompt == "":
|
| 81 |
raise gr.Error("Prompt is required")
|
| 82 |
|
|
@@ -122,7 +120,7 @@ def inference(
|
|
| 122 |
)
|
| 123 |
return out.images[0] # type: ignore
|
| 124 |
|
| 125 |
-
|
| 126 |
with gr.Blocks() as blocks:
|
| 127 |
gr.Markdown(
|
| 128 |
"""
|
|
@@ -131,6 +129,12 @@ with gr.Blocks() as blocks:
|
|
| 131 |
We use the QR code image as the initial image **and** the control image, which allows you to generate
|
| 132 |
QR Codes that blend in **very naturally** with your provided prompt.
|
| 133 |
The strength parameter defines how much noise is added to your QR code and the noisy QR code is then guided towards both your prompt and the QR code image via Controlnet.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
"""
|
| 135 |
)
|
| 136 |
|
|
@@ -155,6 +159,7 @@ The strength parameter defines how much noise is added to your QR code and the n
|
|
| 155 |
label="Negative Prompt",
|
| 156 |
value="ugly, disfigured, low quality, blurry, nsfw",
|
| 157 |
)
|
|
|
|
| 158 |
|
| 159 |
with gr.Accordion(label="Init Images (Optional)", open=False, visible=False) as init_image_acc:
|
| 160 |
init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
|
|
@@ -164,14 +169,36 @@ The strength parameter defines how much noise is added to your QR code and the n
|
|
| 164 |
label="Params: The generated QR Code functionality is largely influenced by the parameters detailed below",
|
| 165 |
open=True,
|
| 166 |
):
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
sampler = gr.Dropdown(choices=list(SAMPLER_MAP.keys()), value="DPM++ Karras SDE", label="Sampler")
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
with gr.Row():
|
| 171 |
run_btn = gr.Button("Run")
|
| 172 |
with gr.Column():
|
| 173 |
result_image = gr.Image(label="Result Image")
|
| 174 |
-
|
| 175 |
run_btn.click(
|
| 176 |
inference,
|
| 177 |
inputs=[
|
|
@@ -196,18 +223,39 @@ The strength parameter defines how much noise is added to your QR code and the n
|
|
| 196 |
"https://huggingface.co/",
|
| 197 |
"A sky view of a colorful lakes and rivers flowing through the desert",
|
| 198 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
"DPM++ Karras SDE",
|
| 200 |
],
|
| 201 |
[
|
| 202 |
"https://huggingface.co/",
|
| 203 |
"Bright sunshine coming through the cracks of a wet, cave wall of big rocks",
|
| 204 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
"DPM++ Karras SDE",
|
| 206 |
],
|
| 207 |
[
|
| 208 |
"https://huggingface.co/",
|
| 209 |
"Sky view of highly aesthetic, ancient greek thermal baths in beautiful nature",
|
| 210 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
"DPM++ Karras SDE",
|
| 212 |
],
|
| 213 |
],
|
|
@@ -216,6 +264,13 @@ The strength parameter defines how much noise is added to your QR code and the n
|
|
| 216 |
qr_code_content,
|
| 217 |
prompt,
|
| 218 |
negative_prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
sampler,
|
| 220 |
],
|
| 221 |
outputs=[result_image],
|
|
|
|
| 9 |
import os
|
| 10 |
from PIL import Image
|
| 11 |
|
|
|
|
| 12 |
from diffusers import (
|
| 13 |
StableDiffusionPipeline,
|
| 14 |
StableDiffusionControlNetImg2ImgPipeline,
|
|
|
|
| 61 |
"DEIS": lambda config: DEISMultistepScheduler.from_config(config),
|
| 62 |
}
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def inference(
|
| 66 |
qr_code_content: str,
|
| 67 |
prompt: str,
|
| 68 |
negative_prompt: str,
|
| 69 |
+
guidance_scale: float = 10.0,
|
| 70 |
+
controlnet_conditioning_scale: float = 2.0,
|
| 71 |
+
strength: float = 0.8,
|
| 72 |
+
seed: int = -1,
|
| 73 |
+
init_image: Image.Image | None = None,
|
| 74 |
+
qrcode_image: Image.Image | None = None,
|
| 75 |
+
use_qr_code_as_init_image = True,
|
| 76 |
+
sampler = "DPM++ Karras SDE",
|
| 77 |
+
):
|
| 78 |
if prompt is None or prompt == "":
|
| 79 |
raise gr.Error("Prompt is required")
|
| 80 |
|
|
|
|
| 120 |
)
|
| 121 |
return out.images[0] # type: ignore
|
| 122 |
|
| 123 |
+
|
| 124 |
with gr.Blocks() as blocks:
|
| 125 |
gr.Markdown(
|
| 126 |
"""
|
|
|
|
| 129 |
We use the QR code image as the initial image **and** the control image, which allows you to generate
|
| 130 |
QR Codes that blend in **very naturally** with your provided prompt.
|
| 131 |
The strength parameter defines how much noise is added to your QR code and the noisy QR code is then guided towards both your prompt and the QR code image via Controlnet.
|
| 132 |
+
Use a high strength value between 0.8 and 0.95 and choose a conditioning scale between 0.6 and 2.0.
|
| 133 |
+
This mode arguably achieves the asthetically most appealing QR code images, but also requires more tuning of the controlnet conditioning scale and the strength value. If the generated image
|
| 134 |
+
looks way to much like the original QR code, make sure to gently increase the *strength* value and reduce the *conditioning* scale. Also check out the examples below.
|
| 135 |
+
model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
| 136 |
+
<a href="https://huggingface.co/spaces/huggingface-projects/QR-code-AI-art-generator?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
|
| 137 |
+
<img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a> for no queue on your own hardware.</p>
|
| 138 |
"""
|
| 139 |
)
|
| 140 |
|
|
|
|
| 159 |
label="Negative Prompt",
|
| 160 |
value="ugly, disfigured, low quality, blurry, nsfw",
|
| 161 |
)
|
| 162 |
+
use_qr_code_as_init_image = gr.Checkbox(label="Use QR code as init image", value=True, interactive=False, info="Whether init image should be QR code. Unclick to pass init image or generate init image with Stable Diffusion 2.1")
|
| 163 |
|
| 164 |
with gr.Accordion(label="Init Images (Optional)", open=False, visible=False) as init_image_acc:
|
| 165 |
init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
|
|
|
|
| 169 |
label="Params: The generated QR Code functionality is largely influenced by the parameters detailed below",
|
| 170 |
open=True,
|
| 171 |
):
|
| 172 |
+
controlnet_conditioning_scale = gr.Slider(
|
| 173 |
+
minimum=0.0,
|
| 174 |
+
maximum=5.0,
|
| 175 |
+
step=0.01,
|
| 176 |
+
value=1.1,
|
| 177 |
+
label="Controlnet Conditioning Scale",
|
| 178 |
+
)
|
| 179 |
+
strength = gr.Slider(
|
| 180 |
+
minimum=0.0, maximum=1.0, step=0.01, value=0.9, label="Strength"
|
| 181 |
+
)
|
| 182 |
+
guidance_scale = gr.Slider(
|
| 183 |
+
minimum=0.0,
|
| 184 |
+
maximum=50.0,
|
| 185 |
+
step=0.25,
|
| 186 |
+
value=7.5,
|
| 187 |
+
label="Guidance Scale",
|
| 188 |
+
)
|
| 189 |
sampler = gr.Dropdown(choices=list(SAMPLER_MAP.keys()), value="DPM++ Karras SDE", label="Sampler")
|
| 190 |
+
seed = gr.Slider(
|
| 191 |
+
minimum=-1,
|
| 192 |
+
maximum=9999999999,
|
| 193 |
+
step=1,
|
| 194 |
+
value=2313123,
|
| 195 |
+
label="Seed",
|
| 196 |
+
randomize=True,
|
| 197 |
+
)
|
| 198 |
with gr.Row():
|
| 199 |
run_btn = gr.Button("Run")
|
| 200 |
with gr.Column():
|
| 201 |
result_image = gr.Image(label="Result Image")
|
|
|
|
| 202 |
run_btn.click(
|
| 203 |
inference,
|
| 204 |
inputs=[
|
|
|
|
| 223 |
"https://huggingface.co/",
|
| 224 |
"A sky view of a colorful lakes and rivers flowing through the desert",
|
| 225 |
"ugly, disfigured, low quality, blurry, nsfw",
|
| 226 |
+
7.5,
|
| 227 |
+
1.3,
|
| 228 |
+
0.9,
|
| 229 |
+
5392011833,
|
| 230 |
+
None,
|
| 231 |
+
None,
|
| 232 |
+
True,
|
| 233 |
"DPM++ Karras SDE",
|
| 234 |
],
|
| 235 |
[
|
| 236 |
"https://huggingface.co/",
|
| 237 |
"Bright sunshine coming through the cracks of a wet, cave wall of big rocks",
|
| 238 |
"ugly, disfigured, low quality, blurry, nsfw",
|
| 239 |
+
7.5,
|
| 240 |
+
1.11,
|
| 241 |
+
0.9,
|
| 242 |
+
2523992465,
|
| 243 |
+
None,
|
| 244 |
+
None,
|
| 245 |
+
True,
|
| 246 |
"DPM++ Karras SDE",
|
| 247 |
],
|
| 248 |
[
|
| 249 |
"https://huggingface.co/",
|
| 250 |
"Sky view of highly aesthetic, ancient greek thermal baths in beautiful nature",
|
| 251 |
"ugly, disfigured, low quality, blurry, nsfw",
|
| 252 |
+
7.5,
|
| 253 |
+
1.5,
|
| 254 |
+
0.9,
|
| 255 |
+
2523992465,
|
| 256 |
+
None,
|
| 257 |
+
None,
|
| 258 |
+
True,
|
| 259 |
"DPM++ Karras SDE",
|
| 260 |
],
|
| 261 |
],
|
|
|
|
| 264 |
qr_code_content,
|
| 265 |
prompt,
|
| 266 |
negative_prompt,
|
| 267 |
+
guidance_scale,
|
| 268 |
+
controlnet_conditioning_scale,
|
| 269 |
+
strength,
|
| 270 |
+
seed,
|
| 271 |
+
init_image,
|
| 272 |
+
qr_code_image,
|
| 273 |
+
use_qr_code_as_init_image,
|
| 274 |
sampler,
|
| 275 |
],
|
| 276 |
outputs=[result_image],
|