Spaces:
Sleeping
Sleeping
Add recommend_pet tool
Browse files
app.py
CHANGED
|
@@ -7,31 +7,48 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
-
@tool
|
| 12 |
-
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
-
"""
|
| 19 |
-
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
-
def
|
| 23 |
-
"""A tool that
|
|
|
|
| 24 |
Args:
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
"""
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
@@ -47,19 +64,12 @@ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
|
| 47 |
custom_role_conversions=None,
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
# Import tool from Hub
|
| 52 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 53 |
-
|
| 54 |
-
# Create the search tool
|
| 55 |
-
search_tool = DuckDuckGoSearchTool()
|
| 56 |
-
|
| 57 |
with open("prompts.yaml", 'r') as stream:
|
| 58 |
prompt_templates = yaml.safe_load(stream)
|
| 59 |
|
| 60 |
agent = CodeAgent(
|
| 61 |
model=model,
|
| 62 |
-
tools=[final_answer,
|
| 63 |
max_steps=6,
|
| 64 |
verbosity_level=1,
|
| 65 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from smolagents import Agent, tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
@tool
|
| 13 |
+
def recommend_pet(personality: str) -> str:
|
| 14 |
+
"""A tool that recommends a pet based on your personality description.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
personality: A description of your personality traits.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
A string with a pet recommendation.
|
| 21 |
"""
|
| 22 |
+
# Normalize input to lowercase for matching.
|
| 23 |
+
personality_lower = personality.lower()
|
| 24 |
+
|
| 25 |
+
# Map personality traits to pet suggestions.
|
| 26 |
+
traits_to_pets = {
|
| 27 |
+
"shy": "cat",
|
| 28 |
+
"curious": "cat",
|
| 29 |
+
"energetic": "dog",
|
| 30 |
+
"active": "dog",
|
| 31 |
+
"calm": "fish",
|
| 32 |
+
"peaceful": "fish",
|
| 33 |
+
"adventurous": "ferret",
|
| 34 |
+
"creative": "parrot",
|
| 35 |
+
"imaginative": "parrot"
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# Count matching traits for each pet.
|
| 39 |
+
scores = {}
|
| 40 |
+
for trait, pet in traits_to_pets.items():
|
| 41 |
+
if trait in personality_lower:
|
| 42 |
+
scores[pet] = scores.get(pet, 0) + 1
|
| 43 |
+
|
| 44 |
+
# If any traits matched, select the pet with the highest score.
|
| 45 |
+
# Otherwise, default to "cat".
|
| 46 |
+
if scores:
|
| 47 |
+
recommended_pet = max(scores, key=scores.get)
|
| 48 |
+
else:
|
| 49 |
+
recommended_pet = "cat"
|
| 50 |
+
|
| 51 |
+
return f"Based on your personality ('{personality}'), I recommend a {recommended_pet} as your companion!"
|
| 52 |
|
| 53 |
|
| 54 |
final_answer = FinalAnswerTool()
|
|
|
|
| 64 |
custom_role_conversions=None,
|
| 65 |
)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
with open("prompts.yaml", 'r') as stream:
|
| 68 |
prompt_templates = yaml.safe_load(stream)
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[final_answer,recommend_pet], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|