Spaces:
Sleeping
Sleeping
created my custom function
Browse files
app.py
CHANGED
|
@@ -1,22 +1,43 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
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 does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
+
import json
|
| 5 |
import pytz
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 8 |
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 get_crypto_price_and_change(symbol: str) -> str:
|
| 13 |
+
"""A tool that fetches the current price and 24h variation of a cryptocurrency.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
symbol: The cryptocurrency symbol (e.g., bitcoin, ethereum, cardano).
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
url = f"https://api.coingecko.com/api/v3/simple/price?ids={symbol.lower()}&vs_currencies=usd&include_24hr_change=true"
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
response.raise_for_status()
|
| 21 |
+
data = response.json()
|
| 22 |
+
crypto_data = data.get(symbol.lower())
|
| 23 |
+
|
| 24 |
+
if crypto_data:
|
| 25 |
+
price = crypto_data.get("usd")
|
| 26 |
+
change_24h = crypto_data.get("usd_24h_change")
|
| 27 |
+
|
| 28 |
+
if price is not None and change_24h is not None:
|
| 29 |
+
return f"{symbol.upper()} price: ${price:.2f}, 24h change: {change_24h:.2f}%"
|
| 30 |
+
else:
|
| 31 |
+
return f"Could not retrieve price or 24h change for {symbol.upper()}."
|
| 32 |
+
else:
|
| 33 |
+
return f"Cryptocurrency symbol '{symbol.upper()}' not found."
|
| 34 |
+
|
| 35 |
+
except requests.exceptions.RequestException as e:
|
| 36 |
+
return f"Error fetching data: {e}"
|
| 37 |
+
except json.JSONDecodeError:
|
| 38 |
+
return "Error decoding JSON response."
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"An unexpected error occurred: {e}"
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|