Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 7df86e7

Browse files
authored
doc: update readme
1 parent dddab19 commit 7df86e7

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

README.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,40 @@ GeminiImage.save_sync(generated_images)
162162
import asyncio
163163
from gemini import Gemini, GeminiImage
164164

165-
async def generate_and_save_images_async():
166-
prompt = "Create illustrations of Seoul, South Korea."
165+
async def fetch_and_save_images_async(prompt: str):
167166
response = await GeminiClient.generate_content_async(prompt)
168167

169-
generated_images = response.generated_images # Check generated images [Dict]
168+
generated_images = response.generated_images # Check response images [Dict]
169+
for image in generated_images:
170+
gemini_image = GeminiImage(url=image.url)
171+
await gemini_image.save(path="save_path") # Save to path asynchronously
172+
173+
# Run the async function
174+
if __name__ == "__main__":
175+
user_prompt = input("Enter your prompt: ")
176+
asyncio.run(fetch_and_save_images_async(user_prompt))
177+
```
178+
<details><summary>GeminiImage.save logics</summary>
179+
180+
```python
181+
import asyncio
182+
from gemini import Gemini, GeminiImage
183+
184+
async def fetch_and_save_images_async(prompt: str):
185+
response = await GeminiClient.generate_content_async(prompt)
186+
187+
generated_images = response.generated_images # Check response images [Dict]
170188
bytes_images_dict = await GeminiImage.fetch_images_dict(generated_images) # Get bytes images dict asynchronously
171189
await GeminiImage.save_images(bytes_images_dict, path="save_path") # Save to path asynchronously
172190

173191
# Run the async function
174192
if __name__ == "__main__":
175-
asyncio.run(generate_and_save_images_async())
176-
193+
user_prompt = input("Enter your prompt: ")
194+
asyncio.run(fetch_and_save_images_async(user_prompt))
177195
```
178196

197+
</details>
198+
179199

180200
<br>
181201

@@ -200,8 +220,26 @@ GeminiImage.save_sync(response_images)
200220
import asyncio
201221
from gemini import Gemini, GeminiImage
202222

203-
async def fetch_and_save_images_async():
204-
prompt = "Please recommend a travel itinerary for Seoul."
223+
async def fetch_and_save_images_async(prompt: str):
224+
response = await GeminiClient.generate_content_async(prompt)
225+
226+
response_images = response.web_images # Check response images [Dict]
227+
for image in response_images:
228+
gemini_image = GeminiImage(url=image.url)
229+
await gemini_image.save(path="save_path") # Save to path asynchronously
230+
231+
# Run the async function
232+
if __name__ == "__main__":
233+
user_prompt = input("Enter your prompt: ")
234+
asyncio.run(fetch_and_save_images_async(user_prompt))
235+
```
236+
<details><summary>GeminiImage.save logics</summary>
237+
238+
```python
239+
import asyncio
240+
from gemini import Gemini, GeminiImage
241+
242+
async def fetch_and_save_images_async(prompt: str):
205243
response = await GeminiClient.generate_content_async(prompt)
206244

207245
response_images = response.web_images # Check response images [Dict]
@@ -210,10 +248,12 @@ async def fetch_and_save_images_async():
210248

211249
# Run the async function
212250
if __name__ == "__main__":
213-
asyncio.run(fetch_and_save_images_async())
214-
251+
user_prompt = input("Enter your prompt: ")
252+
asyncio.run(fetch_and_save_images_async(user_prompt))
215253
```
216254

255+
</details>
256+
217257

218258
<br>
219259

0 commit comments

Comments
 (0)