Spaces:
Running
Running
Update leaderboard
Browse files
app.py
CHANGED
@@ -5,7 +5,31 @@ import requests
|
|
5 |
import streamlit as st
|
6 |
import pandas as pd
|
7 |
|
8 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
def leaderboard_dashboard():
|
@@ -23,7 +47,7 @@ def leaderboard_dashboard():
|
|
23 |
""",
|
24 |
unsafe_allow_html=True,
|
25 |
)
|
26 |
-
|
27 |
|
28 |
# Add emojis based on the status
|
29 |
status_emojis = {
|
@@ -33,29 +57,60 @@ def leaderboard_dashboard():
|
|
33 |
'RUNNING': '🏃RUNNING'
|
34 |
}
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
if response.status_code != 200:
|
39 |
-
st.error("Failed to fetch
|
40 |
return
|
41 |
-
|
42 |
# Parse the response JSON data
|
43 |
-
|
44 |
# Convert the data to a DataFrame
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
# Sort the
|
49 |
-
|
50 |
|
51 |
-
front_order = ['
|
52 |
|
53 |
# move status column to the front
|
54 |
-
column_order = front_order + [column for column in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
st.write(leaderboard)
|
59 |
|
60 |
if __name__ == '__main__':
|
61 |
-
leaderboard_dashboard()
|
|
|
5 |
import streamlit as st
|
6 |
import pandas as pd
|
7 |
|
8 |
+
st.set_page_config(layout="wide")
|
9 |
+
|
10 |
+
import pandas as pd
|
11 |
+
import numpy as np
|
12 |
+
REMOTE_LEADERBOARD_URL = "https://dippy-bittensor-subnet.com/minerboard"
|
13 |
+
def iswin(score_i, score_j, block_i, block_j):
|
14 |
+
MAX_PENALTY = 0.03 # Adjust this value as needed
|
15 |
+
penalty = MAX_PENALTY
|
16 |
+
score_i = (1 - penalty) * score_i if block_i > block_j else score_i
|
17 |
+
score_j = (1 - penalty) * score_j if block_j > block_i else score_j
|
18 |
+
return score_i > score_j
|
19 |
+
|
20 |
+
def calculate_win_rate(df):
|
21 |
+
n = len(df)
|
22 |
+
win_counts = np.zeros(n)
|
23 |
+
|
24 |
+
for i in range(n):
|
25 |
+
for j in range(n):
|
26 |
+
if i != j:
|
27 |
+
if iswin(df.loc[i, 'total_score'], df.loc[j, 'total_score'],
|
28 |
+
df.loc[i, 'block'], df.loc[j, 'block']):
|
29 |
+
win_counts[i] += 1
|
30 |
+
|
31 |
+
return win_counts / (n - 1) # Divide by (n-1) as each row isn't compared with itself
|
32 |
+
|
33 |
|
34 |
|
35 |
def leaderboard_dashboard():
|
|
|
47 |
""",
|
48 |
unsafe_allow_html=True,
|
49 |
)
|
50 |
+
|
51 |
|
52 |
# Add emojis based on the status
|
53 |
status_emojis = {
|
|
|
57 |
'RUNNING': '🏃RUNNING'
|
58 |
}
|
59 |
|
60 |
+
|
61 |
+
# Get the minerboard data from the API
|
62 |
+
# response = requests.get("http://34.41.206.211:8000/minerboard")
|
63 |
+
response = requests.get(REMOTE_LEADERBOARD_URL)
|
64 |
if response.status_code != 200:
|
65 |
+
st.error("Failed to fetch minerboard data.")
|
66 |
return
|
67 |
+
|
68 |
# Parse the response JSON data
|
69 |
+
minerboard_data = response.json()
|
70 |
# Convert the data to a DataFrame
|
71 |
+
minerboard = pd.DataFrame(minerboard_data)
|
72 |
|
73 |
+
minerboard['status'] = minerboard['status'].map(lambda status: status_emojis.get(status, status))
|
74 |
+
# Sort the minerboard_winrate by the total_score column
|
75 |
+
minerboard = minerboard.sort_values(by='total_score', ascending=False, ignore_index=True)
|
76 |
|
77 |
+
front_order = ['uid', 'hotkey', 'total_score', 'status', 'chat_template_type', 'hash']
|
78 |
|
79 |
# move status column to the front
|
80 |
+
column_order = front_order + [column for column in minerboard.columns if column not in front_order]
|
81 |
+
|
82 |
+
minerboard = minerboard[column_order]
|
83 |
+
|
84 |
+
|
85 |
+
minerboard_winrate = pd.DataFrame(minerboard_data)
|
86 |
+
|
87 |
+
minerboard_winrate['status'] = minerboard_winrate['status'].map(lambda status: status_emojis.get(status, status))
|
88 |
|
89 |
+
minerboard_winrate['win_rate'] = calculate_win_rate(minerboard_winrate)
|
90 |
+
|
91 |
+
minerboard_winrate = minerboard_winrate.sort_values(by='win_rate', ascending=False, ignore_index=True)
|
92 |
+
|
93 |
+
column_order = ['uid', 'win_rate', 'hotkey', 'repo_namespace', 'repo_name', 'total_score', 'block', 'vibe_score', 'qualitative_score', 'creativity_score', 'coherence_score', 'model_size_score']
|
94 |
+
|
95 |
+
# Create a new DataFrame with only the specified columns
|
96 |
+
minerboard_winrate = minerboard_winrate[column_order]
|
97 |
+
st.header("Leaderboard by Win Rate ")
|
98 |
+
st.dataframe(minerboard_winrate, hide_index=True)
|
99 |
+
with st.expander("See detailed calculation method"):
|
100 |
+
st.write("The win rate is calculated by comparing each miner against every other miner. Note that this board is only an approximation as queued miners have a score of 0, validators are omitted, etc.")
|
101 |
+
st.code("""
|
102 |
+
Example of calculating a win:
|
103 |
+
def iswin(score_i, score_j, block_i, block_j):
|
104 |
+
penalty = 0.03
|
105 |
+
score_i = (1 - penalty) * score_i if block_i > block_j else score_i
|
106 |
+
score_j = (1 - penalty) * score_j if block_j > block_i else score_j
|
107 |
+
return score_i > score_j
|
108 |
+
""")
|
109 |
+
st.markdown("---")
|
110 |
+
st.header("Minerboard")
|
111 |
+
st.dataframe(minerboard, hide_index=True)
|
112 |
+
st.markdown("---")
|
113 |
|
|
|
114 |
|
115 |
if __name__ == '__main__':
|
116 |
+
leaderboard_dashboard()
|