c1tr0n75 commited on
Commit
de4500d
·
1 Parent(s): 3e8a397

fix: Use image.image_bytes directly to resolve TypeError

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -120,16 +120,18 @@ The output must be a single image that looks like the completed infographic, mai
120
  if image := part.as_image():
121
  # Convert google.genai.types.Image to PIL Image for Gradio
122
  try:
123
- # Try saving to a bytes buffer
124
- img_buffer = io.BytesIO()
125
- image.save(img_buffer)
126
- img_buffer.seek(0)
127
- return Image.open(img_buffer)
128
- except Exception:
129
- # Fallback: if save() doesn't accept buffer, try accessing bytes directly if possible
130
- if hasattr(image, '_image_bytes'):
131
- return Image.open(io.BytesIO(image._image_bytes))
132
- raise
 
 
133
 
134
  raise gr.Error("The model completed but did not return an image. Check inputs or safety filters.")
135
 
@@ -152,7 +154,7 @@ with gr.Blocks(title="Visual Minutes Generator") as demo:
152
  label="Google API Key",
153
  type="password",
154
  placeholder="Enter your Google API Key",
155
- info="Your API key is required to use the Gemini model"
156
  )
157
 
158
  transcript_input = gr.File(
 
120
  if image := part.as_image():
121
  # Convert google.genai.types.Image to PIL Image for Gradio
122
  try:
123
+ # The Google GenAI SDK's image.save() expects a path, not a buffer.
124
+ # However, the object has an .image_bytes attribute we can use directly.
125
+ if hasattr(image, 'image_bytes'):
126
+ return Image.open(io.BytesIO(image.image_bytes))
127
+ elif hasattr(image, '_image_bytes'):
128
+ return Image.open(io.BytesIO(image._image_bytes))
129
+ else:
130
+ # If we can't find bytes, try saving to a temp file as a last resort
131
+ # But likely one of the above will work based on the traceback
132
+ raise ValueError("Could not extract bytes from GenAI Image object")
133
+ except Exception as e:
134
+ raise gr.Error(f"Failed to process generated image: {e}")
135
 
136
  raise gr.Error("The model completed but did not return an image. Check inputs or safety filters.")
137
 
 
154
  label="Google API Key",
155
  type="password",
156
  placeholder="Enter your Google API Key",
157
+ info="Your API key is required to use the model"
158
  )
159
 
160
  transcript_input = gr.File(