Update main.py
Browse files
main.py
CHANGED
@@ -107,13 +107,14 @@ def upload_image_to_imgur(client, image_binary, album=None, name="gemini-image",
|
|
107 |
|
108 |
# 使用 Gemini 生成圖片
|
109 |
def generate_image_with_gemini(prompt):
|
|
|
110 |
client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
111 |
response = client.models.generate_content(
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
for part in response.candidates[0].content.parts:
|
119 |
if part.text is not None:
|
@@ -121,7 +122,7 @@ def generate_image_with_gemini(prompt):
|
|
121 |
elif part.inline_data is not None:
|
122 |
#image = PIL.Image.open(io.BytesIO(part.inline_data.data))
|
123 |
return part.inline_data.data
|
124 |
-
|
125 |
|
126 |
|
127 |
#==========================
|
|
|
107 |
|
108 |
# 使用 Gemini 生成圖片
|
109 |
def generate_image_with_gemini(prompt):
|
110 |
+
|
111 |
client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
112 |
response = client.models.generate_content(
|
113 |
+
model="gemini-2.0-flash-exp-image-generation",
|
114 |
+
contents=prompt,
|
115 |
+
config=types.GenerateContentConfig(
|
116 |
+
response_modalities=['Text', 'Image'])
|
117 |
+
)
|
118 |
|
119 |
for part in response.candidates[0].content.parts:
|
120 |
if part.text is not None:
|
|
|
122 |
elif part.inline_data is not None:
|
123 |
#image = PIL.Image.open(io.BytesIO(part.inline_data.data))
|
124 |
return part.inline_data.data
|
125 |
+
return
|
126 |
|
127 |
|
128 |
#==========================
|