Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,27 @@ 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 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def my_custom_tool(currency: str = "usd", amount: int = 1)-> str: #it's import to specify the return type
|
13 |
+
"""A tool that fetches the current Bitcoin price and calculates conversion
|
|
|
14 |
Args:
|
15 |
+
currency: The currency to get Bitcoin rate in (default: 'usd')
|
16 |
+
amount: The amount of Bitcoin to convert (default: 1.0)
|
17 |
"""
|
18 |
+
try:
|
19 |
+
# CoinGecko API endpoint for Bitcoin price
|
20 |
+
url = f"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies={currency.lower()}"
|
21 |
+
response = requests.get(url)
|
22 |
+
response.raise_for_status()
|
23 |
+
|
24 |
+
# Get the Bitcoin rate
|
25 |
+
btc_price = response.json()['bitcoin'][currency.lower()]
|
26 |
+
converted_amount = btc_price * amount
|
27 |
+
|
28 |
+
return f"{amount} Bitcoin = {converted_amount:,.2f} {currency.upper()} (Current BTC rate: {btc_price:,.2f} {currency.upper()})"
|
29 |
+
except requests.RequestException as e:
|
30 |
+
return f"Error fetching Bitcoin rate: {str(e)}"
|
31 |
+
except (KeyError, ValueError) as e:
|
32 |
+
return f"Error processing Bitcoin rate: {str(e)}"
|
33 |
|
34 |
@tool
|
35 |
def get_current_time_in_timezone(timezone: str) -> str:
|