Created
December 16, 2025 21:44
-
-
Save SqrtRyan/fefe993a0b416d591289226347fec770 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rp | |
| from google import genai | |
| from google.genai.types import ( | |
| GenerateContentConfig, | |
| Modality, | |
| ThinkingConfig, | |
| ImageConfig, | |
| ) | |
| import os | |
| os.environ["GOOGLE_CLOUD_PROJECT"] = "400060882616" | |
| os.environ["GOOGLE_CLOUD_LOCATION"] = "global" | |
| os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "True" | |
| def nanobanana_i2i(input_image, prompt): | |
| client = genai.Client() | |
| response = client.models.generate_content( | |
| # model="gemini-2.5-flash-image-preview", | |
| # model="gemini-3-pro-preview", | |
| model="gemini-3-pro-image-preview", | |
| contents=[ | |
| prompt, | |
| rp.as_pil_image(input_image), | |
| ], | |
| config=GenerateContentConfig( | |
| response_modalities=[Modality.TEXT, Modality.IMAGE], | |
| candidate_count=1, | |
| thinking_config=ThinkingConfig( | |
| # thinking_budget=0, | |
| ), | |
| safety_settings=[ | |
| {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"}, | |
| {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"}, | |
| {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"}, | |
| {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}, | |
| ], | |
| image_config=ImageConfig( | |
| # aspect_ratio="16:9", | |
| image_size="4K", | |
| ), | |
| ), | |
| ) | |
| [candidate] = response.candidates | |
| images = [ | |
| rp.decode_image_from_bytes(part.as_image().image_bytes) | |
| for part in candidate.content.parts | |
| if part.inline_data | |
| ] | |
| [image]=images | |
| return image | |
| if __name__ == "__main__": | |
| input_image_url = "https://people.com/thmb/oIWvqTiZiSegeOjfASchPsiuaMQ=/4000x0/filters:no_upscale():max_bytes(150000):strip_icc():focal(704x0:706x2)/kim-petras-3-1-2000-b7a11e2a0e534ed6b6f458c1d42f8025.jpg" | |
| input_image = rp.load_image(input_image_url, use_cache=True) | |
| prompt = "Give her a leather jacket and put her in the sunlight with the same pose" | |
| rp.tic() | |
| print("Starting nanobanana request...") | |
| output_image = nanobanana_i2i(input_image, prompt) | |
| print("Request took %.2f seconds" % rp.toc()) | |
| output_image_path = rp.save_image(output_image) | |
| output_image_path = rp.get_absolute_path(output_image_path) | |
| print("Saved image:", output_image_path) | |
| rp.display_image(output_image) | |
| rp.web_copy_path(output_image_path) | |
| video_path='/root/CleanCode/Github/ChronoEdit/outputs/mtfi2i_nongrid/prof/smoothwater.mp4' | |
| video_path='/root/CleanCode/Experiments/Nanobananna_Edits/ENV_OCN_0010_FL-2dOcean-CrstMist-CamA_proxyMOV_v0008.mov' | |
| video=load_video_via_decord(video_path,indices=resize_list(range(64),16)) | |
| video=load_video_via_decord(video_path,indices=16) | |
| video=resize_images_to_fit(video,allow_growth=False,height=1024,width=1024) | |
| grid_image=tiled_images(video,border_thickness=0) | |
| prompt='Add tons of seafoam and spray, making the seas rougher - to each of the 16 panels, which are in chronological order from top left going right. Also make it daytime' | |
| input_image=grid_image | |
| rp.tic() | |
| print("Starting nanobanana request...") | |
| output_image = nanobanana_i2i(input_image, prompt) | |
| print("Request took %.2f seconds" % rp.toc()) | |
| output_image_path = rp.save_image(output_image) | |
| output_image_path = rp.get_absolute_path(output_image_path) | |
| print("Saved image:", output_image_path) | |
| rp.display_image(output_image) | |
| rp.web_copy_path(output_image_path) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment