wphoenix commited on
Commit
a1aafdb
·
verified ·
1 Parent(s): 467c4aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -14,22 +14,7 @@ from Gradio_UI import GradioUI
14
  verbose = True
15
  if verbose: print("Running app.py")
16
 
17
- ################### UTILITY ###############################################
18
- def top_10_items_from_json(json_str: str) -> dict[str, int]:
19
- # Parse the JSON string into a dictionary
20
- data = json.loads(json_str)
21
-
22
- # Sort the dictionary by value in descending order
23
- sorted_items = sorted(data.items(), key=lambda item: item[1], reverse=True)
24
-
25
- # Get the top 10 items
26
- top_10 = sorted_items[:10]
27
-
28
- # Convert the list of tuples back into a dictionary
29
- top_10_dict = dict(top_10)
30
-
31
- return top_10_dict
32
- ################### END: UTILITY ###############################################
33
 
34
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
35
  @tool
@@ -44,10 +29,12 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's important to specify the ret
44
 
45
  @tool
46
  def fetch_active_crypto() -> Optional[Dict[str, Any]]:
47
- """A tool that fetches all active crypto by market cap in USD.
 
 
48
 
49
  Returns:
50
- Optional[Dict[str, Any]]: A dictionary containing the top 10 cryptocurrencies by market cap,
51
  or None if an error occurs.
52
  """
53
  # url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
@@ -74,8 +61,9 @@ def fetch_active_crypto() -> Optional[Dict[str, Any]]:
74
  # Extract the top 10 cryptocurrencies by market cap
75
  if 'data' in data:
76
  sorted_crypto = sorted(data['data'], key=lambda x: x['quote']['USD']['market_cap'], reverse=True)
77
- top_10 = sorted_crypto[:10]
78
- return {crypto['name']: crypto['quote']['USD'] for crypto in top_10}
 
79
  else:
80
  print("No data found in the response.")
81
  return None
 
14
  verbose = True
15
  if verbose: print("Running app.py")
16
 
17
+ #################################### TOOLS ###############################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
20
  @tool
 
29
 
30
  @tool
31
  def fetch_active_crypto() -> Optional[Dict[str, Any]]:
32
+ """A tool that fetches all active crypto by market cap in USD.
33
+ This can also be used when a specific crypto is required, then filter by that crypto name to get the
34
+ data for the specific ticker.
35
 
36
  Returns:
37
+ Optional[Dict[str, Any]]: A dictionary containing cryptocurrencies by market cap,
38
  or None if an error occurs.
39
  """
40
  # url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
 
61
  # Extract the top 10 cryptocurrencies by market cap
62
  if 'data' in data:
63
  sorted_crypto = sorted(data['data'], key=lambda x: x['quote']['USD']['market_cap'], reverse=True)
64
+ # top_10 = sorted_crypto[:10]
65
+ # return {crypto['name']: crypto['quote']['USD'] for crypto in top_10}
66
+ return {crypto['name']: crypto['quote']['USD'] for crypto in sorted_crypto}
67
  else:
68
  print("No data found in the response.")
69
  return None