Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,37 +47,29 @@ def generate_surfer_image(next_tide: str) -> str:
|
|
| 47 |
|
| 48 |
|
| 49 |
@tool
|
| 50 |
-
def display_image_tool(image:
|
| 51 |
"""
|
| 52 |
-
Display an image
|
| 53 |
|
| 54 |
Args:
|
| 55 |
-
image: The image to display. It
|
| 56 |
Returns:
|
| 57 |
-
None: The function does not return anything. It displays the image
|
| 58 |
-
|
| 59 |
Raises:
|
| 60 |
ValueError: If the string format is not a valid image URL or Base64 string.
|
| 61 |
-
TypeError: If the input is not a PIL Image or a string.
|
| 62 |
"""
|
| 63 |
-
if
|
| 64 |
-
#
|
| 65 |
-
display.display(image)
|
| 66 |
-
|
| 67 |
-
elif isinstance(image, str):
|
| 68 |
-
if image.startswith("http"):
|
| 69 |
-
# If it's a URL, display it as an HTML image tag
|
| 70 |
-
display.display(display.HTML(f'<img src="{image}" width="512">'))
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
else:
|
| 77 |
-
print("Invalid string format: Expected an image URL or Base64 string.")
|
| 78 |
|
| 79 |
else:
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
@tool
|
| 50 |
+
def display_image_tool(image: str) -> None:
|
| 51 |
"""
|
| 52 |
+
Display an image from a URL or a Base64 string.
|
| 53 |
|
| 54 |
Args:
|
| 55 |
+
image: The image to display. It must be: a URL string (starting with "http") or a Base64-encoded image string (starting with "data:image").
|
| 56 |
Returns:
|
| 57 |
+
None: The function does not return anything. It displays the image.
|
| 58 |
+
|
| 59 |
Raises:
|
| 60 |
ValueError: If the string format is not a valid image URL or Base64 string.
|
|
|
|
| 61 |
"""
|
| 62 |
+
if image.startswith("http"):
|
| 63 |
+
# Display image from URL
|
| 64 |
+
display.display(display.HTML(f'<img src="{image}" width="512">'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
elif image.startswith("data:image"):
|
| 67 |
+
# Display Base64-encoded image
|
| 68 |
+
display.display(display.HTML(f'<img src="{image}" width="512">'))
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
else:
|
| 71 |
+
raise ValueError("Invalid image format: Expected an image URL or Base64 string.")
|
| 72 |
+
|
| 73 |
|
| 74 |
|
| 75 |
|