Update main.py
Browse files
main.py
CHANGED
@@ -108,15 +108,21 @@ def upload_image_to_imgur(client, image_binary, album=None, name="Hugging Face-i
|
|
108 |
|
109 |
# δ½Ώη¨ Gemini ηζεη
|
110 |
def generate_image_with_gemini(prompt):
|
111 |
-
|
112 |
-
image_model = genai.GenerativeModel(model_name)
|
113 |
|
114 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
|
117 |
-
|
|
|
118 |
|
119 |
-
return None
|
120 |
|
121 |
# δ½Ώη¨ Hugging Face ηζεη
|
122 |
def generate_image_hf(prompt):
|
@@ -215,7 +221,7 @@ def handle_image_message(event):
|
|
215 |
|
216 |
prompt_en = translate_zh_to_en(prompt)
|
217 |
# ηζεη
|
218 |
-
image_binary =
|
219 |
|
220 |
if image_binary:
|
221 |
album = "nvsYwgq"
|
|
|
108 |
|
109 |
# δ½Ώη¨ Gemini ηζεη
|
110 |
def generate_image_with_gemini(prompt):
|
111 |
+
client = genai.Client()
|
|
|
112 |
|
113 |
+
response = client.models.generate_content(
|
114 |
+
model="gemini-2.0-flash-exp-image-generation",
|
115 |
+
contents=prompt,
|
116 |
+
config=types.GenerateContentConfig(
|
117 |
+
response_modalities=['Text', 'Image']
|
118 |
+
)
|
119 |
+
)
|
120 |
|
121 |
+
for part in response.candidates[0].content.parts:
|
122 |
+
if part.inline_data is not None:
|
123 |
+
return part.inline_data.data # εε³ binary εηθ³ζ
|
124 |
|
125 |
+
return None # ε¦ζη‘ζ³ηζεηοΌεε³None
|
126 |
|
127 |
# δ½Ώη¨ Hugging Face ηζεη
|
128 |
def generate_image_hf(prompt):
|
|
|
221 |
|
222 |
prompt_en = translate_zh_to_en(prompt)
|
223 |
# ηζεη
|
224 |
+
image_binary = generate_image_with_gemini(prompt_en)
|
225 |
|
226 |
if image_binary:
|
227 |
album = "nvsYwgq"
|