Upload 4 files
Browse files
app.py
CHANGED
|
@@ -279,12 +279,31 @@ async def generate(request: GenerateRequest):
|
|
| 279 |
seed=seed,
|
| 280 |
)
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
else:
|
| 287 |
-
|
|
|
|
| 288 |
|
| 289 |
# Convert to base64
|
| 290 |
buffer = io.BytesIO()
|
|
|
|
| 279 |
seed=seed,
|
| 280 |
)
|
| 281 |
|
| 282 |
+
print(f"Output type: {type(output)}")
|
| 283 |
+
|
| 284 |
+
# Handle different output formats from stable-diffusion-cpp
|
| 285 |
+
if isinstance(output, list):
|
| 286 |
+
# Returns list of images, take first one
|
| 287 |
+
img_data = output[0]
|
| 288 |
+
else:
|
| 289 |
+
img_data = output
|
| 290 |
+
|
| 291 |
+
# Convert to PIL Image based on data type
|
| 292 |
+
if isinstance(img_data, bytes):
|
| 293 |
+
image = Image.open(io.BytesIO(img_data))
|
| 294 |
+
elif hasattr(img_data, 'data'):
|
| 295 |
+
# Raw pixel data
|
| 296 |
+
image = Image.frombytes('RGB', (width, height), img_data.data)
|
| 297 |
+
elif hasattr(img_data, 'tobytes'):
|
| 298 |
+
# NumPy array or similar
|
| 299 |
+
import numpy as np
|
| 300 |
+
arr = np.array(img_data)
|
| 301 |
+
image = Image.fromarray(arr.astype('uint8'))
|
| 302 |
+
elif isinstance(img_data, Image.Image):
|
| 303 |
+
image = img_data
|
| 304 |
else:
|
| 305 |
+
# Try direct conversion
|
| 306 |
+
image = Image.fromarray(img_data)
|
| 307 |
|
| 308 |
# Convert to base64
|
| 309 |
buffer = io.BytesIO()
|