Askinkaty commited on
Commit
d50fee8
·
verified ·
1 Parent(s): 791ae86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
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: Union[Image.Image, str]) -> None:
51
  """
52
- Display an image in different formats.
53
 
54
  Args:
55
- image: The image to display. It can be a PIL Image object; a URL string (starting with "http"), a Base64-encoded image string (starting with "data:image").
56
  Returns:
57
- None: The function does not return anything. It displays the image in the notebook or script.
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 isinstance(image, Image.Image):
64
- # If it's a PIL Image, display it directly
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
- elif image.startswith("data:image"):
73
- # If it's a Base64-encoded image, display it directly
74
- display.display(display.HTML(f'<img src="{image}" width="512">'))
75
-
76
- else:
77
- print("Invalid string format: Expected an image URL or Base64 string.")
78
 
79
  else:
80
- print("Unsupported image format. Please provide a PIL image, URL, or Base64 string.")
 
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