mujtabarizvi commited on
Commit
b0488f6
·
verified ·
1 Parent(s): bdaa6f0
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -9,11 +9,14 @@ 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(symbol: str) -> str:
13
- """Get cryptocurrency price with basic error handling"""
 
 
 
14
  try:
15
  symbol = symbol.upper()
16
- # Using CoinGecko's simple API (no key needed)
17
  response = requests.get(
18
  f"https://api.coingecko.com/api/v3/simple/price?ids={symbol.lower()}&vs_currencies=usd",
19
  timeout=3
@@ -21,17 +24,12 @@ def get_crypto_price(symbol: str) -> str:
21
  data = response.json()
22
 
23
  if symbol.lower() in data and 'usd' in data[symbol.lower()]:
24
- price = "{:,.2f}".format(data[symbol.lower()]['usd'])
25
- return f"Current {symbol} price: ${price}"
26
 
27
  return f"Could not find price for {symbol} (try BTC/ETH/SOL)"
28
 
29
- except Exception as e:
30
- # Fallback to hardcoded prices if API fails
31
- default_prices = {'BTC': 63000, 'ETH': 3500, 'SOL': 150}
32
- if symbol in default_prices:
33
- return f"{symbol} price unavailable - Last known: ${default_prices[symbol]:,}"
34
- return f"Price check failed for {symbol}"
35
 
36
  @tool
37
  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
+ @tool
13
  def get_crypto_price(symbol: str) -> str:
14
+ """Get cryptocurrency price with basic error handling
15
+ Args:
16
+ symbol: The cryptocurrency symbol (e.g., 'BTC', 'ETH', 'SOL')
17
+ """
18
  try:
19
  symbol = symbol.upper()
 
20
  response = requests.get(
21
  f"https://api.coingecko.com/api/v3/simple/price?ids={symbol.lower()}&vs_currencies=usd",
22
  timeout=3
 
24
  data = response.json()
25
 
26
  if symbol.lower() in data and 'usd' in data[symbol.lower()]:
27
+ return f"Current {symbol} price: ${data[symbol.lower()]['usd']:,.2f}"
 
28
 
29
  return f"Could not find price for {symbol} (try BTC/ETH/SOL)"
30
 
31
+ except Exception:
32
+ return f"Price check service unavailable for {symbol}"
 
 
 
 
33
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str: