Spaces:
Sleeping
Sleeping
Update app.py
Browse filesEquip agent with custom and pre-existing tools.
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
-
from
|
|
|
|
|
|
|
| 2 |
import datetime
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
@@ -7,16 +10,24 @@ 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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -33,7 +44,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
-
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# 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:
|
|
@@ -55,7 +66,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 1 |
+
from collections import defaultdict
|
| 2 |
+
from random import randint
|
| 3 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, load_tool,tool
|
| 4 |
import datetime
|
| 5 |
+
|
| 6 |
import requests
|
| 7 |
import pytz
|
| 8 |
import yaml
|
|
|
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
|
|
| 13 |
@tool
|
| 14 |
+
def pick_song(mood:str)-> str: #it's import to specify the return type
|
| 15 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 16 |
+
"""A tool that returns a youtube song URL based on the user's mood.
|
| 17 |
Args:
|
| 18 |
+
mood: the user's current mood
|
|
|
|
| 19 |
"""
|
| 20 |
+
song_dict = defaultdict(
|
| 21 |
+
lambda: ["https://youtu.be/dQw4w9WgXcQ?feature=shared"],
|
| 22 |
+
{
|
| 23 |
+
"happy" : ["https://youtu.be/ZbZSe6N_BXs?feature=shared", "https://youtu.be/ru0K8uYEZWw?feature=shared", "https://youtu.be/09R8_2nJtjg?feature=shared"],
|
| 24 |
+
"sad" : ["https://youtu.be/TdrL3QxjyVw?feature=shared", "https://youtu.be/S9bCLPwzSC0?feature=shared"],
|
| 25 |
+
"angry" : ["https://youtu.be/l3RsOxKHr6k?feature=shared", "https://youtu.be/5x3PuvsHpNY?feature=shared", "https://youtu.be/MjwttGizNEs?feature=shared"]
|
| 26 |
+
}
|
| 27 |
+
)
|
| 28 |
+
url_list = song_dict[mood]
|
| 29 |
+
|
| 30 |
+
return url_list[randint(0, len(url_list) - 1)]
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 46 |
|
| 47 |
+
private_search_tool = DuckDuckGoSearchTool()
|
| 48 |
final_answer = FinalAnswerTool()
|
| 49 |
|
| 50 |
# 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:
|
|
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
+
tools=[get_current_time_in_timezone, private_search_tool, image_generation_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|