|
from PIL import Image |
|
import torch |
|
import numpy as np |
|
import tempfile |
|
import os |
|
import uuid |
|
|
|
|
|
def plot_and_save_agent_image(agent_image, save_path=None): |
|
|
|
pil_image = agent_image.to_raw() |
|
|
|
|
|
pil_image.show() |
|
|
|
|
|
if save_path: |
|
pil_image.save(save_path) |
|
print(f"Image saved to {save_path}") |
|
else: |
|
print("No save path provided. Image not saved.") |
|
|
|
|
|
def generate_prompts_for_object(object_name): |
|
prompts = { |
|
"past": f"Show an old version of a {object_name} from its early days.", |
|
"present": f"Show a {object_name} with from present with current features/design/technology.", |
|
"future": f"Show a futuristic version of a {object_name}, by predicting advanced features and futuristic design." |
|
} |
|
return prompts |
|
|
|
|
|
|
|
def generate_object_history(object_name): |
|
images = [] |
|
|
|
|
|
prompts = generate_prompts_for_object(object_name) |
|
|
|
|
|
for time_period, frame in prompts.items(): |
|
print(f"Generating {time_period} frame: {frame}") |
|
result = agent.run(frame) |
|
|
|
|
|
images.append(result.to_raw()) |
|
|
|
|
|
image_filename = f"{object_name}_{time_period}.png" |
|
plot_and_save_agent_image(result, save_path=image_filename) |
|
|
|
|
|
|
|
gif_path = f"{object_name}_evolution.gif" |
|
images[0].save( |
|
gif_path, |
|
save_all=True, |
|
append_images=images[1:], |
|
duration=1000, |
|
loop=0 |
|
) |
|
|
|
|
|
return images, gif_path |
|
|
|
|