Spaces:
Sleeping
Sleeping
Added my format_country_info tool in app.py, modified tools list used by the agent. Added tabulate in requirements.txt
Browse files- app.py +47 -18
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,22 +1,47 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
-
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -36,30 +61,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
| 39 |
-
max_tokens=2096,
|
| 40 |
-
temperature=0.5,
|
| 41 |
-
model_id=
|
| 42 |
-
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
| 45 |
|
| 46 |
# Import tool from Hub
|
| 47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
| 49 |
-
with open("prompts.yaml",
|
| 50 |
prompt_templates = yaml.safe_load(stream)
|
| 51 |
-
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
| 58 |
planning_interval=None,
|
| 59 |
name=None,
|
| 60 |
description=None,
|
| 61 |
-
prompt_templates=prompt_templates
|
| 62 |
)
|
| 63 |
|
| 64 |
|
| 65 |
-
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
+
|
| 6 |
+
import pandas
|
| 7 |
+
|
| 8 |
+
from typing import List
|
| 9 |
+
|
| 10 |
from tools.final_answer import FinalAnswerTool
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
| 14 |
+
|
| 15 |
@tool
|
| 16 |
+
def format_country_info(
|
| 17 |
+
population: int, languages: List[str], religions: List[str]
|
| 18 |
+
) -> str:
|
| 19 |
+
"""A tool that takes as argument the most recent info about a country and most specifically
|
| 20 |
+
the population number, the officially languages (accompanied and sorted by their respective percentage) used
|
| 21 |
+
as well as the common religions (accompanied and sorted by their respective percentage) found in the country.
|
| 22 |
+
It returns the same info formatted in markdown.
|
| 23 |
+
For any info field that is not available, its value is considered as N/A
|
| 24 |
Args:
|
| 25 |
+
population: the country's population number according to most recent info
|
| 26 |
+
languages: the languages used in the country
|
| 27 |
+
religions: the religions found in the country
|
| 28 |
+
|
| 29 |
"""
|
| 30 |
+
summary_info = {
|
| 31 |
+
"Population": population if population > 0 else "N/A",
|
| 32 |
+
"Languages": "<br>".join(
|
| 33 |
+
[f"- {lang}" for lang in languages] if len(languages) > 1 else languages
|
| 34 |
+
)
|
| 35 |
+
or "N/A",
|
| 36 |
+
"Religions": "<br>".join(
|
| 37 |
+
[f"- {rel}" for rel in religions] if len(religions) > 1 else religions
|
| 38 |
+
)
|
| 39 |
+
or "N/A",
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
df = pandas.DataFrame(summary_info, index=[1])
|
| 43 |
+
return df.to_markdown(index=False)
|
| 44 |
+
|
| 45 |
|
| 46 |
@tool
|
| 47 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 61 |
|
| 62 |
final_answer = FinalAnswerTool()
|
| 63 |
model = HfApiModel(
|
| 64 |
+
max_tokens=2096,
|
| 65 |
+
temperature=0.5,
|
| 66 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 67 |
+
custom_role_conversions=None,
|
| 68 |
)
|
| 69 |
|
| 70 |
|
| 71 |
# Import tool from Hub
|
| 72 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 73 |
|
| 74 |
+
with open("prompts.yaml", "r") as stream:
|
| 75 |
prompt_templates = yaml.safe_load(stream)
|
| 76 |
+
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[
|
| 80 |
+
final_answer,
|
| 81 |
+
DuckDuckGoSearchTool(),
|
| 82 |
+
format_country_info,
|
| 83 |
+
], ## add your tools here (don't remove final answer)
|
| 84 |
max_steps=6,
|
| 85 |
verbosity_level=1,
|
| 86 |
grammar=None,
|
| 87 |
planning_interval=None,
|
| 88 |
name=None,
|
| 89 |
description=None,
|
| 90 |
+
prompt_templates=prompt_templates,
|
| 91 |
)
|
| 92 |
|
| 93 |
|
| 94 |
+
GradioUI(agent).launch()
|
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
tabulate
|