Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,38 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import asyncio
|
4 |
from typing import Any
|
|
|
|
|
|
|
|
|
5 |
from communex.client import CommuneClient
|
6 |
from communex.balance import from_nano
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
netuid = 24
|
9 |
node_url = "wss://commune.api.onfinality.io/public-ws"
|
10 |
|
|
|
11 |
def get_com_price() -> Any:
|
12 |
retries = 5
|
13 |
for i in range(0, retries):
|
14 |
try:
|
15 |
-
price = float(
|
|
|
|
|
|
|
|
|
16 |
print(f"Fetched COM price: {price}")
|
17 |
return price
|
18 |
except Exception as e:
|
@@ -22,6 +43,7 @@ def get_com_price() -> Any:
|
|
22 |
asyncio.sleep(retries)
|
23 |
raise RuntimeError("Failed to fetch COM price")
|
24 |
|
|
|
25 |
async def get_leaderboard_data():
|
26 |
try:
|
27 |
com_price = get_com_price()
|
@@ -35,12 +57,13 @@ async def get_leaderboard_data():
|
|
35 |
sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
36 |
leaderboard_data = []
|
37 |
for rank, (uid, score) in enumerate(sorted_scores, start=1):
|
38 |
-
leaderboard_data.append((rank, uid, score))
|
39 |
return leaderboard_data
|
40 |
except Exception as e:
|
41 |
print(f"Error fetching leaderboard data: {e}")
|
42 |
return []
|
43 |
-
|
|
|
44 |
async def update_leaderboard_table():
|
45 |
leaderboard_data = await get_leaderboard_data()
|
46 |
# Convert tuples to lists
|
@@ -50,66 +73,85 @@ async def update_leaderboard_table():
|
|
50 |
row[0] = f"{row[0]} π"
|
51 |
return leaderboard_data
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
.
|
79 |
-
.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
.
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
""
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
leaderboard_table = gr.components.Dataframe(
|
107 |
-
headers=["Rank π", "User π", "Score
|
108 |
datatype=["str", "str", "str"],
|
109 |
interactive=False,
|
110 |
visible=True,
|
111 |
-
elem_id="leaderboard-table"
|
112 |
)
|
|
|
113 |
refresh_button = gr.Button("Refresh Leaderboard")
|
114 |
refresh_button.click(fn=update_leaderboard_table, outputs=leaderboard_table)
|
115 |
|
@@ -117,4 +159,4 @@ with gr.Blocks(css=custom_css) as demo:
|
|
117 |
demo.load(update_leaderboard_table, inputs=None, outputs=leaderboard_table)
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
-
demo.launch()
|
|
|
2 |
import requests
|
3 |
import asyncio
|
4 |
from typing import Any
|
5 |
+
from gradio.themes.base import Base
|
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 |
+
|
14 |
+
TITLE = """<h1 align="center" id="space-title" class="typewriter">Synthia Leaderboard</h1>"""
|
15 |
+
|
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 |
|
27 |
+
|
28 |
def get_com_price() -> Any:
|
29 |
retries = 5
|
30 |
for i in range(0, retries):
|
31 |
try:
|
32 |
+
price = float(
|
33 |
+
requests.get(
|
34 |
+
"https://api.mexc.com/api/v3/avgPrice?symbol=COMAIUSDT"
|
35 |
+
).json()["price"]
|
36 |
+
)
|
37 |
print(f"Fetched COM price: {price}")
|
38 |
return price
|
39 |
except Exception as e:
|
|
|
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()
|
|
|
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}")
|
64 |
return []
|
65 |
+
|
66 |
+
|
67 |
async def update_leaderboard_table():
|
68 |
leaderboard_data = await get_leaderboard_data()
|
69 |
# Convert tuples to lists
|
|
|
73 |
row[0] = f"{row[0]} π"
|
74 |
return leaderboard_data
|
75 |
|
76 |
+
|
77 |
+
white = Color(
|
78 |
+
name="white",
|
79 |
+
c50="#000000",
|
80 |
+
c100="#000000",
|
81 |
+
c200="#eeeeee",
|
82 |
+
c300="#e0e0e0",
|
83 |
+
c400="#000000",
|
84 |
+
c500="#cccccc",
|
85 |
+
c600="#b3b3b3",
|
86 |
+
c700="#000000",
|
87 |
+
c800="#f0f0f0",
|
88 |
+
c900="#e8e8e8",
|
89 |
+
c950="#e2e2e2",
|
90 |
+
)
|
91 |
+
|
92 |
+
|
93 |
+
class Seafoam(Base):
|
94 |
+
def __init__(
|
95 |
+
self,
|
96 |
+
*,
|
97 |
+
primary_hue: colors.Color | str = white,
|
98 |
+
secondary_hue: colors.Color | str = white,
|
99 |
+
neutral_hue: colors.Color | str = white,
|
100 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
101 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
102 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
103 |
+
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
104 |
+
fonts.GoogleFont("Quicksand"),
|
105 |
+
"ui-sans-serif",
|
106 |
+
"sans-serif",
|
107 |
+
),
|
108 |
+
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
|
109 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
110 |
+
"ui-monospace",
|
111 |
+
"monospace",
|
112 |
+
),
|
113 |
+
):
|
114 |
+
super().__init__(
|
115 |
+
primary_hue=primary_hue,
|
116 |
+
secondary_hue=secondary_hue,
|
117 |
+
neutral_hue=neutral_hue,
|
118 |
+
spacing_size=spacing_size,
|
119 |
+
radius_size=radius_size,
|
120 |
+
text_size=text_size,
|
121 |
+
font=font,
|
122 |
+
font_mono=font_mono,
|
123 |
+
)
|
124 |
+
super().set(
|
125 |
+
block_title_text_weight="600",
|
126 |
+
block_border_width="3px",
|
127 |
+
block_shadow="*shadow_drop_lg",
|
128 |
+
button_shadow="*shadow_drop_lg",
|
129 |
+
button_large_padding="32px",
|
130 |
+
button_primary_background_fill_hover="*button_primary_background_fill",
|
131 |
+
# Add the following lines to set the button colors
|
132 |
+
button_primary_background_fill="#333333", # Dark background color
|
133 |
+
button_primary_text_color="#ffffff", # White text color
|
134 |
+
)
|
135 |
+
|
136 |
+
|
137 |
+
seafoam = Seafoam()
|
138 |
+
|
139 |
+
with gr.Blocks(theme=seafoam, analytics_enabled=True) as demo:
|
140 |
+
gr.HTML(FONT)
|
141 |
+
gr.HTML(TITLE)
|
142 |
+
gr.HTML(IMAGE)
|
143 |
+
gr.HTML(HEADER)
|
144 |
+
gr.HTML(EVALUATION_HEADER)
|
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,
|
152 |
+
elem_id="leaderboard-table",
|
153 |
)
|
154 |
+
|
155 |
refresh_button = gr.Button("Refresh Leaderboard")
|
156 |
refresh_button.click(fn=update_leaderboard_table, outputs=leaderboard_table)
|
157 |
|
|
|
159 |
demo.load(update_leaderboard_table, inputs=None, outputs=leaderboard_table)
|
160 |
|
161 |
if __name__ == "__main__":
|
162 |
+
demo.launch()
|