Askinkaty commited on
Commit
e22e37b
·
verified ·
1 Parent(s): 5871662

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -45,6 +45,39 @@ def generate_surfer_image(next_tide: str) -> str:
45
  return f"Error generating image: {str(e)}"
46
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  @tool
49
  def tide_time(date: str) -> str:
50
  """ A tool that checks when the time of the next high tide in Falesia beach in Algarve using DuckDuckGo search.
@@ -133,7 +166,7 @@ with open("prompts.yaml", 'r') as stream:
133
 
134
  agent = CodeAgent(
135
  model=model,
136
- tools=[get_current_time_in_timezone,get_tide_time,generate_surfer_image,final_answer], ## add your tools here (don't remove final answer)
137
  max_steps=6,
138
  verbosity_level=1,
139
  grammar=None,
 
45
  return f"Error generating image: {str(e)}"
46
 
47
 
48
+ @tool
49
+ def display_image_tool(image):
50
+ """
51
+ A tool that displays an image correctly in different formats.
52
+
53
+ Args:
54
+ image: Can be a PIL image, a URL (string), or a Base64-encoded image.
55
+
56
+ Returns:
57
+ None. Displays the image in the notebook or script.
58
+ """
59
+ if isinstance(image, Image.Image):
60
+ # If it's a PIL Image, display it directly
61
+ display.display(image)
62
+
63
+ elif isinstance(image, str):
64
+ if image.startswith("http"):
65
+ # If it's a URL, display it as an HTML image tag
66
+ display.display(display.HTML(f'<img src="{image}" width="512">'))
67
+
68
+ elif image.startswith("data:image"):
69
+ # If it's a Base64-encoded image, display it directly
70
+ display.display(display.HTML(f'<img src="{image}" width="512">'))
71
+
72
+ else:
73
+ print("Invalid string format: Expected an image URL or Base64 string.")
74
+
75
+ else:
76
+ print("Unsupported image format. Please provide a PIL image, URL, or Base64 string.")
77
+
78
+
79
+
80
+
81
  @tool
82
  def tide_time(date: str) -> str:
83
  """ A tool that checks when the time of the next high tide in Falesia beach in Algarve using DuckDuckGo search.
 
166
 
167
  agent = CodeAgent(
168
  model=model,
169
+ tools=[get_current_time_in_timezone,get_tide_time,generate_surfer_image,display_image_tool,final_answer], ## add your tools here (don't remove final answer)
170
  max_steps=6,
171
  verbosity_level=1,
172
  grammar=None,