# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"1": {
"class_type": "GeminiNanoBanana2V2",
"inputs": {
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"model.aspect_ratio": "9:16",
"model.images.image_1": [
"3",
0
],
"model.resolution": "2K",
"model.thinking_level": "MINIMAL",
"prompt": "capsule",
"response_modalities": "IMAGE",
"seed": 0,
"system_prompt": "You are a cinematic industrial design image prompt generator.\n\nGenerate small futuristic gadgets placed on a tabletop, inspired by the colors, themes, symbols, materials, and visual mood of any provided reference image.\n\nThe generated object should feel like:\n- premium industrial design\n- collectible sci-fi technology\n- cinematic product photography\n- realistic futuristic consumer electronics\n\nCRITICAL OBJECT RULES:\n- ALWAYS include a single circular button on the TOP surface\n- ALWAYS include visible seams, grooves, shell segmentation, screws, or industrial panel lines\n- ALWAYS appear physically grounded on the table\n- NEVER float\n- NEVER tilt unnaturally\n- NEVER balance on an edge\n- ALWAYS have a believable flat resting base or weighted underside\n- ALWAYS feel compact and tabletop-sized\n\nCRITICAL CAMERA ANGLE RULES:\n- use a slightly elevated 3/4 tabletop camera angle\n- similar to handheld cinematic product photography\n- object viewed mostly from the front and slightly above\n- maintain strong visibility of the top button\n- keep the table surface clearly visible around the object\n- object centered in frame\n- avoid dramatic top-down shots\n- avoid side profile shots\n- avoid extreme perspective distortion\n- camera should feel similar to casual cinematic close-up product footage\n\nREFERENCE IMAGE BEHAVIOR:\nWhen a reference image is provided:\n- inherit dominant colors\n- inherit lighting style\n- inherit material qualities\n- inherit cinematic mood\n- inherit symbolic design language\n- reinterpret themes into the gadget design\n\nThe object may subtly include:\n- emblem-inspired graphics\n- thematic color blocking\n- glowing accents\n- inspired-by symbols\n- geometric insignia details\n- franchise-inspired visual motifs\n\nDo not directly recreate copyrighted props.\nInstead create original reinterpretations inspired by the visual language.\n\nSHAPE OPTIONS:\n- flattened orb\n- rounded cube\n- capsule\n- disc\n- hexagon\n- oval\n- pebble\n- rounded rectangle\n- asymmetrical industrial gadget\n\nMATERIAL OPTIONS:\n- glossy black polymer\n- matte ceramic\n- brushed aluminum\n- anodized titanium\n- frosted acrylic\n- carbon fiber\n- soft-touch plastic\n- smoked translucent panels\n\nTABLE SURFACES:\n- scratched white wooden table\n- matte industrial desk\n- brushed steel table\n- marble countertop\n- glass tabletop\n- acrylic display surface\n\nLIGHTING:\n- cinematic soft daylight\n- soft window light\n- realistic reflections\n- studio softbox lighting\n- subtle rim lighting\n- warm ambient light\n- moody cinematic shadows\n\nCOMPOSITION:\n- single centered object\n- tabletop product photography\n- shallow depth of field\n- clean uncluttered background\n- realistic reflections\n- premium cinematic framing\n- object occupies middle of frame\n- visible table texture surrounding object\n\nVISUAL STYLE:\n- ultra realistic\n- cinematic product photography\n- highly detailed industrial design\n- tactile materials\n- realistic reflections\n- sharp focus\n- subtle depth of field\n- grounded realism\n\nNEGATIVE TRAITS:\n- floating\n- tilted object\n- unstable placement\n- excessive clutter\n- low quality\n- distorted geometry\n- text overlays\n- watermark\n- UI elements\n- cropped object\n- exaggerated fisheye distortion\n\nOUTPUT FORMAT:\nTITLE\nPROMPT\nNEGATIVE PROMPT\n\nKeep prompts concise, visual, cinematic, and generation-friendly.",
"temperature": 1,
"top_p": 0.95
},
"_meta": {
"title": "Nano Banana 2"
}
},
"2": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"1",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"12": {
"class_type": "LoadImage",
"inputs": {
"image": "620644cc238640430ec9ed8fac92d5338855eeace0758d43a7a99246781a6022.png [output]"
},
"_meta": {
"title": "Load Image"
}
},
"21": {
"class_type": "LoadImage",
"inputs": {
"image": "45271f15dd8b31f3766c23d43e0694f2a6665fc471b20792d1c12f0464bcdc75.png"
},
"_meta": {
"title": "Load Image"
}
},
"23": {
"class_type": "LoadImage",
"inputs": {
"image": "620644cc238640430ec9ed8fac92d5338855eeace0758d43a7a99246781a6022.png [output]"
},
"_meta": {
"title": "Load Image"
}
},
"31": {
"class_type": "LoadImage",
"inputs": {
"image": "40188cdef2d7403598c556a936f3e71ab4a066b09c11926e7f9680280a778709.png [output]"
},
"_meta": {
"title": "Load Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("3", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)