Skip to content

Commit

Permalink
docs: update README.md with image saving feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HanaokaYuzu committed Feb 15, 2024
1 parent e1f867a commit 5b432f9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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())
Expand All @@ -97,15 +96,27 @@ 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())
```

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.
Expand Down

0 comments on commit 5b432f9

Please sign in to comment.