Spaces:
Running
on
Zero
Running
on
Zero
Julian Bilcke
commited on
Commit
·
5d5f3fd
1
Parent(s):
49465bb
up
Browse files- app.py +39 -3
- style_presets.yaml +14 -6
app.py
CHANGED
|
@@ -493,6 +493,14 @@ def create_single_page_pdf(images: List[Image.Image], layout_id: str, num_images
|
|
| 493 |
|
| 494 |
x_rel, y_rel, w_rel, h_rel = pos
|
| 495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
# Convert relative positions to absolute positions
|
| 497 |
# Note: In ReportLab, y=0 is at the bottom
|
| 498 |
x = x_rel * page_width
|
|
@@ -500,15 +508,38 @@ def create_single_page_pdf(images: List[Image.Image], layout_id: str, num_images
|
|
| 500 |
width = w_rel * page_width
|
| 501 |
height = h_rel * page_height
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
# Convert PIL image to format suitable for ReportLab
|
| 504 |
img_buffer = io.BytesIO()
|
| 505 |
# Save with good quality
|
| 506 |
image.save(img_buffer, format='JPEG', quality=95)
|
| 507 |
img_buffer.seek(0)
|
| 508 |
|
| 509 |
-
# Draw the image on the PDF
|
| 510 |
-
|
| 511 |
-
|
|
|
|
| 512 |
|
| 513 |
# Save the PDF
|
| 514 |
pdf.save()
|
|
@@ -713,6 +744,11 @@ def infer_single_auto(
|
|
| 713 |
true_cfg_scale=guidance_scale, # Use true_cfg_scale for this model
|
| 714 |
).images[0]
|
| 715 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
return image, seed
|
| 717 |
|
| 718 |
# Keep the old infer function for backward compatibility (simplified)
|
|
|
|
| 493 |
|
| 494 |
x_rel, y_rel, w_rel, h_rel = pos
|
| 495 |
|
| 496 |
+
# Reduce gaps - adjust positions to bring panels closer
|
| 497 |
+
# Add small padding (1% of page dimensions)
|
| 498 |
+
padding = 0.01
|
| 499 |
+
x_rel = x_rel * 0.95 + padding # Compress horizontally
|
| 500 |
+
y_rel = y_rel * 0.95 + padding # Compress vertically
|
| 501 |
+
w_rel = w_rel * 1.05 # Slightly increase width
|
| 502 |
+
h_rel = h_rel * 1.05 # Slightly increase height
|
| 503 |
+
|
| 504 |
# Convert relative positions to absolute positions
|
| 505 |
# Note: In ReportLab, y=0 is at the bottom
|
| 506 |
x = x_rel * page_width
|
|
|
|
| 508 |
width = w_rel * page_width
|
| 509 |
height = h_rel * page_height
|
| 510 |
|
| 511 |
+
# Calculate image aspect ratio and layout aspect ratio
|
| 512 |
+
img_aspect = image.width / image.height
|
| 513 |
+
layout_aspect = width / height
|
| 514 |
+
|
| 515 |
+
# Preserve aspect ratio while fitting in the allocated space
|
| 516 |
+
if img_aspect > layout_aspect:
|
| 517 |
+
# Image is wider than the layout space
|
| 518 |
+
new_height = width / img_aspect
|
| 519 |
+
y_offset = (height - new_height) / 2
|
| 520 |
+
actual_width = width
|
| 521 |
+
actual_height = new_height
|
| 522 |
+
actual_x = x
|
| 523 |
+
actual_y = y + y_offset
|
| 524 |
+
else:
|
| 525 |
+
# Image is taller than the layout space
|
| 526 |
+
new_width = height * img_aspect
|
| 527 |
+
x_offset = (width - new_width) / 2
|
| 528 |
+
actual_width = new_width
|
| 529 |
+
actual_height = height
|
| 530 |
+
actual_x = x + x_offset
|
| 531 |
+
actual_y = y
|
| 532 |
+
|
| 533 |
# Convert PIL image to format suitable for ReportLab
|
| 534 |
img_buffer = io.BytesIO()
|
| 535 |
# Save with good quality
|
| 536 |
image.save(img_buffer, format='JPEG', quality=95)
|
| 537 |
img_buffer.seek(0)
|
| 538 |
|
| 539 |
+
# Draw the image on the PDF preserving aspect ratio
|
| 540 |
+
pdf.drawImage(ImageReader(img_buffer), actual_x, actual_y,
|
| 541 |
+
width=actual_width, height=actual_height,
|
| 542 |
+
preserveAspectRatio=True, mask='auto')
|
| 543 |
|
| 544 |
# Save the PDF
|
| 545 |
pdf.save()
|
|
|
|
| 744 |
true_cfg_scale=guidance_scale, # Use true_cfg_scale for this model
|
| 745 |
).images[0]
|
| 746 |
|
| 747 |
+
# Convert to grayscale if using manga_no_color style
|
| 748 |
+
if style_preset == "manga_no_color":
|
| 749 |
+
# Convert to grayscale while preserving quality
|
| 750 |
+
image = image.convert('L').convert('RGB')
|
| 751 |
+
|
| 752 |
return image, seed
|
| 753 |
|
| 754 |
# Keep the old infer function for backward compatibility (simplified)
|
style_presets.yaml
CHANGED
|
@@ -19,13 +19,21 @@ presets:
|
|
| 19 |
prompt_suffix: ""
|
| 20 |
negative_prompt: ""
|
| 21 |
|
| 22 |
-
|
| 23 |
-
id: "
|
| 24 |
-
label: "Japanese Manga"
|
| 25 |
enabled: true
|
| 26 |
-
prompt_prefix: "grayscale, detailed drawing, japanese manga"
|
| 27 |
-
prompt_suffix: ""
|
| 28 |
-
negative_prompt: "franco-belgian comic, color album,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
nihonga:
|
| 31 |
id: "nihonga"
|
|
|
|
| 19 |
prompt_suffix: ""
|
| 20 |
negative_prompt: ""
|
| 21 |
|
| 22 |
+
manga_no_color:
|
| 23 |
+
id: "manga_no_color"
|
| 24 |
+
label: "Japanese Manga (No Color)"
|
| 25 |
enabled: true
|
| 26 |
+
prompt_prefix: "black and white, grayscale, detailed drawing, japanese manga, monochrome"
|
| 27 |
+
prompt_suffix: "high contrast, ink drawing, manga panel"
|
| 28 |
+
negative_prompt: "color, colored, franco-belgian comic, color album, american comic, photo, painting, 3D render, chromatic, colorful, rainbow"
|
| 29 |
+
|
| 30 |
+
manga_few_colors:
|
| 31 |
+
id: "manga_few_colors"
|
| 32 |
+
label: "Japanese Manga (Few Colors)"
|
| 33 |
+
enabled: true
|
| 34 |
+
prompt_prefix: "detailed drawing, japanese manga, limited color palette"
|
| 35 |
+
prompt_suffix: "manga style, subtle colors"
|
| 36 |
+
negative_prompt: "franco-belgian comic, american comic, photo, painting, 3D render, oversaturated"
|
| 37 |
|
| 38 |
nihonga:
|
| 39 |
id: "nihonga"
|