--- a/scripts/generate_image.py +++ b/scripts/generate_image.py @@ -111,11 +111,33 @@ return base64.b64decode(b64) return base64.b64decode(img_data) - # Handle 'content' response format (Gemini models) + # Handle 'content' response format (Gemini models) and 'message.images' format (FLUX) if "choices" in data: for choice in data["choices"]: message = choice.get("message", {}) - content_parts = message.get("content", []) + + # Check for images array in message (FLUX edit responses) + msg_images = message.get("images") or [] + for img_data in msg_images: + if isinstance(img_data, dict): + # Handle {"type": "image_url", "image_url": {"url": "data:..."}} + img_url = "" + if "image_url" in img_data and isinstance(img_data["image_url"], dict): + img_url = img_data["image_url"].get("url", "") + elif "url" in img_data: + img_url = img_data["url"] + if img_url: + if img_url.startswith("data:"): + _, _, b64 = img_url.partition(",") + return base64.b64decode(b64) + return base64.b64decode(img_url) + elif isinstance(img_data, str): + if img_data.startswith("data:"): + _, _, b64 = img_data.partition(",") + return base64.b64decode(b64) + return base64.b64decode(img_data) + + content_parts = message.get("content") or [] if isinstance(content_parts, str): continue for part in content_parts: @@ -126,7 +148,12 @@ return base64.b64decode(b64) print("ERROR: Could not extract image from API response.", file=sys.stderr) - print("Response:", json.dumps(data, indent=2)[:500], file=sys.stderr) + # Debug: show structure without full base64 data + debug = json.dumps(data, indent=2) + # Truncate any base64 blobs for readability + import re + debug = re.sub(r'[A-Za-z0-9+/=]{200,}', '', debug) + print("Response structure:", debug[:3000], file=sys.stderr) sys.exit(1)