Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,45 +7,6 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
@tool
|
| 11 |
-
def get_weather(location: str)-> str:
|
| 12 |
-
"""A tool that fetches the weather.
|
| 13 |
-
Args:
|
| 14 |
-
location: A string representing a valid location (e.g., 'San Diego, California', 'New York')
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
places = {
|
| 18 |
-
"New York": {
|
| 19 |
-
"lon": 40.730610,
|
| 20 |
-
"lat": -73.935242
|
| 21 |
-
},
|
| 22 |
-
"Richmond, Virginia": {
|
| 23 |
-
"lon": 37.5407,
|
| 24 |
-
"lat": 77.4360
|
| 25 |
-
},
|
| 26 |
-
"San Diego, California": {
|
| 27 |
-
"lon": 32.7157,
|
| 28 |
-
"lat": 117.1611
|
| 29 |
-
}
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
lon = ""
|
| 33 |
-
lat = ""
|
| 34 |
-
|
| 35 |
-
for place in places:
|
| 36 |
-
if place.lower() in location.lower():
|
| 37 |
-
lon = place['lon']
|
| 38 |
-
lat = place['lat']
|
| 39 |
-
|
| 40 |
-
url = f'https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=currently,minutely,hourly,alert&appid=6969cb0fa02ea908feee8820d3a22689'
|
| 41 |
-
try:
|
| 42 |
-
weather_status = requests.get(url)
|
| 43 |
-
return weather_status['daily'][0]['summary']
|
| 44 |
-
|
| 45 |
-
except error:
|
| 46 |
-
return f"Error fetching weather for {location} passed"
|
| 47 |
-
|
| 48 |
-
|
| 49 |
@tool
|
| 50 |
def get_gas_fee_estimate(start: str, end: str)-> str: #it's import to specify the return type
|
| 51 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
@@ -67,6 +28,61 @@ def get_gas_fee_estimate(start: str, end: str)-> str: #it's import to specify th
|
|
| 67 |
return f"The estimated gas fee is {response['result']}"
|
| 68 |
except error:
|
| 69 |
return f"Error trying to process given wallet addresses {start} and/or {end}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
@tool
|
|
@@ -106,7 +122,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 106 |
|
| 107 |
agent = CodeAgent(
|
| 108 |
model=model,
|
| 109 |
-
tools=[get_current_time_in_timezone,get_weather,
|
| 110 |
max_steps=6,
|
| 111 |
verbosity_level=1,
|
| 112 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
@tool
|
| 11 |
def get_gas_fee_estimate(start: str, end: str)-> str: #it's import to specify the return type
|
| 12 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
|
| 28 |
return f"The estimated gas fee is {response['result']}"
|
| 29 |
except error:
|
| 30 |
return f"Error trying to process given wallet addresses {start} and/or {end}"
|
| 31 |
+
@tool
|
| 32 |
+
def get_asset_price(asset: str, base_curr: str):
|
| 33 |
+
|
| 34 |
+
"""A tool that gets the current price of a given digital asset
|
| 35 |
+
Args:
|
| 36 |
+
asset: A string representing a valid digital asset name (e.g., ethereum)
|
| 37 |
+
base_curr: A string that represents a valid base currency (e.g., usd).
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
url = "https://api.coingecko.com/api/v3/simple/price"
|
| 41 |
+
params = {
|
| 42 |
+
"ids": asset,
|
| 43 |
+
"vs_currencies": base_curr
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
response = requests.get(url, params=params)
|
| 47 |
+
if response.status_code == 200:
|
| 48 |
+
data = response.json()
|
| 49 |
+
price = data[asset][base_curr]
|
| 50 |
+
return f"Current {asset} price: ${price}"
|
| 51 |
+
else:
|
| 52 |
+
return f"Error: {response.status_code}, {response.text}"
|
| 53 |
+
|
| 54 |
+
@tool
|
| 55 |
+
def get_weather_weatherapi(city: str, state: str) -> str:
|
| 56 |
+
"""A tool that gets the current weather
|
| 57 |
+
Args:
|
| 58 |
+
city: A string that represents a valid city name
|
| 59 |
+
state: A String that represents a valid state name
|
| 60 |
+
"""
|
| 61 |
+
api_key = "dbe243d225564a6d8fc195119250406"
|
| 62 |
+
location = f"{city},{state}"
|
| 63 |
+
url = f"http://api.weatherapi.com/v1/current.json"
|
| 64 |
+
|
| 65 |
+
params = {
|
| 66 |
+
"key": api_key,
|
| 67 |
+
"q": location
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
response = requests.get(url, params=params)
|
| 72 |
+
data = response.json()
|
| 73 |
+
|
| 74 |
+
if response.status_code != 200:
|
| 75 |
+
return f"API Error: {data.get('error', {}).get('message', 'Unknown error')}"
|
| 76 |
+
|
| 77 |
+
temp = data["current"]["temp_f"]
|
| 78 |
+
condition = data["current"]["condition"]["text"]
|
| 79 |
+
name = data["location"]["name"]
|
| 80 |
+
region = data["location"]["region"]
|
| 81 |
+
|
| 82 |
+
return f"The current weather in {name}, {region} is {temp}°F with {condition}."
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
return f"Error: {e}"
|
| 86 |
|
| 87 |
|
| 88 |
@tool
|
|
|
|
| 122 |
|
| 123 |
agent = CodeAgent(
|
| 124 |
model=model,
|
| 125 |
+
tools=[get_current_time_in_timezone,get_weather, get_asset_price, DuckDuckGoSearchTool(), final_answer], ## add your tools here (don't remove final answer)
|
| 126 |
max_steps=6,
|
| 127 |
verbosity_level=1,
|
| 128 |
grammar=None,
|