fix: Use image.image_bytes directly to resolve TypeError
Browse files
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 |
-
#
|
| 124 |
-
|
| 125 |
-
image
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
| 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
|
| 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(
|