c1tr0n75 commited on
Commit
338edf6
·
1 Parent(s): 96813ce

feat: Convert `google.genai.types.Image` to `PIL.Image` for Gradio display using `io.BytesIO`.

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -117,7 +117,18 @@ The output must be a single image that looks like the completed infographic, mai
117
  # Extract and return the generated image
118
  for part in response.parts:
119
  if image := part.as_image():
120
- return image
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  raise gr.Error("The model completed but did not return an image. Check inputs or safety filters.")
123
 
 
117
  # Extract and return the generated image
118
  for part in response.parts:
119
  if image := part.as_image():
120
+ # Convert google.genai.types.Image to PIL Image for Gradio
121
+ try:
122
+ # Try saving to a bytes buffer
123
+ img_buffer = io.BytesIO()
124
+ image.save(img_buffer)
125
+ img_buffer.seek(0)
126
+ return Image.open(img_buffer)
127
+ except Exception:
128
+ # Fallback: if save() doesn't accept buffer, try accessing bytes directly if possible
129
+ if hasattr(image, '_image_bytes'):
130
+ return Image.open(io.BytesIO(image._image_bytes))
131
+ raise
132
 
133
  raise gr.Error("The model completed but did not return an image. Check inputs or safety filters.")
134