kalekarnn commited on
Commit
c32d7de
·
verified ·
1 Parent(s): d57be3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
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
- print("result")
24
- print(result)
25
- if result and result.data:
26
- return result.data.priceUsd
27
- return "No price found"
 
28
  except Exception as e:
29
- return f"Error fetching currrency price for '{coin_name}'"
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: