Fix Nano Banana image editing: use reference_image base64 from API instead of reference_asset_id
This commit is contained in:
parent
360ea3f919
commit
700ce92098
2 changed files with 18 additions and 10 deletions
|
|
@ -222,18 +222,21 @@ async def generate(job_id: str):
|
|||
image_data, filename = await _generate_imagen(input_data)
|
||||
job.api_model = input_data.get("model", "imagen-4.0-generate-001")
|
||||
elif provider == "nano-banana" or provider == "gemini":
|
||||
# Fetch reference image if provided
|
||||
ref_id = input_data.get("reference_asset_id")
|
||||
# The API endpoint converts reference_asset_id to reference_image (base64)
|
||||
# So we use that directly instead of loading from database
|
||||
ref_image_b64 = input_data.get("reference_image")
|
||||
ref_image_data = None
|
||||
ref_mime_type = "image/png" # Default
|
||||
ref_mime_type = "image/png" # Default
|
||||
|
||||
if ref_id:
|
||||
ref_asset = db.query(Asset).filter(Asset.id == ref_id).first()
|
||||
if ref_asset and os.path.exists(ref_asset.file_path):
|
||||
with open(ref_asset.file_path, "rb") as f:
|
||||
ref_image_data = f.read()
|
||||
if ref_asset.mime_type:
|
||||
ref_mime_type = ref_asset.mime_type
|
||||
if ref_image_b64:
|
||||
import base64
|
||||
try:
|
||||
ref_image_data = base64.b64decode(ref_image_b64)
|
||||
# Detect MIME type from decoded data
|
||||
ref_mime_type = determine_mime_type(ref_image_data)
|
||||
logger.info(f"✓ Decoded reference image from base64 ({ref_mime_type}, {len(ref_image_data)} bytes)")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to decode reference_image base64: {e}")
|
||||
|
||||
image_data, filename = await _generate_nano_banana(input_data, ref_image_data, ref_mime_type)
|
||||
job.api_model = input_data.get("model", "gemini-3-pro-image-preview")
|
||||
|
|
|
|||
|
|
@ -98,8 +98,13 @@ export default function NanoBananaProPage() {
|
|||
|
||||
if (currentAsset) {
|
||||
payload.reference_asset_id = currentAsset.id;
|
||||
console.log('✓ Adding reference asset:', currentAsset.id, currentAsset.original_filename);
|
||||
} else {
|
||||
console.warn('⚠️ No currentAsset - generating from scratch');
|
||||
}
|
||||
|
||||
console.log('📤 Sending payload:', JSON.stringify(payload, null, 2));
|
||||
|
||||
// Use direct API call with JSON
|
||||
const response = await api.post('/modules/image/generate', payload);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue