From 5b432f91503d1597e250004b50f6c118221b3751 Mon Sep 17 00:00:00 2001 From: UZQueen <157540577+HanaokaYuzu@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:31:05 -0600 Subject: [PATCH] docs: update README.md with image saving feature --- README.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4b46a00..0d569f1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A reverse-engineered asynchronous python wrapper for [Google Gemini](https://gem ## Features - **ImageFx Support** - Supports retrieving images generated by ImageFx, Google's latest AI image generator. -- **Classified Outputs** - Automatically categorizes texts, web images and AI generated images from the response. +- **Classified Outputs** - Auto categorizes texts, web images and AI generated images from the response. - **Official Flavor** - Provides a simple and elegant interface inspired by [Google Generative AI](https://ai.google.dev/tutorials/python_quickstart)'s official API. - **Asynchronous** - Utilizes `asyncio` to run generating tasks and return outputs efficiently. @@ -83,8 +83,7 @@ Images in the API's output are stored as a list of `Image` objects. You can acce ```python async def main(): response = await client.generate_content("Send me some pictures of cats") - images = response.images - for image in images: + for image in response.images: print(image, "\n\n----------------------------------\n") asyncio.run(main()) @@ -97,8 +96,7 @@ In February 2022, Google introduced a new AI image generator called ImageFx and ```python async def main(): response = await client.generate_content("Generate some pictures of cats") - images = response.images - for image in images: + for image in response.images: print(image, "\n\n----------------------------------\n") asyncio.run(main()) @@ -106,6 +104,19 @@ asyncio.run(main()) Note: by default, when asked to send images (like the previous example), Gemini will send images fetched from web instead of generating images with AI model, unless you specifically require to "generate" images in your prompt. In this package, web images and generated images are treated differently as `WebImage` and `GeneratedImage`, and will be automatically categorized in the output. +### Save images to local files + +You can save images returned from Gemini to local files under `/temp` by calling `Image.save()`. Optionally, you can specify the file path and file name by passing `path` and `filename` arguments to the function. Works for both `WebImage` and `GeneratedImage`. + +```python +async def main(): + response = await client.generate_content("Generate some pictures of cats") + for i, image in enumerate(response.images): + await image.save(path="temp/", filename=f"cat_{i}.png") + +asyncio.run(main()) +``` + ### Check and switch to other answer candidates A response from Gemini usually contains multiple reply candidates with different generated contents. You can check all candidates and choose one to continue the conversation. By default, the first candidate will be chosen automatically.