Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,24 +9,23 @@ 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 crypto_currency_price(coin_name:str)-> str:
|
| 13 |
-
"""A tool that fetch the crypto currency price of the specified coin_name
|
| 14 |
Args:
|
| 15 |
coin_name: A string representing a name of the crypto currency coin whose price needs to be fetched.
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
endpoint = f"https://api.coincap.io/v2/assets/{coin_name}"
|
| 19 |
-
print(endpoint)
|
| 20 |
response = requests.get(endpoint)
|
| 21 |
-
print(response)
|
| 22 |
result = response.json()
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
return
|
| 30 |
|
| 31 |
@tool
|
| 32 |
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 crypto_currency_price(coin_name: str) -> str:
|
| 13 |
+
"""A tool that fetch the crypto currency price of the specified coin_name
|
| 14 |
Args:
|
| 15 |
coin_name: A string representing a name of the crypto currency coin whose price needs to be fetched.
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
endpoint = f"https://api.coincap.io/v2/assets/{coin_name}"
|
|
|
|
| 19 |
response = requests.get(endpoint)
|
|
|
|
| 20 |
result = response.json()
|
| 21 |
+
|
| 22 |
+
if "data" in result and "priceUsd" in result["data"]:
|
| 23 |
+
price = float(result["data"]["priceUsd"])
|
| 24 |
+
formatted_price = f"${price:.2f}"
|
| 25 |
+
return f"The current price of {coin_name} is {formatted_price} USD"
|
| 26 |
+
return f"No price found for {coin_name}"
|
| 27 |
except Exception as e:
|
| 28 |
+
return f"Error fetching currency price for '{coin_name}': {str(e)}"
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|