Spaces:
Running
on
Zero
Running
on
Zero
History v3
Browse files
app.py
CHANGED
@@ -154,32 +154,31 @@ def generate(
|
|
154 |
).images
|
155 |
|
156 |
if images:
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
for image in images:
|
179 |
filepath = utils.save_image(image, metadata, OUTPUT_DIR)
|
180 |
logger.info(f"Image saved as {filepath} with metadata")
|
181 |
|
182 |
-
return
|
183 |
|
184 |
except Exception as e:
|
185 |
logger.exception(f"An error occurred: {e}")
|
|
|
154 |
).images
|
155 |
|
156 |
if images:
|
157 |
+
image = images[0]
|
158 |
+
# Create thumbnail
|
159 |
+
thumbnail = image.copy()
|
160 |
+
thumbnail.thumbnail((256, 256))
|
161 |
+
|
162 |
+
# Convert thumbnail to base64
|
163 |
+
buffered = BytesIO()
|
164 |
+
thumbnail.save(buffered, format="PNG")
|
165 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
166 |
+
|
167 |
+
# Add to history
|
168 |
+
image_history.appendleft({
|
169 |
+
"thumbnail": f"data:image/png;base64,{img_str}",
|
170 |
+
"prompt": prompt,
|
171 |
+
"negative_prompt": negative_prompt,
|
172 |
+
"seed": seed,
|
173 |
+
"width": width,
|
174 |
+
"height": height,
|
175 |
+
})
|
176 |
+
|
177 |
+
if IS_COLAB:
|
|
|
178 |
filepath = utils.save_image(image, metadata, OUTPUT_DIR)
|
179 |
logger.info(f"Image saved as {filepath} with metadata")
|
180 |
|
181 |
+
return image, metadata, list(image_history)
|
182 |
|
183 |
except Exception as e:
|
184 |
logger.exception(f"An error occurred: {e}")
|