Spaces:
Sleeping
Sleeping
test name nationality
Browse files
app.py
CHANGED
|
@@ -9,36 +9,33 @@ 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 |
-
A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
Returns:
|
| 18 |
-
A string with the
|
| 19 |
"""
|
| 20 |
import requests
|
| 21 |
try:
|
| 22 |
-
url = "https://api.
|
| 23 |
params = {
|
| 24 |
-
"
|
| 25 |
-
"language": "en",
|
| 26 |
-
"apiKey": "9kgcb14yVbcFQULH9tMpF-ZS0bDx9ISbP7oJEk_lcN7pbpWu",
|
| 27 |
-
"limit": 5 # Limit to 5 headlines
|
| 28 |
}
|
| 29 |
response = requests.get(url, params=params)
|
| 30 |
data = response.json()
|
| 31 |
if data.get("status") == "ok":
|
| 32 |
-
|
| 33 |
-
if
|
| 34 |
-
return f"Top
|
| 35 |
else:
|
| 36 |
-
return f"No
|
| 37 |
else:
|
| 38 |
-
return "Error fetching
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error fetching news: {str(e)}"
|
| 41 |
-
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 44 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -76,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
-
tools=[final_answer,
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_nationality_from_name(name: str) -> str:
|
| 13 |
"""
|
| 14 |
+
A tool that predict the nationality from a given name.
|
| 15 |
Args:
|
| 16 |
+
name: The name of the person to predict natiolnality.
|
| 17 |
Returns:
|
| 18 |
+
A string with the predicted nationality.
|
| 19 |
"""
|
| 20 |
import requests
|
| 21 |
try:
|
| 22 |
+
url = "https://api.nationalize.io"
|
| 23 |
params = {
|
| 24 |
+
"name": name
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
response = requests.get(url, params=params)
|
| 27 |
data = response.json()
|
| 28 |
if data.get("status") == "ok":
|
| 29 |
+
countries = [country["country_id"] for country in data.get("country", [])]
|
| 30 |
+
if countries:
|
| 31 |
+
return f"Top countries for {name}:\n" + "\n".join(countries)
|
| 32 |
else:
|
| 33 |
+
return f"No countries found for {name}."
|
| 34 |
else:
|
| 35 |
+
return "Error fetching date: " + data.get("message", "Unknown error")
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching news: {str(e)}"
|
| 38 |
+
#https://api.nationalize.io?name=nathaniel
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 41 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer, get_nationality_from_name], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|