Spaces:
Running
on
Zero
Running
on
Zero
Fix: Include source input images in ZIP package
Browse files
app.py
CHANGED
|
@@ -292,14 +292,43 @@ def create_download_zip(
|
|
| 292 |
character_sheet: Image.Image,
|
| 293 |
stages: Dict[str, Any],
|
| 294 |
metadata: Dict[str, Any],
|
| 295 |
-
output_dir: Path
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
) -> Path:
|
| 297 |
-
"""Create a ZIP file with character sheet, individual views, and metadata JSON."""
|
| 298 |
safe_name = sanitize_filename(character_name)
|
| 299 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 300 |
zip_path = output_dir / f"{safe_name}_{timestamp}.zip"
|
| 301 |
|
| 302 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
# Add character sheet
|
| 304 |
sheet_path = output_dir / f"{safe_name}_character_sheet.png"
|
| 305 |
character_sheet.save(sheet_path)
|
|
@@ -543,13 +572,17 @@ def generate_character_sheet(
|
|
| 543 |
with open(json_path, 'w') as f:
|
| 544 |
json.dump(json_metadata, f, indent=2)
|
| 545 |
|
| 546 |
-
# Create ZIP file
|
| 547 |
zip_path = create_download_zip(
|
| 548 |
character_name=character_name or "Character",
|
| 549 |
character_sheet=character_sheet,
|
| 550 |
stages=stages,
|
| 551 |
metadata=json_metadata,
|
| 552 |
-
output_dir=OUTPUT_DIR
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
)
|
| 554 |
|
| 555 |
# Final yield with all outputs
|
|
|
|
| 292 |
character_sheet: Image.Image,
|
| 293 |
stages: Dict[str, Any],
|
| 294 |
metadata: Dict[str, Any],
|
| 295 |
+
output_dir: Path,
|
| 296 |
+
input_image: Optional[Image.Image] = None,
|
| 297 |
+
face_image: Optional[Image.Image] = None,
|
| 298 |
+
body_image: Optional[Image.Image] = None,
|
| 299 |
+
costume_image: Optional[Image.Image] = None
|
| 300 |
) -> Path:
|
| 301 |
+
"""Create a ZIP file with character sheet, individual views, source inputs, and metadata JSON."""
|
| 302 |
safe_name = sanitize_filename(character_name)
|
| 303 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 304 |
zip_path = output_dir / f"{safe_name}_{timestamp}.zip"
|
| 305 |
|
| 306 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 307 |
+
# Add source input image(s)
|
| 308 |
+
if input_image is not None:
|
| 309 |
+
input_path = output_dir / f"{safe_name}_input.png"
|
| 310 |
+
input_image.save(input_path)
|
| 311 |
+
zf.write(input_path, f"{safe_name}_input.png")
|
| 312 |
+
input_path.unlink()
|
| 313 |
+
|
| 314 |
+
if face_image is not None:
|
| 315 |
+
face_path = output_dir / f"{safe_name}_input_face.png"
|
| 316 |
+
face_image.save(face_path)
|
| 317 |
+
zf.write(face_path, f"{safe_name}_input_face.png")
|
| 318 |
+
face_path.unlink()
|
| 319 |
+
|
| 320 |
+
if body_image is not None:
|
| 321 |
+
body_path = output_dir / f"{safe_name}_input_body.png"
|
| 322 |
+
body_image.save(body_path)
|
| 323 |
+
zf.write(body_path, f"{safe_name}_input_body.png")
|
| 324 |
+
body_path.unlink()
|
| 325 |
+
|
| 326 |
+
if costume_image is not None:
|
| 327 |
+
costume_path = output_dir / f"{safe_name}_input_costume.png"
|
| 328 |
+
costume_image.save(costume_path)
|
| 329 |
+
zf.write(costume_path, f"{safe_name}_input_costume.png")
|
| 330 |
+
costume_path.unlink()
|
| 331 |
+
|
| 332 |
# Add character sheet
|
| 333 |
sheet_path = output_dir / f"{safe_name}_character_sheet.png"
|
| 334 |
character_sheet.save(sheet_path)
|
|
|
|
| 572 |
with open(json_path, 'w') as f:
|
| 573 |
json.dump(json_metadata, f, indent=2)
|
| 574 |
|
| 575 |
+
# Create ZIP file (includes source input images)
|
| 576 |
zip_path = create_download_zip(
|
| 577 |
character_name=character_name or "Character",
|
| 578 |
character_sheet=character_sheet,
|
| 579 |
stages=stages,
|
| 580 |
metadata=json_metadata,
|
| 581 |
+
output_dir=OUTPUT_DIR,
|
| 582 |
+
input_image=input_image,
|
| 583 |
+
face_image=face_image,
|
| 584 |
+
body_image=body_image,
|
| 585 |
+
costume_image=costume_image
|
| 586 |
)
|
| 587 |
|
| 588 |
# Final yield with all outputs
|