File size: 781 Bytes
55159ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Utility functions
"""
import os
from pathlib import Path


def ensure_directories():
    """Create necessary directories"""
    dirs = ["outputs", "models", "/tmp/huggingface"]
    for d in dirs:
        Path(d).mkdir(parents=True, exist_ok=True)


def save_image_with_metadata(image, metadata, output_dir="outputs"):
    """Save image and metadata file"""
    import json
    from datetime import datetime

    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    seed = metadata.get("seed", "unknown")

    img_path = os.path.join(output_dir, f"art_{timestamp}_{seed}.png")
    meta_path = os.path.join(output_dir, f"art_{timestamp}_{seed}.json")

    image.save(img_path)
    with open(meta_path, "w") as f:
        json.dump(metadata, f, indent=2)

    return img_path