Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,7 +85,7 @@ def resize_image(image, resolution):
|
|
| 85 |
new_h = int(h * ratio)
|
| 86 |
return image.resize((new_w, new_h), Image.LANCZOS)
|
| 87 |
|
| 88 |
-
def text_to_image(text, size=72, position="
|
| 89 |
width, height = 1024, 576
|
| 90 |
image = Image.new("RGB", (width, height), "white")
|
| 91 |
draw = ImageDraw.Draw(image)
|
|
@@ -137,7 +137,7 @@ def text_to_image(text, size=72, position="middle-center"):
|
|
| 137 |
return image
|
| 138 |
|
| 139 |
@spaces.GPU
|
| 140 |
-
def infer_canny(prompt, text_for_image,
|
| 141 |
negative_prompt = "nsfw, facial shadows, low resolution, jpeg artifacts, blurry, bad quality, dark face, neon lights",
|
| 142 |
seed = 397886929,
|
| 143 |
randomize_seed = False,
|
|
@@ -155,7 +155,7 @@ def infer_canny(prompt, text_for_image,
|
|
| 155 |
generator = torch.Generator().manual_seed(seed)
|
| 156 |
|
| 157 |
# Generate text image
|
| 158 |
-
init_image = text_to_image(text_for_image)
|
| 159 |
init_image = resize_image(init_image, MAX_IMAGE_SIZE)
|
| 160 |
|
| 161 |
pipe = pipe_canny.to("cuda")
|
|
@@ -179,6 +179,16 @@ css = """
|
|
| 179 |
footer {
|
| 180 |
visibility: hidden;
|
| 181 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
"""
|
| 183 |
|
| 184 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
|
|
@@ -196,6 +206,28 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
|
|
| 196 |
placeholder="Enter text to be converted into an image",
|
| 197 |
lines=3
|
| 198 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
with gr.Accordion("Advanced Settings", open=False):
|
| 200 |
negative_prompt = gr.Textbox(
|
| 201 |
label="Negative prompt",
|
|
@@ -258,7 +290,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
|
|
| 258 |
|
| 259 |
canny_button.click(
|
| 260 |
fn = infer_canny,
|
| 261 |
-
inputs = [prompt, text_for_image, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
| 262 |
outputs = [result, seed_used]
|
| 263 |
)
|
| 264 |
|
|
|
|
| 85 |
new_h = int(h * ratio)
|
| 86 |
return image.resize((new_w, new_h), Image.LANCZOS)
|
| 87 |
|
| 88 |
+
def text_to_image(text, size=72, position="top-center"):
|
| 89 |
width, height = 1024, 576
|
| 90 |
image = Image.new("RGB", (width, height), "white")
|
| 91 |
draw = ImageDraw.Draw(image)
|
|
|
|
| 137 |
return image
|
| 138 |
|
| 139 |
@spaces.GPU
|
| 140 |
+
def infer_canny(prompt, text_for_image, text_position, font_size,
|
| 141 |
negative_prompt = "nsfw, facial shadows, low resolution, jpeg artifacts, blurry, bad quality, dark face, neon lights",
|
| 142 |
seed = 397886929,
|
| 143 |
randomize_seed = False,
|
|
|
|
| 155 |
generator = torch.Generator().manual_seed(seed)
|
| 156 |
|
| 157 |
# Generate text image
|
| 158 |
+
init_image = text_to_image(text_for_image, size=font_size, position=text_position)
|
| 159 |
init_image = resize_image(init_image, MAX_IMAGE_SIZE)
|
| 160 |
|
| 161 |
pipe = pipe_canny.to("cuda")
|
|
|
|
| 179 |
footer {
|
| 180 |
visibility: hidden;
|
| 181 |
}
|
| 182 |
+
.text-position-grid {
|
| 183 |
+
display: grid;
|
| 184 |
+
grid-template-columns: repeat(3, 1fr);
|
| 185 |
+
gap: 5px;
|
| 186 |
+
margin-bottom: 10px;
|
| 187 |
+
}
|
| 188 |
+
.text-position-grid button {
|
| 189 |
+
aspect-ratio: 1;
|
| 190 |
+
padding: 0;
|
| 191 |
+
}
|
| 192 |
"""
|
| 193 |
|
| 194 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
|
|
|
|
| 206 |
placeholder="Enter text to be converted into an image",
|
| 207 |
lines=3
|
| 208 |
)
|
| 209 |
+
with gr.Row():
|
| 210 |
+
with gr.Column():
|
| 211 |
+
gr.Markdown("Text Position")
|
| 212 |
+
with gr.Row(elem_classes="text-position-grid"):
|
| 213 |
+
text_positions = ["top-left", "top-center", "top-right",
|
| 214 |
+
"middle-left", "middle-center", "middle-right",
|
| 215 |
+
"bottom-left", "bottom-center", "bottom-right"]
|
| 216 |
+
text_position = gr.Radio(
|
| 217 |
+
choices=text_positions,
|
| 218 |
+
value="top-center",
|
| 219 |
+
label="",
|
| 220 |
+
show_label=False,
|
| 221 |
+
elem_classes="text-position-grid"
|
| 222 |
+
)
|
| 223 |
+
with gr.Column():
|
| 224 |
+
font_size = gr.Slider(
|
| 225 |
+
label="Font Size",
|
| 226 |
+
minimum=12,
|
| 227 |
+
maximum=144,
|
| 228 |
+
step=1,
|
| 229 |
+
value=72
|
| 230 |
+
)
|
| 231 |
with gr.Accordion("Advanced Settings", open=False):
|
| 232 |
negative_prompt = gr.Textbox(
|
| 233 |
label="Negative prompt",
|
|
|
|
| 290 |
|
| 291 |
canny_button.click(
|
| 292 |
fn = infer_canny,
|
| 293 |
+
inputs = [prompt, text_for_image, text_position, font_size, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
| 294 |
outputs = [result, seed_used]
|
| 295 |
)
|
| 296 |
|