Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,41 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 17 |
arg2: the second argument
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 17 |
arg2: the second argument
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
+
|
| 21 |
+
@tool
|
| 22 |
+
def get_country_economics(country_code: str) -> str:
|
| 23 |
+
"""Fetches basic economic data for a country using World Bank's API.
|
| 24 |
+
Args:
|
| 25 |
+
country_code: The ISO 3166-1 alpha-3 country code (e.g., 'USA' for United States, 'IND' for India).
|
| 26 |
+
"""
|
| 27 |
+
try:
|
| 28 |
+
# Fetch GDP (current US$)
|
| 29 |
+
gdp_url = f"http://api.worldbank.org/v2/country/{country_code}/indicator/NY.GDP.MKTP.CD?format=json&per_page=1"
|
| 30 |
+
gdp_response = requests.get(gdp_url).json()
|
| 31 |
+
gdp_value = gdp_response[1][0]['value']
|
| 32 |
+
gdp_year = gdp_response[1][0]['date']
|
| 33 |
+
|
| 34 |
+
# Fetch population
|
| 35 |
+
pop_url = f"http://api.worldbank.org/v2/country/{country_code}/indicator/SP.POP.TOTL?format=json&per_page=1"
|
| 36 |
+
pop_response = requests.get(pop_url).json()
|
| 37 |
+
pop_value = pop_response[1][0]['value']
|
| 38 |
+
pop_year = pop_response[1][0]['date']
|
| 39 |
+
|
| 40 |
+
if gdp_value is None or pop_value is None:
|
| 41 |
+
return f"Data unavailable for country code '{country_code}'. Try a different one like 'USA', 'CHN', or 'IND'."
|
| 42 |
+
|
| 43 |
+
gdp_per_capita = gdp_value / pop_value
|
| 44 |
+
return (
|
| 45 |
+
f"Economic data for {country_code}:\n"
|
| 46 |
+
f"• Year: {gdp_year}\n"
|
| 47 |
+
f"• GDP: ${gdp_value:,.2f} USD\n"
|
| 48 |
+
f"• Population: {pop_value:,}\n"
|
| 49 |
+
f"• GDP per Capita: ${gdp_per_capita:,.2f}"
|
| 50 |
+
)
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"Failed to fetch economic data for '{country_code}': {str(e)}"
|
| 53 |
|
| 54 |
+
|
| 55 |
@tool
|
| 56 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 57 |
"""A tool that fetches the current local time in a specified timezone.
|