Spaces:
Sleeping
Sleeping
Update app.py
Browse filesGoing back to defaults
app.py
CHANGED
@@ -19,22 +19,22 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
-
@tool
|
23 |
-
def get_web_search_results(query: str)-> str: #it's import to specify the return type
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
@tool
|
40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -51,26 +51,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
51 |
except Exception as e:
|
52 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
53 |
|
54 |
-
@tool
|
55 |
-
def generate_image(description: str) -> str:
|
56 |
-
"""A tool that generates an image from a text description. The generated image should be displayed using Markdown.
|
57 |
-
Args:
|
58 |
-
description: A string representing the text description to generate an image of.
|
59 |
-
"""
|
60 |
-
image_generation_tool = Tool.from_space(
|
61 |
-
"black-forest-labs/FLUX.1-schnell",
|
62 |
-
name="image_generator",
|
63 |
-
description="Generate an image from a prompt"
|
64 |
-
)
|
65 |
-
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
66 |
-
image = image_generation_tool(description)
|
67 |
-
image.save("my picture.png")
|
68 |
-
return f"Image generated for prompt: {description} is {image}."
|
69 |
-
|
70 |
-
|
71 |
# @tool
|
72 |
# def generate_image(description: str) -> str:
|
73 |
-
# """A tool that generates an image from a text description.
|
74 |
# Args:
|
75 |
# description: A string representing the text description to generate an image of.
|
76 |
# """
|
@@ -79,21 +62,13 @@ def generate_image(description: str) -> str:
|
|
79 |
# name="image_generator",
|
80 |
# description="Generate an image from a prompt"
|
81 |
# )
|
82 |
-
# #
|
83 |
-
#
|
84 |
-
|
85 |
-
#
|
86 |
-
# buffered = BytesIO()
|
87 |
-
# pil_image.save(buffered, format="PNG")
|
88 |
-
# buffered.seek(0)
|
89 |
-
|
90 |
-
# # Encode as base64
|
91 |
-
# img_base64 = base64.b64encode(buffered.read()).decode()
|
92 |
-
|
93 |
-
# # Return as Markdown image
|
94 |
-
# return f""
|
95 |
-
|
96 |
|
|
|
|
|
97 |
|
98 |
final_answer = FinalAnswerTool()
|
99 |
|
@@ -109,14 +84,14 @@ custom_role_conversions=None,
|
|
109 |
|
110 |
|
111 |
# Import tool from Hub
|
112 |
-
|
113 |
|
114 |
with open("prompts.yaml", 'r') as stream:
|
115 |
prompt_templates = yaml.safe_load(stream)
|
116 |
|
117 |
agent = CodeAgent(
|
118 |
model=model,
|
119 |
-
tools=[final_answer,
|
120 |
max_steps=6,
|
121 |
verbosity_level=1,
|
122 |
grammar=None,
|
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
+
# @tool
|
23 |
+
# def get_web_search_results(query: str)-> str: #it's import to specify the return type
|
24 |
+
# #Keep this format for the description / args / args description but feel free to modify the tool
|
25 |
+
# """A tool that searchs the web using a query.
|
26 |
+
# Args:
|
27 |
+
# query: A string representing a valid web query. IMPORTANT: Follow type str format strictly e.g. 'pictures of cats'.
|
28 |
+
# """
|
29 |
+
# search_results_tool = DuckDuckGoSearchTool()
|
30 |
+
# try:
|
31 |
+
# results = search_results_tool(query)
|
32 |
+
# if results and results != "None":
|
33 |
+
# return results
|
34 |
+
# else:
|
35 |
+
# return "Your query may be incorrectly formatted or there may be an issue with search engine."
|
36 |
+
# except Exception as e:
|
37 |
+
# return f"{query} is an invalid query"
|
38 |
|
39 |
@tool
|
40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
51 |
except Exception as e:
|
52 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# @tool
|
55 |
# def generate_image(description: str) -> str:
|
56 |
+
# """A tool that generates an image from a text description. The generated image should be displayed using Markdown.
|
57 |
# Args:
|
58 |
# description: A string representing the text description to generate an image of.
|
59 |
# """
|
|
|
62 |
# name="image_generator",
|
63 |
# description="Generate an image from a prompt"
|
64 |
# )
|
65 |
+
# # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
66 |
+
# image = image_generation_tool(description)
|
67 |
+
# image.save("my picture.png")
|
68 |
+
# return f"Image generated for prompt: {description} is {image}."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
|
71 |
+
web_search = DuckDuckGoSearchTool()
|
72 |
|
73 |
final_answer = FinalAnswerTool()
|
74 |
|
|
|
84 |
|
85 |
|
86 |
# Import tool from Hub
|
87 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
88 |
|
89 |
with open("prompts.yaml", 'r') as stream:
|
90 |
prompt_templates = yaml.safe_load(stream)
|
91 |
|
92 |
agent = CodeAgent(
|
93 |
model=model,
|
94 |
+
tools=[final_answer, image_generation_tool, web_search], ## add your tools here (don't remove final answer)
|
95 |
max_steps=6,
|
96 |
verbosity_level=1,
|
97 |
grammar=None,
|