Update app.py
#349
by
SBellilty
- opened
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -7,16 +7,22 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -40,13 +46,12 @@ final_answer = FinalAnswerTool()
|
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
-
max_tokens=2096,
|
| 44 |
-
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 46 |
-
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
|
@@ -55,7 +60,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
@@ -65,5 +70,4 @@ agent = CodeAgent(
|
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Below is an example of a creative tool that generates emojis based on mood
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(mood: str) -> str: # it's important to specify the return type
|
| 13 |
+
"""A tool that returns a fun emoji sequence based on the given mood.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
mood: A mood like 'happy', 'sad', 'angry', or 'love'.
|
|
|
|
| 16 |
"""
|
| 17 |
+
emoji_dict = {
|
| 18 |
+
"happy": "😊🎉🌈✨😄",
|
| 19 |
+
"sad": "😢🌧️💔😭🕯️",
|
| 20 |
+
"angry": "😠🔥💢👿⚡",
|
| 21 |
+
"love": "😍❤️💌💘😘",
|
| 22 |
+
"tired": "😴💤☕😩🛌",
|
| 23 |
+
"excited": "🤩🚀🎊🥳💥",
|
| 24 |
+
}
|
| 25 |
+
return f"Mood: {mood}\nEmojis: {emoji_dict.get(mood.lower(), '🤖❓ Unknown mood ❓🤖')}"
|
| 26 |
|
| 27 |
@tool
|
| 28 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 46 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 47 |
|
| 48 |
model = HfApiModel(
|
| 49 |
+
max_tokens=2096,
|
| 50 |
+
temperature=0.5,
|
| 51 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
| 52 |
+
custom_role_conversions=None,
|
| 53 |
)
|
| 54 |
|
|
|
|
| 55 |
# Import tool from Hub
|
| 56 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 57 |
|
|
|
|
| 60 |
|
| 61 |
agent = CodeAgent(
|
| 62 |
model=model,
|
| 63 |
+
tools=[final_answer, my_custom_tool, get_current_time_in_timezone, image_generation_tool], # all tools listed
|
| 64 |
max_steps=6,
|
| 65 |
verbosity_level=1,
|
| 66 |
grammar=None,
|
|
|
|
| 70 |
prompt_templates=prompt_templates
|
| 71 |
)
|
| 72 |
|
| 73 |
+
GradioUI(agent).launch()
|
|
|