wphoenix commited on
Commit
14378c6
·
verified ·
1 Parent(s): 75c3bd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -13,6 +13,22 @@ from Gradio_UI import GradioUI
13
  verbose = True
14
  if verbose: print("Running app.py")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
18
  @tool
@@ -47,7 +63,7 @@ def fetch_active_crypto()-> str: #it's important to specify the return type
47
  try:
48
  response = session.get(url, params=parameters)
49
  data = json.loads(response.text)
50
- return data
51
  except (ConnectionError, Timeout, TooManyRedirects) as e:
52
  return e
53
 
@@ -124,7 +140,7 @@ if verbose: print("Checking available models.")
124
  selected_model_id = get_available_model()
125
 
126
  model = HfApiModel(
127
- max_tokens=104800000,
128
  temperature=0.5,
129
  #model_id='meta-llama/Llama-3.2-1B-Instruct',
130
  #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
 
13
  verbose = True
14
  if verbose: print("Running app.py")
15
 
16
+ ################### UTILITY ###############################################
17
+ def top_10_items_from_json(json_str: str) -> dict[str, int]:
18
+ # Parse the JSON string into a dictionary
19
+ data = json.loads(json_str)
20
+
21
+ # Sort the dictionary by value in descending order
22
+ sorted_items = sorted(data.items(), key=lambda item: item[1], reverse=True)
23
+
24
+ # Get the top 10 items
25
+ top_10 = sorted_items[:10]
26
+
27
+ # Convert the list of tuples back into a dictionary
28
+ top_10_dict = dict(top_10)
29
+
30
+ return top_10_dict
31
+ ################### END: UTILITY ###############################################
32
 
33
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
34
  @tool
 
63
  try:
64
  response = session.get(url, params=parameters)
65
  data = json.loads(response.text)
66
+ return str(top_10_items_from_json(data))
67
  except (ConnectionError, Timeout, TooManyRedirects) as e:
68
  return e
69
 
 
140
  selected_model_id = get_available_model()
141
 
142
  model = HfApiModel(
143
+ max_tokens=16000,
144
  temperature=0.5,
145
  #model_id='meta-llama/Llama-3.2-1B-Instruct',
146
  #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',