RanM commited on
Commit
9d2d2d3
·
verified ·
1 Parent(s): be9bf09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
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
- return output
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
- image.save(buffered, format="JPEG")
22
- image_bytes = buffered.getvalue()
23
- return image_bytes
 
 
 
 
 
 
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: