artintel235 commited on
Commit
f51f1c6
·
verified ·
1 Parent(s): 9e73c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -35,19 +35,22 @@ async def generate_command(
35
  img_count:int,
36
  aspect_ratio: app_commands.Choice[str],
37
  ):
38
- genai.configure(api_key=GEMINI_API_KEY)
39
- imagen = genai.ImageGenerationModel("imagen-3.0-generate-001")
40
-
41
- result = imagen.generate_images(
42
- prompt=prompt,
43
- number_of_images=img_count,
44
- safety_filter_level="block_only_high",
45
- person_generation="allow_adult",
46
- aspect_ratio=aspect_ratio,
47
- )
48
-
49
- if result:
50
- await interaction.followup.send(content=f"Successful request!")
 
 
 
51
  files = []
52
  for i, image in enumerate(result.generated_images):
53
  # Assuming `image` is a byte array or binary stream of the image
 
35
  img_count:int,
36
  aspect_ratio: app_commands.Choice[str],
37
  ):
38
+ try:
39
+ genai.configure(api_key=GEMINI_API_KEY)
40
+ imagen = genai.ImageGenerationModel("imagen-3.0-generate-001")
41
+
42
+ result = imagen.generate_images(
43
+ prompt=prompt,
44
+ number_of_images=img_count,
45
+ safety_filter_level="block_only_high",
46
+ person_generation="allow_adult",
47
+ aspect_ratio=aspect_ratio,
48
+ )
49
+
50
+ if result:
51
+ await interaction.followup.send(content=f"Successful request!")
52
+ except Exception as e:
53
+ interaction.followup.send(content=f"exception:{e}")
54
  files = []
55
  for i, image in enumerate(result.generated_images):
56
  # Assuming `image` is a byte array or binary stream of the image