Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,14 +13,20 @@ async def generate_image(prompt):
|
|
13 |
# Generate an image based on the prompt
|
14 |
output = await asyncio.to_thread(model, prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
15 |
print(f"Model output: {output}")
|
16 |
-
|
17 |
# Check if the model returned images
|
18 |
if isinstance(output.images, list) and len(output.images) > 0:
|
19 |
image = output.images[0]
|
20 |
buffered = BytesIO()
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
raise Exception("No images returned by the model.")
|
26 |
except Exception as e:
|
|
|
13 |
# Generate an image based on the prompt
|
14 |
output = await asyncio.to_thread(model, prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
15 |
print(f"Model output: {output}")
|
16 |
+
|
17 |
# Check if the model returned images
|
18 |
if isinstance(output.images, list) and len(output.images) > 0:
|
19 |
image = output.images[0]
|
20 |
buffered = BytesIO()
|
21 |
+
try:
|
22 |
+
image.save(buffered, format="JPEG")
|
23 |
+
image_bytes = buffered.getvalue()
|
24 |
+
# Verify the image bytes
|
25 |
+
print(f"Image bytes length: {len(image_bytes)}")
|
26 |
+
return image_bytes
|
27 |
+
except Exception as e:
|
28 |
+
print(f"Error saving image: {e}")
|
29 |
+
return None
|
30 |
else:
|
31 |
raise Exception("No images returned by the model.")
|
32 |
except Exception as e:
|