Update app.py
Browse files
app.py
CHANGED
@@ -87,6 +87,8 @@ agent = CodeAgent(tools=[image_generation_tool, search_tool], model=llm_engine)
|
|
87 |
# Main logic for image generation
|
88 |
# =========================================================
|
89 |
|
|
|
|
|
90 |
def generate_object_history(object_name):
|
91 |
images = []
|
92 |
prompts = generate_prompts_for_object(object_name)
|
@@ -106,26 +108,37 @@ def generate_object_history(object_name):
|
|
106 |
additional_args={"user_prompt": prompt}
|
107 |
)
|
108 |
|
|
|
109 |
if isinstance(result, (list, tuple)):
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
image
|
113 |
image_filename = f"{object_name}_{time_period}.png"
|
114 |
image.save(image_filename)
|
|
|
|
|
115 |
plot_and_save_agent_image(image, f"{object_name} - {time_period.title()}", save_path=image_filename)
|
116 |
|
117 |
image_paths.append(image_filename)
|
118 |
images.append(image)
|
|
|
119 |
except Exception as e:
|
120 |
print(f"Agent failed on {time_period}: {e}")
|
121 |
continue
|
122 |
|
|
|
123 |
gif_path = f"{object_name}_evolution.gif"
|
124 |
if images:
|
125 |
images[0].save(gif_path, save_all=True, append_images=images[1:], duration=1000, loop=0)
|
126 |
|
127 |
return image_paths, gif_path
|
128 |
|
|
|
129 |
# =========================================================
|
130 |
# Gradio Interface
|
131 |
# =========================================================
|
|
|
87 |
# Main logic for image generation
|
88 |
# =========================================================
|
89 |
|
90 |
+
from PIL import Image
|
91 |
+
|
92 |
def generate_object_history(object_name):
|
93 |
images = []
|
94 |
prompts = generate_prompts_for_object(object_name)
|
|
|
108 |
additional_args={"user_prompt": prompt}
|
109 |
)
|
110 |
|
111 |
+
# result is tuple: (filepath, seed)
|
112 |
if isinstance(result, (list, tuple)):
|
113 |
+
image_filepath = result[0]
|
114 |
+
else:
|
115 |
+
image_filepath = result # fallback in case result is just a string
|
116 |
+
|
117 |
+
# Open the image from filepath
|
118 |
+
image = Image.open(image_filepath)
|
119 |
|
120 |
+
# Save the image to your naming convention
|
121 |
image_filename = f"{object_name}_{time_period}.png"
|
122 |
image.save(image_filename)
|
123 |
+
|
124 |
+
# Optional: call your plotting function (if needed)
|
125 |
plot_and_save_agent_image(image, f"{object_name} - {time_period.title()}", save_path=image_filename)
|
126 |
|
127 |
image_paths.append(image_filename)
|
128 |
images.append(image)
|
129 |
+
|
130 |
except Exception as e:
|
131 |
print(f"Agent failed on {time_period}: {e}")
|
132 |
continue
|
133 |
|
134 |
+
# Create GIF from generated images if any
|
135 |
gif_path = f"{object_name}_evolution.gif"
|
136 |
if images:
|
137 |
images[0].save(gif_path, save_all=True, append_images=images[1:], duration=1000, loop=0)
|
138 |
|
139 |
return image_paths, gif_path
|
140 |
|
141 |
+
|
142 |
# =========================================================
|
143 |
# Gradio Interface
|
144 |
# =========================================================
|