Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,23 +12,27 @@ import requests
|
|
| 12 |
from io import BytesIO
|
| 13 |
from PIL import Image
|
| 14 |
|
|
|
|
|
|
|
| 15 |
@tool
|
| 16 |
-
def generate_image(imageprompt: str) ->
|
| 17 |
"""A tool that generates an image based on a given prompt.
|
| 18 |
|
| 19 |
Args:
|
| 20 |
imageprompt: The description of the image to generate.
|
| 21 |
|
| 22 |
Returns:
|
| 23 |
-
|
| 24 |
"""
|
| 25 |
url = f"https://image.pollinations.ai/prompt/{imageprompt}"
|
| 26 |
response = requests.get(url)
|
| 27 |
|
| 28 |
if response.status_code == 200:
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
-
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 12 |
from io import BytesIO
|
| 13 |
from PIL import Image
|
| 14 |
|
| 15 |
+
import base64
|
| 16 |
+
|
| 17 |
@tool
|
| 18 |
+
def generate_image(imageprompt: str) -> str:
|
| 19 |
"""A tool that generates an image based on a given prompt.
|
| 20 |
|
| 21 |
Args:
|
| 22 |
imageprompt: The description of the image to generate.
|
| 23 |
|
| 24 |
Returns:
|
| 25 |
+
A base64 string representing the generated image.
|
| 26 |
"""
|
| 27 |
url = f"https://image.pollinations.ai/prompt/{imageprompt}"
|
| 28 |
response = requests.get(url)
|
| 29 |
|
| 30 |
if response.status_code == 200:
|
| 31 |
+
image_data = BytesIO(response.content)
|
| 32 |
+
base64_image = base64.b64encode(image_data.getvalue()).decode("utf-8")
|
| 33 |
+
return f"data:image/png;base64,{base64_image}"
|
| 34 |
else:
|
| 35 |
+
return "Failed to generate image."
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|