Fix for Gemini Image Generation using Nano Banana
https://ai.google.dev/gemini-api/docs/image-generation?authuser=1#rest
This commit is contained in:
parent
171021cfa4
commit
ac045ee2d2
|
@ -586,17 +586,15 @@ async def image_generations(
|
|||
|
||||
model = get_image_model(request)
|
||||
data = {
|
||||
"instances": {"prompt": form_data.prompt},
|
||||
"parameters": {
|
||||
"sampleCount": form_data.n,
|
||||
"outputOptions": {"mimeType": "image/png"},
|
||||
},
|
||||
"prompt": {"text": form_data.prompt},
|
||||
"samples": form_data.n
|
||||
}
|
||||
|
||||
|
||||
# Use asyncio.to_thread for the requests.post call
|
||||
r = await asyncio.to_thread(
|
||||
requests.post,
|
||||
url=f"{request.app.state.config.IMAGES_GEMINI_API_BASE_URL}/models/{model}:predict",
|
||||
url=f"{request.app.state.config.IMAGES_GEMINI_API_BASE_URL}/models/{model}:generateImage?key={request.app.state.config.IMAGES_GEMINI_API_KEY}",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
@ -605,9 +603,9 @@ async def image_generations(
|
|||
res = r.json()
|
||||
|
||||
images = []
|
||||
for image in res["predictions"]:
|
||||
for image in res.get("images", []):
|
||||
image_data, content_type = load_b64_image_data(
|
||||
image["bytesBase64Encoded"]
|
||||
image["imageBytes"]
|
||||
)
|
||||
url = upload_image(request, image_data, content_type, data, user)
|
||||
images.append({"url": url})
|
||||
|
|
Loading…
Reference in New Issue