Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,6 +59,18 @@ def append_to_history(image, prompt, seed, width, height, guidance_scale, steps,
|
|
| 59 |
if image is None:
|
| 60 |
return history
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Convert final image to bytes
|
| 63 |
buffered = BytesIO()
|
| 64 |
image.save(buffered, format="PNG")
|
|
|
|
| 59 |
if image is None:
|
| 60 |
return history
|
| 61 |
|
| 62 |
+
# Convert numpy array to PIL Image if needed
|
| 63 |
+
from PIL import Image
|
| 64 |
+
import numpy as np
|
| 65 |
+
|
| 66 |
+
if isinstance(image, np.ndarray):
|
| 67 |
+
# Convert from [0-255] to PIL Image
|
| 68 |
+
if image.dtype == np.uint8:
|
| 69 |
+
image = Image.fromarray(image)
|
| 70 |
+
# Convert from float [0-1] to PIL Image
|
| 71 |
+
else:
|
| 72 |
+
image = Image.fromarray((image * 255).astype(np.uint8))
|
| 73 |
+
|
| 74 |
# Convert final image to bytes
|
| 75 |
buffered = BytesIO()
|
| 76 |
image.save(buffered, format="PNG")
|