Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,31 @@ 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 my_custom_tool(
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that fetches the weather for a provided
|
| 15 |
Args:
|
| 16 |
location_name: weather location
|
| 17 |
"""
|
| 18 |
api_key = "3MfEYSjmLMlWRZCbw7VSLhaGyptxpUYP"
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
url = f"http://dataservice.accuweather.com/currentconditions/v1/{location_key}?apikey={api_key}"
|
| 21 |
|
| 22 |
try:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(city:str, state:str, country="United States")-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that fetches the weather for a provided city and state. This tool only works for the united states
|
| 15 |
Args:
|
| 16 |
location_name: weather location
|
| 17 |
"""
|
| 18 |
api_key = "3MfEYSjmLMlWRZCbw7VSLhaGyptxpUYP"
|
| 19 |
+
|
| 20 |
+
url_city = f"http://dataservice.accuweather.com/locations/v1/cities/{country}/{state}/search"
|
| 21 |
+
params = {
|
| 22 |
+
"apikey": api_key,
|
| 23 |
+
"q": city,
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
response = responses.get(url_city, params=params)
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
data = response.json()
|
| 30 |
+
if data:
|
| 31 |
+
location_key = data[0]["Key"]
|
| 32 |
+
else:
|
| 33 |
+
return "No results found"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#location_key = "35341"
|
| 37 |
url = f"http://dataservice.accuweather.com/currentconditions/v1/{location_key}?apikey={api_key}"
|
| 38 |
|
| 39 |
try:
|