Jobfromearth commited on
Commit
985c000
·
verified ·
1 Parent(s): 3f998fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -4,10 +4,26 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  @tool
12
  def get_hacker_news_top_stories(limit: int = 5) -> str:
13
  """A tool that fetches the current top stories directly from Hacker News.
@@ -74,6 +90,9 @@ get_time = get_current_time_in_timezone
74
  # 实例化 定制工具
75
  custom = my_custom_tool
76
 
 
 
 
77
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
78
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
79
 
@@ -93,7 +112,7 @@ with open("prompts.yaml", 'r') as stream:
93
 
94
  agent = CodeAgent(
95
  model=model,
96
- tools=[final_answer, search_tool, image_generation_tool, hacker_news, get_time, custom], ## add your tools here (don't remove final answer)
97
  max_steps=6,
98
  verbosity_level=1,
99
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from PIL import Image
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+
13
+ @tool
14
+ def save_image_to_disk(image: Image.Image, filename: str) -> str:
15
+ """A tool that securely saves a PIL Image object to the local disk.
16
+
17
+ Args:
18
+ image: The PIL Image object to be saved.
19
+ filename: The desired filename (e.g., 'cyber_cat.png').
20
+ """
21
+ try:
22
+ image.save(filename)
23
+ return f"Success! Image permanently saved as {filename} in the current directory."
24
+ except Exception as e:
25
+ return f"Error saving image: {str(e)}"
26
+
27
  @tool
28
  def get_hacker_news_top_stories(limit: int = 5) -> str:
29
  """A tool that fetches the current top stories directly from Hacker News.
 
90
  # 实例化 定制工具
91
  custom = my_custom_tool
92
 
93
+ # 实例化image save tool
94
+ image_save = save_image_to_disk
95
+
96
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
97
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
98
 
 
112
 
113
  agent = CodeAgent(
114
  model=model,
115
+ tools=[final_answer, search_tool, image_generation_tool, hacker_news, get_time, custom, image_save], ## add your tools here (don't remove final answer)
116
  max_steps=6,
117
  verbosity_level=1,
118
  grammar=None,