Spaces:
Runtime error
Runtime error
Upload app.py
Browse filesThis my edited version of the original app.py, I have added some tools to my agent such as get a GDP of a country, web search tool or image generation tool
app.py
CHANGED
|
@@ -9,14 +9,25 @@ 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 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -35,6 +46,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -55,7 +67,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_gdp(country_iso_code: str, year: int) -> str:
|
| 13 |
+
"""Retrieves the GDP of a given country for a specified year in USD.
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
country_iso_code: The ISO 3166-1 alpha-3 code of the country (e.g., "FRA" for France, "USA" for United States).
|
| 17 |
+
year: The year for which to retrieve GDP data.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
The GDP of the country in the given year (in US dollars) or an error message.
|
| 21 |
"""
|
| 22 |
+
base_url = "https://api.worldbank.org/v2/country/{}/indicator/NY.GDP.MKTP.CD"
|
| 23 |
+
response = requests.get(base_url.format(country_iso_code), params={"date": year, "format": "json"})
|
| 24 |
+
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
data = response.json()
|
| 27 |
+
if data and len(data) > 1 and "value" in data[1][0]:
|
| 28 |
+
return f"GDP of {country_iso_code} in {year}: ${data[1][0]['value']:,} USD"
|
| 29 |
+
|
| 30 |
+
return "GDP data not available."
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
final_answer = FinalAnswerTool()
|
| 49 |
+
web_search_tool = DuckDuckGoSearchTool()
|
| 50 |
|
| 51 |
# 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:
|
| 52 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 67 |
|
| 68 |
agent = CodeAgent(
|
| 69 |
model=model,
|
| 70 |
+
tools=[final_answer, get_gdp, image_generation_tool, web_search_tool], ## add your tools here (don't remove final answer)
|
| 71 |
max_steps=6,
|
| 72 |
verbosity_level=1,
|
| 73 |
grammar=None,
|