Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,22 +12,22 @@ client = genai.Client(api_key=API_KEY)
|
|
| 12 |
def edit_image_with_gemini(image, text_input):
|
| 13 |
"""
|
| 14 |
Edits an image using Gemini 2.0 Flash Experimental API based on a given text prompt.
|
| 15 |
-
|
| 16 |
Parameters:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
Returns:
|
| 21 |
-
|
| 22 |
"""
|
| 23 |
-
|
| 24 |
if image is None or not text_input:
|
| 25 |
return "Please upload an image and provide an edit prompt.", None
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
# Generate content with Gemini API
|
| 28 |
response = client.models.generate_content(
|
| 29 |
model="gemini-2.0-flash-exp-image-generation",
|
| 30 |
-
contents=
|
| 31 |
config=types.GenerateContentConfig(
|
| 32 |
response_modalities=['Text', 'Image']
|
| 33 |
)
|
|
|
|
| 12 |
def edit_image_with_gemini(image, text_input):
|
| 13 |
"""
|
| 14 |
Edits an image using Gemini 2.0 Flash Experimental API based on a given text prompt.
|
|
|
|
| 15 |
Parameters:
|
| 16 |
+
image (PIL.Image): The input image.
|
| 17 |
+
text_input (str): Text prompt describing the edit.
|
|
|
|
| 18 |
Returns:
|
| 19 |
+
A tuple of status message and the modified image (or None).
|
| 20 |
"""
|
|
|
|
| 21 |
if image is None or not text_input:
|
| 22 |
return "Please upload an image and provide an edit prompt.", None
|
| 23 |
|
| 24 |
+
# Wrap text_input in a tuple to match the expected format
|
| 25 |
+
contents = [(text_input,), image]
|
| 26 |
+
|
| 27 |
# Generate content with Gemini API
|
| 28 |
response = client.models.generate_content(
|
| 29 |
model="gemini-2.0-flash-exp-image-generation",
|
| 30 |
+
contents=contents,
|
| 31 |
config=types.GenerateContentConfig(
|
| 32 |
response_modalities=['Text', 'Image']
|
| 33 |
)
|