Spaces:
Build error
Build error
initial sn58
Browse files
app.py
CHANGED
|
@@ -1,4 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Streamlit dashboard for the Dippy Speech Subnet Leaderboard
|
| 3 |
+
"""
|
| 4 |
+
import requests
|
| 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://vsapi.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():
|
| 36 |
+
# load the logo from image.txt file as base64
|
| 37 |
+
with open("image.txt", "r") as f:
|
| 38 |
+
image = f.read()
|
| 39 |
+
|
| 40 |
+
st.markdown(
|
| 41 |
+
f"""
|
| 42 |
+
<div style="text-align: center;">
|
| 43 |
+
<img src="data:image/png;base64,{image}" alt="Dippy Roleplay Logo" width="600" height="300" style="margin-bottom: 2rem;">
|
| 44 |
+
<h1 style="margin-top: 0;">SN58-Dippy-Speech Leaderboard</h1>
|
| 45 |
+
<div style="font-size: 18px;">This is the leaderboard for the Dippy voice validation API hosted by SN58.</div>
|
| 46 |
+
</div>
|
| 47 |
+
""",
|
| 48 |
+
unsafe_allow_html=True,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# Add emojis based on the status
|
| 53 |
+
status_emojis = {
|
| 54 |
+
'COMPLETED': '✅COMPLETED',
|
| 55 |
+
'FAILED': '❌FAILED',
|
| 56 |
+
'QUEUED': '🕒QUEUED',
|
| 57 |
+
'RUNNING': '🏃RUNNING'
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# Get the minerboard data from the API
|
| 62 |
+
response = requests.get(REMOTE_LEADERBOARD_URL)
|
| 63 |
+
if response.status_code != 200:
|
| 64 |
+
st.error("Failed to fetch minerboard data.")
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
# Parse the response JSON data
|
| 68 |
+
minerboard_data = response.json()
|
| 69 |
+
if len(minerboard_data) < 1:
|
| 70 |
+
st.markdown(
|
| 71 |
+
f"""
|
| 72 |
+
<div style="text-align: center;">
|
| 73 |
+
<h2 style="margin-top: 0;">In progress!</h2>
|
| 74 |
+
</div>
|
| 75 |
+
""",
|
| 76 |
+
unsafe_allow_html=True,
|
| 77 |
+
)
|
| 78 |
+
return
|
| 79 |
+
# Convert the data to a DataFrame
|
| 80 |
+
minerboard = pd.DataFrame(minerboard_data)
|
| 81 |
+
|
| 82 |
+
minerboard['status'] = minerboard['status'].map(lambda status: status_emojis.get(status, status))
|
| 83 |
+
# Sort the minerboard_winrate by the total_score column
|
| 84 |
+
minerboard = minerboard.sort_values(by='total_score', ascending=False, ignore_index=True)
|
| 85 |
+
|
| 86 |
+
front_order = ['uid', 'hotkey', 'total_score', 'status', 'hash']
|
| 87 |
+
|
| 88 |
+
# move status column to the front
|
| 89 |
+
column_order = front_order + [column for column in minerboard.columns if column not in front_order]
|
| 90 |
+
|
| 91 |
+
minerboard = minerboard[column_order]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
minerboard_winrate = pd.DataFrame(minerboard_data)
|
| 95 |
+
|
| 96 |
+
minerboard_winrate['status'] = minerboard_winrate['status'].map(lambda status: status_emojis.get(status, status))
|
| 97 |
+
|
| 98 |
+
minerboard_winrate['win_rate'] = calculate_win_rate(minerboard_winrate)
|
| 99 |
+
|
| 100 |
+
minerboard_winrate = minerboard_winrate.sort_values(by='win_rate', ascending=False, ignore_index=True)
|
| 101 |
+
|
| 102 |
+
column_order = ['uid', 'win_rate', 'hotkey', 'hash', 'total_score', 'block', 'status']
|
| 103 |
+
|
| 104 |
+
# Create a new DataFrame with only the specified columns
|
| 105 |
+
minerboard_winrate = minerboard_winrate[column_order]
|
| 106 |
+
st.header("Leaderboard by Win Rate ")
|
| 107 |
+
st.dataframe(minerboard_winrate, hide_index=True)
|
| 108 |
+
with st.expander("See detailed calculation method"):
|
| 109 |
+
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.")
|
| 110 |
+
st.code("""
|
| 111 |
+
Example of calculating a win:
|
| 112 |
+
def iswin(score_i, score_j, block_i, block_j):
|
| 113 |
+
penalty = 0.03
|
| 114 |
+
score_i = (1 - penalty) * score_i if block_i > block_j else score_i
|
| 115 |
+
score_j = (1 - penalty) * score_j if block_j > block_i else score_j
|
| 116 |
+
return score_i > score_j
|
| 117 |
+
""")
|
| 118 |
+
st.markdown("---")
|
| 119 |
+
st.header("Minerboard")
|
| 120 |
+
st.dataframe(minerboard, hide_index=True)
|
| 121 |
+
st.markdown("---")
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
if __name__ == '__main__':
|
| 125 |
+
leaderboard_dashboard()
|
image.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|