afght12 commited on
Commit
04fe107
Β·
verified Β·
1 Parent(s): 526fa85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -9
app.py CHANGED
@@ -7,7 +7,6 @@ from gradio.themes.utils import colors, fonts, sizes
7
  from gradio.themes.utils.colors import Color
8
  from typing import Iterable
9
  from communex.client import CommuneClient
10
- from communex.balance import from_nano
11
 
12
  FONT = """<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">"""
13
 
@@ -16,11 +15,11 @@ TITLE = """<h1 align="center" id="space-title" class="typewriter">Synthia Leader
16
  IMAGE = """<a href="https://www.communeai.org/commune-logo.svg" target="_blank"><img src="https://www.communeai.org/commune-logo.svg" alt="Synthia Logo" style="margin: auto; width: 20%; border: 0;" /></a>"""
17
 
18
  HEADER = """<h2 align="center" class="typewriter">Welcome to the Synthia Leaderboard!</h2>
19
- <p align="center">This leaderboard showcases the top-performing models in the Synthia competition. The models are ranked based on their daily rewards and perplexity scores.</p>"""
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. <b>Perplexity</b> represents the model's performance on the evaluation data (lower is better). <b>UID</b> is the unique identifier of the model submitter. <b>Block</b> represents the block number when the model was submitted.</p>"""
24
  netuid = 24
25
  node_url = "wss://commune.api.onfinality.io/public-ws"
26
 
@@ -40,24 +39,50 @@ def get_com_price() -> Any:
40
  print(f"Error fetching COM price: {e}")
41
  if i == retries - 1:
42
  raise
43
- asyncio.sleep(retries)
44
  raise RuntimeError("Failed to fetch COM price")
45
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  async def get_leaderboard_data():
48
  try:
49
  com_price = get_com_price()
50
  blocks_in_day = 10_800
51
  client = CommuneClient(node_url)
52
- emission = client.query("Emission", params=[netuid])
53
  print("got tha emission")
54
  scores = {}
55
- for uid, emi in enumerate(emission):
56
- scores[uid] = ((emi / 10**11) * blocks_in_day) * com_price
 
 
57
  sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
58
  leaderboard_data = []
59
  for rank, (uid, score) in enumerate(sorted_scores, start=1):
60
- leaderboard_data.append((rank, uid, f"${score:.2f}"))
 
 
 
61
  return leaderboard_data
62
  except Exception as e:
63
  print(f"Error fetching leaderboard data: {e}")
@@ -145,7 +170,7 @@ with gr.Blocks(theme=seafoam, analytics_enabled=True) as demo:
145
  gr.HTML(EVALUATION_DETAILS)
146
 
147
  leaderboard_table = gr.components.Dataframe(
148
- headers=["Rank πŸ†", "User πŸ˜„", "Score πŸ’°"],
149
  datatype=["str", "str", "str"],
150
  interactive=False,
151
  visible=True,
 
7
  from gradio.themes.utils.colors import Color
8
  from typing import Iterable
9
  from communex.client import CommuneClient
 
10
 
11
  FONT = """<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">"""
12
 
 
15
  IMAGE = """<a href="https://www.communeai.org/commune-logo.svg" target="_blank"><img src="https://www.communeai.org/commune-logo.svg" alt="Synthia Logo" style="margin: auto; width: 20%; border: 0;" /></a>"""
16
 
17
  HEADER = """<h2 align="center" class="typewriter">Welcome to the Synthia Leaderboard!</h2>
18
+ <p align="center">This leaderboard showcases the top-performing models in the Synthia Subnet. The models are ranked based on their daily rewards.</p>"""
19
 
20
  EVALUATION_HEADER = """<h3 align="center">Evaluation Details</h3>"""
21
 
22
+ 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 $COMAI. <b>UID</b> is the unique identifier of the model submitter. <b>$USD Value</b> is the estimated dollar value of the daily rewards.</p>"""
23
  netuid = 24
24
  node_url = "wss://commune.api.onfinality.io/public-ws"
25
 
 
39
  print(f"Error fetching COM price: {e}")
40
  if i == retries - 1:
41
  raise
42
+ _ = asyncio.sleep(retries)
43
  raise RuntimeError("Failed to fetch COM price")
44
 
45
 
46
+ def make_query(client: CommuneClient) -> tuple[dict[int, int], dict[int, str]]:
47
+ request_dict: dict[Any, Any] = {
48
+ "SubspaceModule": [
49
+ ("Name", [netuid]),
50
+ ("Emission", []),
51
+ ],
52
+ }
53
+ emission_dict: dict[int, int] = {}
54
+ name_dict: dict[int, str] = {}
55
+ result = client.query_batch_map(request_dict)
56
+ emission = result["Emission"]
57
+ netuid_emission = emission[netuid]
58
+ names = result["Name"]
59
+ highest_uid = max(names.keys())
60
+ for uid in range(highest_uid + 1):
61
+ emission_dict[uid] = netuid_emission[uid]
62
+ name_dict[uid] = names[uid]
63
+
64
+ return emission_dict, name_dict
65
+
66
+
67
  async def get_leaderboard_data():
68
  try:
69
  com_price = get_com_price()
70
  blocks_in_day = 10_800
71
  client = CommuneClient(node_url)
72
+ emission_dict, name_dict = make_query(client)
73
  print("got tha emission")
74
  scores = {}
75
+ for uid, emi in emission_dict.items():
76
+ # we are doing ** 11 because emission are for modules have 2 extra units,
77
+ # (otherwise it would be more intuive to do ** 9, hence from_nano)
78
+ scores[uid] = (emi / 10**11) * blocks_in_day
79
  sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
80
  leaderboard_data = []
81
  for rank, (uid, score) in enumerate(sorted_scores, start=1):
82
+ name = name_dict[uid]
83
+ units = score
84
+ usd_value = score * com_price
85
+ leaderboard_data.append((rank, uid, name, units, f"${usd_value:.2f}"))
86
  return leaderboard_data
87
  except Exception as e:
88
  print(f"Error fetching leaderboard data: {e}")
 
170
  gr.HTML(EVALUATION_DETAILS)
171
 
172
  leaderboard_table = gr.components.Dataframe(
173
+ headers=["Rank πŸ†", "UID", "Name", "Rewards / Day", "$USD Value"],
174
  datatype=["str", "str", "str"],
175
  interactive=False,
176
  visible=True,