Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,14 +39,14 @@ def generate_passover_coloring_pages(age):
|
|
| 39 |
],
|
| 40 |
"intermediate": [
|
| 41 |
"Jewish Seder table with symbolic foods",
|
| 42 |
-
"Hebrew letters spelling
|
| 43 |
"Israelites leaving Egypt scene",
|
| 44 |
"Four Sons from the Haggadah"
|
| 45 |
],
|
| 46 |
"advanced": [
|
| 47 |
"Haggadah page with Seder order",
|
| 48 |
"Miriam and women celebrating after Red Sea",
|
| 49 |
-
"Hebrew calligraphy
|
| 50 |
"Passover journey from slavery to freedom"
|
| 51 |
]
|
| 52 |
}
|
|
@@ -58,24 +58,19 @@ def generate_passover_coloring_pages(age):
|
|
| 58 |
temp_dir = os.path.join(IMAGES_DIR, f"temp_{timestamp}")
|
| 59 |
os.makedirs(temp_dir, exist_ok=True)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
font = ImageFont.truetype("Arial", 40)
|
| 64 |
-
small_font = ImageFont.truetype("Arial", 20)
|
| 65 |
-
except:
|
| 66 |
-
font = ImageFont.load_default()
|
| 67 |
-
small_font = ImageFont.load_default()
|
| 68 |
|
| 69 |
# Create a cover page
|
| 70 |
cover_img = Image.new('RGB', (2480, 3508), color='white') # A4 size at 300 DPI
|
| 71 |
draw = ImageDraw.Draw(cover_img)
|
| 72 |
|
| 73 |
-
# Add title to cover page
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
# Save cover page
|
| 81 |
cover_path = os.path.join(temp_dir, f"01_cover.png")
|
|
@@ -92,7 +87,7 @@ def generate_passover_coloring_pages(age):
|
|
| 92 |
draw.rectangle([(100, 100), (2380, 3408)], outline='black', width=4)
|
| 93 |
|
| 94 |
# Add title at the top
|
| 95 |
-
|
| 96 |
|
| 97 |
# Add a content area for the coloring image
|
| 98 |
draw.rectangle([(300, 400), (2180, 2800)], outline='black', width=2)
|
|
@@ -116,7 +111,7 @@ def generate_passover_coloring_pages(age):
|
|
| 116 |
sections = ["Karpas", "Charoset", "Maror", "Zeroa", "Beitzah", "Chazeret"]
|
| 117 |
positions = [(975, 1075), (1525, 1075), (975, 1625), (1525, 1625), (1250, 1075), (1250, 1625)]
|
| 118 |
for section, pos in zip(sections, positions):
|
| 119 |
-
|
| 120 |
|
| 121 |
elif "red sea" in description.lower():
|
| 122 |
# Draw the Red Sea
|
|
@@ -134,21 +129,24 @@ def generate_passover_coloring_pages(age):
|
|
| 134 |
draw.rectangle([(1050, 600), (1350, 2600)], outline='black', width=3)
|
| 135 |
|
| 136 |
elif "hebrew" in description.lower() and "pesach" in description.lower():
|
| 137 |
-
# Draw Hebrew
|
| 138 |
-
|
| 139 |
-
draw.
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
#
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# Add description
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
# Add footer
|
| 151 |
-
|
| 152 |
|
| 153 |
# Save with sequential numbering for proper PDF ordering
|
| 154 |
seq_num = i + 2 # Start from 2 after the cover page
|
|
@@ -297,6 +295,23 @@ def generate_passover_coloring_pages(age):
|
|
| 297 |
|
| 298 |
return html_path
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
if __name__ == "__main__":
|
| 301 |
print("===== Jewish Passover Coloring Pages Generator =====")
|
| 302 |
|
|
|
|
| 39 |
],
|
| 40 |
"intermediate": [
|
| 41 |
"Jewish Seder table with symbolic foods",
|
| 42 |
+
"Hebrew letters spelling Pesach",
|
| 43 |
"Israelites leaving Egypt scene",
|
| 44 |
"Four Sons from the Haggadah"
|
| 45 |
],
|
| 46 |
"advanced": [
|
| 47 |
"Haggadah page with Seder order",
|
| 48 |
"Miriam and women celebrating after Red Sea",
|
| 49 |
+
"Hebrew calligraphy Next year in Jerusalem",
|
| 50 |
"Passover journey from slavery to freedom"
|
| 51 |
]
|
| 52 |
}
|
|
|
|
| 58 |
temp_dir = os.path.join(IMAGES_DIR, f"temp_{timestamp}")
|
| 59 |
os.makedirs(temp_dir, exist_ok=True)
|
| 60 |
|
| 61 |
+
# Always use default font to avoid font loading issues
|
| 62 |
+
font = ImageFont.load_default()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# Create a cover page
|
| 65 |
cover_img = Image.new('RGB', (2480, 3508), color='white') # A4 size at 300 DPI
|
| 66 |
draw = ImageDraw.Draw(cover_img)
|
| 67 |
|
| 68 |
+
# Add title to cover page - using simple text placement
|
| 69 |
+
draw_centered_text(draw, "Jewish Passover (Pesach)", 1240, 800, font)
|
| 70 |
+
draw_centered_text(draw, "Coloring Pages", 1240, 1000, font)
|
| 71 |
+
draw_centered_text(draw, f"For Ages {age} Years", 1240, 1200, font)
|
| 72 |
+
draw_centered_text(draw, "Created for Jewish children and families", 1240, 1500, font)
|
| 73 |
+
draw_centered_text(draw, "to celebrate the story of Passover", 1240, 1600, font)
|
| 74 |
|
| 75 |
# Save cover page
|
| 76 |
cover_path = os.path.join(temp_dir, f"01_cover.png")
|
|
|
|
| 87 |
draw.rectangle([(100, 100), (2380, 3408)], outline='black', width=4)
|
| 88 |
|
| 89 |
# Add title at the top
|
| 90 |
+
draw_centered_text(draw, description, 1240, 200, font)
|
| 91 |
|
| 92 |
# Add a content area for the coloring image
|
| 93 |
draw.rectangle([(300, 400), (2180, 2800)], outline='black', width=2)
|
|
|
|
| 111 |
sections = ["Karpas", "Charoset", "Maror", "Zeroa", "Beitzah", "Chazeret"]
|
| 112 |
positions = [(975, 1075), (1525, 1075), (975, 1625), (1525, 1625), (1250, 1075), (1250, 1625)]
|
| 113 |
for section, pos in zip(sections, positions):
|
| 114 |
+
draw_centered_text(draw, section, pos[0], pos[1], font)
|
| 115 |
|
| 116 |
elif "red sea" in description.lower():
|
| 117 |
# Draw the Red Sea
|
|
|
|
| 129 |
draw.rectangle([(1050, 600), (1350, 2600)], outline='black', width=3)
|
| 130 |
|
| 131 |
elif "hebrew" in description.lower() and "pesach" in description.lower():
|
| 132 |
+
# Draw a simple symbol instead of Hebrew text to avoid font issues
|
| 133 |
+
draw.rectangle([(900, 1300), (1100, 1500)], outline='black', width=3)
|
| 134 |
+
draw.rectangle([(1200, 1300), (1400, 1500)], outline='black', width=3)
|
| 135 |
+
draw.rectangle([(1500, 1300), (1700, 1500)], outline='black', width=3)
|
| 136 |
+
|
| 137 |
+
# Add text labels
|
| 138 |
+
draw_centered_text(draw, "P", 1000, 1400, font)
|
| 139 |
+
draw_centered_text(draw, "E", 1300, 1400, font)
|
| 140 |
+
draw_centered_text(draw, "S", 1600, 1400, font)
|
| 141 |
+
draw_centered_text(draw, "PESACH", 1300, 1600, font)
|
| 142 |
|
| 143 |
# Add description
|
| 144 |
+
draw_centered_text(draw, description, 1240, 1600, font)
|
| 145 |
+
draw_centered_text(draw, "Jewish Passover Coloring Page", 1240, 1700, font)
|
| 146 |
+
draw_centered_text(draw, f"For age: {age}", 1240, 1800, font)
|
| 147 |
|
| 148 |
# Add footer
|
| 149 |
+
draw_centered_text(draw, f"Page {i+1} of {len(selected_pages)}", 1240, 3300, font)
|
| 150 |
|
| 151 |
# Save with sequential numbering for proper PDF ordering
|
| 152 |
seq_num = i + 2 # Start from 2 after the cover page
|
|
|
|
| 295 |
|
| 296 |
return html_path
|
| 297 |
|
| 298 |
+
# Helper function to draw centered text without relying on font-specific anchor points
|
| 299 |
+
def draw_centered_text(draw, text, x, y, font):
|
| 300 |
+
# Get the text size
|
| 301 |
+
try:
|
| 302 |
+
text_width, text_height = draw.textsize(text, font=font)
|
| 303 |
+
except:
|
| 304 |
+
# Estimate text size for older PIL versions or if textsize fails
|
| 305 |
+
text_width = len(text) * 7 # Rough estimate
|
| 306 |
+
text_height = 12
|
| 307 |
+
|
| 308 |
+
# Calculate position for centered text
|
| 309 |
+
text_x = x - (text_width // 2)
|
| 310 |
+
text_y = y - (text_height // 2)
|
| 311 |
+
|
| 312 |
+
# Draw the text
|
| 313 |
+
draw.text((text_x, text_y), text, fill='black', font=font)
|
| 314 |
+
|
| 315 |
if __name__ == "__main__":
|
| 316 |
print("===== Jewish Passover Coloring Pages Generator =====")
|
| 317 |
|