Spaces:
Runtime error
Runtime error
Update Image_generation.py
Browse files- Image_generation.py +5 -5
Image_generation.py
CHANGED
|
@@ -7,12 +7,12 @@ from google import genai
|
|
| 7 |
from google.genai import types
|
| 8 |
from imgurpython import ImgurClient
|
| 9 |
|
|
|
|
|
|
|
| 10 |
class ImageGenerator:
|
| 11 |
-
def __init__(self,
|
| 12 |
-
# 初始化 Gemini 客戶端
|
| 13 |
-
self.genai_client = genai.Client(api_key=google_api_key)
|
| 14 |
# 初始化 Imgur 客戶端
|
| 15 |
-
self.imgur_client =
|
| 16 |
|
| 17 |
def generate_image_with_gemini(self, prompt):
|
| 18 |
"""
|
|
@@ -24,7 +24,7 @@ class ImageGenerator:
|
|
| 24 |
返回:
|
| 25 |
bytes: 生成的圖片的二進位資料,如果生成失敗則返回 None。
|
| 26 |
"""
|
| 27 |
-
response =
|
| 28 |
model="gemini-2.0-flash-exp-image-generation",
|
| 29 |
contents=prompt,
|
| 30 |
config=types.GenerateContentConfig(response_modalities=['Text', 'Image'])
|
|
|
|
| 7 |
from google.genai import types
|
| 8 |
from imgurpython import ImgurClient
|
| 9 |
|
| 10 |
+
genai_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
| 11 |
+
|
| 12 |
class ImageGenerator:
|
| 13 |
+
def __init__(self, imgur):
|
|
|
|
|
|
|
| 14 |
# 初始化 Imgur 客戶端
|
| 15 |
+
self.imgur_client = imgur
|
| 16 |
|
| 17 |
def generate_image_with_gemini(self, prompt):
|
| 18 |
"""
|
|
|
|
| 24 |
返回:
|
| 25 |
bytes: 生成的圖片的二進位資料,如果生成失敗則返回 None。
|
| 26 |
"""
|
| 27 |
+
response = genai_client.models.generate_content(
|
| 28 |
model="gemini-2.0-flash-exp-image-generation",
|
| 29 |
contents=prompt,
|
| 30 |
config=types.GenerateContentConfig(response_modalities=['Text', 'Image'])
|