afght12 commited on
Commit
5a032ac
ยท
verified ยท
1 Parent(s): ae7a531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -34
app.py CHANGED
@@ -17,12 +17,12 @@ HEADER = """
17
  <p align="center">This leaderboard showcases the top-performing miners in the Synthia Commune Subnet. The models are ranked based on their daily rewards.</p>
18
  <p align="center">The Synthia subnet leverages Commune's incentives to create a permissionless mining market around distilling knowledge out of SOTA closed-source model APIs into a public dataset to accelerate the OpenSource AI space. Targeted models and strategy will adapt based on the current SOTA.</p>
19
  """
20
-
21
  EVALUATION_HEADER = """<h3 align="center">Evaluation Details</h3>"""
22
-
23
  EVALUATION_DETAILS = """<p align="center"><b>Name</b> represents the model name. <b>Rewards / Day</b> indicates the expected daily rewards for each model in <b>$COMAI</b>. <b>UID</b> is the unique identifier of the miner. <b>$USD Value</b> is the estimated dollar value of the daily rewards.</p>"""
24
- netuid = 3
25
  node_url = "wss://commune.api.onfinality.io/public-ws"
 
 
26
 
27
 
28
  def get_com_price() -> Any:
@@ -47,61 +47,74 @@ def get_com_price() -> Any:
47
  def make_query(client: CommuneClient) -> tuple[dict[int, int], dict[int, str]]:
48
  request_dict: dict[Any, Any] = {
49
  "SubspaceModule": [
50
- ("Name", [netuid]),
51
  ("Emission", []),
52
  ("Incentive", []),
53
  ("Dividends", []),
 
54
  ],
55
  }
 
56
  emission_dict: dict[int, int] = {}
57
  name_dict: dict[int, str] = {}
58
  result = client.query_batch_map(request_dict)
59
 
60
  emission = result["Emission"]
61
- netuid_emission = emission[netuid]
62
  incentive = result["Incentive"]
63
- netuid_incentive = incentive[netuid]
64
  dividends = result["Dividends"]
65
- netuid_dividends = dividends[netuid]
 
 
 
 
 
 
 
 
 
 
66
 
67
  names = result["Name"]
68
  highest_uid = max(names.keys())
69
  for uid in range(highest_uid + 1):
70
 
71
- emission = netuid_emission[uid]
72
-
 
73
  if emission != 0:
74
  incentive = netuid_incentive[uid]
75
  dividends = netuid_dividends[uid]
76
 
77
-
78
- emission_dict[uid] = netuid_emission[uid]
79
- name_dict[uid] = names[uid]
80
-
81
  return emission_dict, name_dict
82
 
83
 
84
  async def get_leaderboard_data():
85
  try:
86
  com_price = get_com_price()
87
- blocks_in_day = 10_800
88
  client = CommuneClient(node_url)
89
  emission_dict, name_dict = make_query(client)
90
  print("got tha emission")
91
- scores = {}
92
- for uid, emi in emission_dict.items():
93
- # we are doing ** 11 because emission are for modules have 2 extra units,
94
- # (otherwise it would be more intuive to do ** 9, hence from_nano)
95
- scores[uid] = (emi / 10**11) * blocks_in_day
96
- sorted_scores = sorted(
97
- scores.items(), key=lambda x: x[1], reverse=True)
 
98
  leaderboard_data = []
99
  for rank, (uid, score) in enumerate(sorted_scores, start=1):
100
  name = name_dict[uid]
101
  units = score
102
  usd_value = score * com_price
103
- leaderboard_data.append(
104
- (rank, uid, name, units, f"${usd_value:.2f}"))
105
  return leaderboard_data
106
  except Exception as e:
107
  print(f"Error fetching leaderboard data: {e}")
@@ -123,13 +136,16 @@ async def update_leaderboard_table():
123
  rewards_per_week = total_usd_value * 7
124
  rewards_per_month = total_usd_value * 30
125
 
126
- return leaderboard_data, f'''
 
 
127
  <div style="display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: bold;">
128
- <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™’๐™š๐™š๐™ : ${rewards_per_week:,.0f}</div>
129
- <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐˜ฟ๐™–๐™ฎ: ${total_usd_value:,.0f}</div>
130
- <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™ˆ๐™ค๐™ฃ๐™ฉ๐™: ${rewards_per_month:,.0f}</div>
131
  </div>
132
- '''
 
133
 
134
 
135
  stone_gray = Color(
@@ -203,13 +219,13 @@ with gr.Blocks(theme=seafoam, analytics_enabled=True) as demo:
203
 
204
  total_usd_value_html = gr.HTML(
205
  elem_id="total-usd-value",
206
- value='''
207
  <div style="display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: bold;">
208
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™’๐™š๐™š๐™ : $0.00</div>
209
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐˜ฟ๐™–๐™ฎ: $0.00</div>
210
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™ˆ๐™ค๐™ฃ๐™ฉ๐™: $0.00</div>
211
  </div>
212
- '''
213
  )
214
  leaderboard_table = gr.components.Dataframe(
215
  headers=["Rank ๐Ÿ†", "UID", "Name", "Rewards / Day", "$USD Value"],
@@ -219,12 +235,16 @@ with gr.Blocks(theme=seafoam, analytics_enabled=True) as demo:
219
  elem_id="leaderboard-table",
220
  )
221
  refresh_button = gr.Button("Refresh Leaderboard")
222
- refresh_button.click(fn=update_leaderboard_table, outputs=[
223
- leaderboard_table, total_usd_value_html])
 
224
 
225
  # Initial load of leaderboard data
226
- demo.load(update_leaderboard_table, inputs=None, outputs=[
227
- leaderboard_table, total_usd_value_html])
 
 
 
228
 
229
  if __name__ == "__main__":
230
  demo.launch()
 
17
  <p align="center">This leaderboard showcases the top-performing miners in the Synthia Commune Subnet. The models are ranked based on their daily rewards.</p>
18
  <p align="center">The Synthia subnet leverages Commune's incentives to create a permissionless mining market around distilling knowledge out of SOTA closed-source model APIs into a public dataset to accelerate the OpenSource AI space. Targeted models and strategy will adapt based on the current SOTA.</p>
19
  """
 
20
  EVALUATION_HEADER = """<h3 align="center">Evaluation Details</h3>"""
 
21
  EVALUATION_DETAILS = """<p align="center"><b>Name</b> represents the model name. <b>Rewards / Day</b> indicates the expected daily rewards for each model in <b>$COMAI</b>. <b>UID</b> is the unique identifier of the miner. <b>$USD Value</b> is the estimated dollar value of the daily rewards.</p>"""
22
+
23
  node_url = "wss://commune.api.onfinality.io/public-ws"
24
+ EMITTED_PER_DAY = 250_000
25
+ SYNTHIA_NETUID = 3
26
 
27
 
28
  def get_com_price() -> Any:
 
47
  def make_query(client: CommuneClient) -> tuple[dict[int, int], dict[int, str]]:
48
  request_dict: dict[Any, Any] = {
49
  "SubspaceModule": [
50
+ ("Name", [SYNTHIA_NETUID]),
51
  ("Emission", []),
52
  ("Incentive", []),
53
  ("Dividends", []),
54
+ ("SubnetEmission", []),
55
  ],
56
  }
57
+
58
  emission_dict: dict[int, int] = {}
59
  name_dict: dict[int, str] = {}
60
  result = client.query_batch_map(request_dict)
61
 
62
  emission = result["Emission"]
63
+ netuid_emission = emission[SYNTHIA_NETUID]
64
  incentive = result["Incentive"]
65
+ netuid_incentive = incentive[SYNTHIA_NETUID]
66
  dividends = result["Dividends"]
67
+ netuid_dividends = dividends[SYNTHIA_NETUID]
68
+ raw_s_emission = result["SubnetEmission"]
69
+
70
+ total_subnet_emission = sum(raw_s_emission.values())
71
+ subnet_emission = raw_s_emission[SYNTHIA_NETUID]
72
+
73
+ portion_of_emission = subnet_emission / total_subnet_emission
74
+
75
+ subnet_daily_distro = portion_of_emission * EMITTED_PER_DAY
76
+
77
+ all_emission = sum(netuid_emission)
78
 
79
  names = result["Name"]
80
  highest_uid = max(names.keys())
81
  for uid in range(highest_uid + 1):
82
 
83
+ raw_emission = netuid_emission[uid]
84
+ emission = (raw_emission / all_emission) * subnet_daily_distro
85
+
86
  if emission != 0:
87
  incentive = netuid_incentive[uid]
88
  dividends = netuid_dividends[uid]
89
 
90
+ if incentive > 0:
91
+ emission_dict[uid] = emission
92
+ name_dict[uid] = names[uid]
93
+
94
  return emission_dict, name_dict
95
 
96
 
97
  async def get_leaderboard_data():
98
  try:
99
  com_price = get_com_price()
100
+ # blocks_in_day = 10_800
101
  client = CommuneClient(node_url)
102
  emission_dict, name_dict = make_query(client)
103
  print("got tha emission")
104
+ # scores = {}
105
+ # for uid, emi in emission_dict.items():
106
+ # # we are doing ** 11 because emission are for modules have 2 extra units,
107
+ # # (otherwise it would be more intuive to do ** 9, hence from_nano)
108
+ # scores[uid] = emi
109
+ scores = emission_dict
110
+
111
+ sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
112
  leaderboard_data = []
113
  for rank, (uid, score) in enumerate(sorted_scores, start=1):
114
  name = name_dict[uid]
115
  units = score
116
  usd_value = score * com_price
117
+ leaderboard_data.append((rank, uid, name, units, f"${usd_value:.2f}"))
 
118
  return leaderboard_data
119
  except Exception as e:
120
  print(f"Error fetching leaderboard data: {e}")
 
136
  rewards_per_week = total_usd_value * 7
137
  rewards_per_month = total_usd_value * 30
138
 
139
+ return (
140
+ leaderboard_data,
141
+ f"""
142
  <div style="display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: bold;">
143
+ <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™’๐™š๐™š๐™ : ${rewards_per_week:,.2f}</div>
144
+ <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐˜ฟ๐™–๐™ฎ: ${total_usd_value:,.2f}</div>
145
+ <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™ˆ๐™ค๐™ฃ๐™ฉ๐™: ${rewards_per_month:,.2f}</div>
146
  </div>
147
+ """,
148
+ )
149
 
150
 
151
  stone_gray = Color(
 
219
 
220
  total_usd_value_html = gr.HTML(
221
  elem_id="total-usd-value",
222
+ value="""
223
  <div style="display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: bold;">
224
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™’๐™š๐™š๐™ : $0.00</div>
225
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐˜ฟ๐™–๐™ฎ: $0.00</div>
226
  <div>๐™๐™ค๐™ฉ๐™–๐™ก ๐™๐™Ž๐˜ฟ ๐™๐™š๐™ฌ๐™–๐™ง๐™™๐™จ ๐™‹๐™š๐™ง ๐™ˆ๐™ค๐™ฃ๐™ฉ๐™: $0.00</div>
227
  </div>
228
+ """,
229
  )
230
  leaderboard_table = gr.components.Dataframe(
231
  headers=["Rank ๐Ÿ†", "UID", "Name", "Rewards / Day", "$USD Value"],
 
235
  elem_id="leaderboard-table",
236
  )
237
  refresh_button = gr.Button("Refresh Leaderboard")
238
+ refresh_button.click(
239
+ fn=update_leaderboard_table, outputs=[leaderboard_table, total_usd_value_html]
240
+ )
241
 
242
  # Initial load of leaderboard data
243
+ demo.load(
244
+ update_leaderboard_table,
245
+ inputs=None,
246
+ outputs=[leaderboard_table, total_usd_value_html],
247
+ )
248
 
249
  if __name__ == "__main__":
250
  demo.launch()