File size: 1,330 Bytes
3369069
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
import os
import random
from datetime import datetime
from PIL import Image
import matplotlib.pyplot as plt

# ๐Ÿ“ฆ Resize + convert image
def resize_image(image, size=(512, 512)):
    return image.convert("RGB").resize(size)

# ๐Ÿ“‚ Save output with timestamp
def save_output(image, save_dir="output", prefix="stylized"):
    os.makedirs(save_dir, exist_ok=True)
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"{prefix}_{timestamp}.jpg"
    path = os.path.join(save_dir, filename)
    image.save(path)
    return path

# ๐Ÿ“œ Log content + style pairing
def log_run(content_name, style_name, log_path="log.txt"):
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    line = f"{timestamp} | Content: {content_name} + Style: {style_name} = Stylized\n"
    with open(log_path, "a") as f:
        f.write(line)

# ๐Ÿ–ผ๏ธ Triptych visualizer: A + B = C
def show_triptych(content_img, style_img, output_img):
    fig, axs = plt.subplots(1, 3, figsize=(15, 5))
    axs[0].imshow(content_img); axs[0].set_title("A: Content"); axs[0].axis('off')
    axs[1].imshow(style_img);  axs[1].set_title("B: Style");   axs[1].axis('off')
    axs[2].imshow(output_img); axs[2].set_title("C: Output");  axs[2].axis('off')
    plt.suptitle("A + B = C", fontsize=20)
    plt.show()