Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ from tools.final_answer import FinalAnswerTool
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
|
|
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
def get_domain_name(email:str)-> str: #it's import to specify the return type
|
|
@@ -41,6 +43,40 @@ def generate_jokes(joke_type:str)-> str: #it's import to specify the return type
|
|
| 41 |
|
| 42 |
return f'The joke is: {joke}'
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 46 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -79,7 +115,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 79 |
|
| 80 |
agent = CodeAgent(
|
| 81 |
model=model,
|
| 82 |
-
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_tool, get_domain_name, generate_jokes], ## add your tools here (don't remove final answer)
|
| 83 |
max_steps=6,
|
| 84 |
verbosity_level=1,
|
| 85 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
+
weather_api_key = os.getenv("weather_api_key")
|
| 13 |
+
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def get_domain_name(email:str)-> str: #it's import to specify the return type
|
|
|
|
| 43 |
|
| 44 |
return f'The joke is: {joke}'
|
| 45 |
|
| 46 |
+
@tool
|
| 47 |
+
def get_weather(location:str, units:str="imperial")->str:
|
| 48 |
+
"""
|
| 49 |
+
A tool that gets current weather for the specified location. Location has to be a city.
|
| 50 |
+
Args:
|
| 51 |
+
location: a string that specifies a location.
|
| 52 |
+
units: a string that specifies measuring units. Two are accepted "metric" meaning Celcius and "imperial"
|
| 53 |
+
meaning Fahrenheit. The default value is "imperial"
|
| 54 |
+
"""
|
| 55 |
+
url = f"http://api.openweathermap.org/geo/1.0/direct?limit=5"
|
| 56 |
+
params = {
|
| 57 |
+
"q": location,
|
| 58 |
+
"appid": weather_api_key,
|
| 59 |
+
}
|
| 60 |
+
# retrieve latitude and longuitude
|
| 61 |
+
response = requests.get(url, params=params)
|
| 62 |
+
resp = response.json()
|
| 63 |
+
params = {
|
| 64 |
+
"lat": resp[0]['lat'],
|
| 65 |
+
"appid": weather_api_key,
|
| 66 |
+
"units": units,
|
| 67 |
+
"lon": resp[0]['lon']
|
| 68 |
+
}
|
| 69 |
+
weather_url = f'https://api.openweathermap.org/data/2.5/weather?'
|
| 70 |
+
response_weather = requests.get(weather_url, params=params)
|
| 71 |
+
resp_weather = response_weather.json()
|
| 72 |
+
combined_dictionary = {'description': resp_weather['weather'][0]['description']}
|
| 73 |
+
result = {key: resp_weather['main'][key]
|
| 74 |
+
for key in resp_weather['main'].keys() if key not in ['grnd_level', 'sea_level']}
|
| 75 |
+
combined_dictionary.update({'units': units})
|
| 76 |
+
combined_dictionary.update(result)
|
| 77 |
+
|
| 78 |
+
return combined_dictionary
|
| 79 |
+
|
| 80 |
@tool
|
| 81 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 82 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 115 |
|
| 116 |
agent = CodeAgent(
|
| 117 |
model=model,
|
| 118 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_tool, get_domain_name, get_weather, generate_jokes], ## add your tools here (don't remove final answer)
|
| 119 |
max_steps=6,
|
| 120 |
verbosity_level=1,
|
| 121 |
grammar=None,
|