Spaces:
Runtime error
Runtime error
alex n
commited on
Commit
ยท
c074aa5
1
Parent(s):
6155353
fixed loading issues
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import bittensor as bt
|
3 |
import requests
|
4 |
-
import pandas as pd
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
# Enhanced Custom CSS
|
10 |
custom_css = """
|
11 |
#component-0 {
|
12 |
max-width: 100% !important;
|
@@ -24,16 +23,39 @@ custom_css = """
|
|
24 |
background-repeat: no-repeat !important;
|
25 |
min-height: 100vh !important;
|
26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
"""
|
28 |
|
29 |
# Add error handling for bittensor initialization
|
30 |
try:
|
31 |
subtensor = bt.subtensor()
|
32 |
metagraph = bt.metagraph(netuid=36)
|
|
|
|
|
|
|
33 |
except Exception as e:
|
34 |
-
print(f"Failed to initialize
|
35 |
-
|
36 |
-
|
37 |
|
38 |
def get_validator_data() -> pd.DataFrame:
|
39 |
if subtensor is None or metagraph is None:
|
@@ -116,6 +138,41 @@ def get_validator_data() -> pd.DataFrame:
|
|
116 |
df['VTrust'] = df['VTrust'].round(4)
|
117 |
return df.sort_values('Step', ascending=False)[['Name', 'UID', 'Axon', 'API', 'Step', 'Recent Bits', 'Updated', 'VTrust']]
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
# Create the Gradio interface with custom theme
|
120 |
app = gr.Blocks(
|
121 |
title="SN36 Validator Leaderboard",
|
@@ -126,26 +183,26 @@ app = gr.Blocks(
|
|
126 |
)
|
127 |
)
|
128 |
|
129 |
-
# Update the HTML template
|
130 |
-
header_html = """
|
131 |
-
<div style="text-align: center; max-width: 100%; padding: 1rem; background-color: #1f2937; border-radius: 1rem;">
|
132 |
-
<h1 style="color: white;">SN36 Validator Leaderboard</h1>
|
133 |
-
<p style="color: white;">Real-time tracking of validator performance and bits</p>
|
134 |
-
</div>
|
135 |
-
"""
|
136 |
-
|
137 |
with app:
|
138 |
gr.HTML(header_html)
|
139 |
|
140 |
with gr.Tabs(elem_id="main-tabs"):
|
141 |
with gr.Tab("๐ Leaderboard", elem_id="leaderboard-tab"):
|
|
|
142 |
leaderboard = gr.DataFrame(
|
|
|
143 |
headers=["Name", "UID", "Axon", "API", "Step", "Recent Bits", "Updated", "VTrust"],
|
144 |
datatype=["str", "number", "str", "html", "number", "str", "number", "number"],
|
145 |
elem_id="leaderboard-table",
|
146 |
render=True
|
147 |
)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
with gr.Row(equal_height=True):
|
150 |
refresh_button = gr.Button("๐ Refresh Data", variant="primary", elem_classes=["refresh-btn"])
|
151 |
auto_refresh = gr.Checkbox(
|
@@ -154,8 +211,6 @@ with app:
|
|
154 |
interactive=True
|
155 |
)
|
156 |
|
157 |
-
status_message = gr.Markdown("Last updated: Never", elem_classes=["status-msg"])
|
158 |
-
|
159 |
with gr.Tab("โน๏ธ About"):
|
160 |
gr.Markdown(
|
161 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
import bittensor as bt
|
4 |
import requests
|
|
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
6 |
|
7 |
+
background_url = "https://cdn-lfs.hf.co/repos/a4/b4/a4b48e51a6a5ebd9414fc6798da9acf09a6a9425ea160334a1a81c4ad3fdb801/7f89926e2018d54403ac1dc8b0d6fe2401a6489d7da11df27259a07cde7acf87?response-content-disposition=inline%3B+filename*%3DUTF-8%27%27background2.png%3B+filename%3D%22background2.png%22%3B&response-content-type=image%2Fpng&Expires=1731722075&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTczMTcyMjA3NX19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy5oZi5jby9yZXBvcy9hNC9iNC9hNGI0OGU1MWE2YTVlYmQ5NDE0ZmM2Nzk4ZGE5YWNmMDlhNmE5NDI1ZWExNjAzMzRhMWE4MWM0YWQzZmRiODAxLzdmODk5MjZlMjAxOGQ1NDQwM2FjMWRjOGIwZDZmZTI0MDFhNjQ4OWQ3ZGExMWRmMjcyNTlhMDdjZGU3YWNmODc%7EcmVzcG9uc2UtY29udGVudC1kaXNwb3NpdGlvbj0qJnJlc3BvbnNlLWNvbnRlbnQtdHlwZT0qIn1dfQ__&Signature=Y9KvhLMB7xHfQUnq2RC4rMDegTBzbqoMiHAIJzVKy%7E7ajPw2p-AQ19KCYCaXPNbElSV7PZowowMOS%7EtK98A7SM4ndHDePx3OcD%7EDNP8w150rLj58XeCZuVSZ32ayv%7Eb6nZEwYjUbrtrFboN5T9HG8xezW7BgmcXzV3iHppgSNu%7EnwKwJvorVr%7EyddXC6AMsAjsYKYOl1AxnkiMiIKeoD7Rd4ZaAlQsbqAC31BfnbSkBfPq4g0HlCiQYvYsxoofyLsGslnx9X5yIPaYRIRz3uJibPwDZg6GCEYViOfKWwiWV74iA1ptt2DeWLSxBRkjRfnv-HMAs25GmMjqyF85o8vA__&Key-Pair-Id=K3RPWS32NSSJCE"
|
8 |
+
#Enhanced Custom CSS
|
|
|
9 |
custom_css = """
|
10 |
#component-0 {
|
11 |
max-width: 100% !important;
|
|
|
23 |
background-repeat: no-repeat !important;
|
24 |
min-height: 100vh !important;
|
25 |
}
|
26 |
+
|
27 |
+
.header-box {
|
28 |
+
text-align: center;
|
29 |
+
max-width: 100%;
|
30 |
+
margin: 20px auto;
|
31 |
+
padding: 1rem;
|
32 |
+
background-color: rgba(17, 24, 39, 0.95); /* Darker, more opaque background */
|
33 |
+
border-radius: 1rem;
|
34 |
+
}
|
35 |
+
|
36 |
+
.header-box h1 {
|
37 |
+
color: white;
|
38 |
+
margin: 0;
|
39 |
+
font-size: 2rem;
|
40 |
+
}
|
41 |
+
|
42 |
+
.header-box p {
|
43 |
+
color: white; /* Changed to white instead of gray */
|
44 |
+
margin-top: 0.5rem;
|
45 |
+
}
|
46 |
"""
|
47 |
|
48 |
# Add error handling for bittensor initialization
|
49 |
try:
|
50 |
subtensor = bt.subtensor()
|
51 |
metagraph = bt.metagraph(netuid=36)
|
52 |
+
# Preload initial data
|
53 |
+
initial_df = get_validator_data()
|
54 |
+
initial_timestamp = pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S UTC")
|
55 |
except Exception as e:
|
56 |
+
print(f"Failed to initialize: {e}")
|
57 |
+
initial_df = pd.DataFrame()
|
58 |
+
initial_timestamp = "Failed to load initial data"
|
59 |
|
60 |
def get_validator_data() -> pd.DataFrame:
|
61 |
if subtensor is None or metagraph is None:
|
|
|
138 |
df['VTrust'] = df['VTrust'].round(4)
|
139 |
return df.sort_values('Step', ascending=False)[['Name', 'UID', 'Axon', 'API', 'Step', 'Recent Bits', 'Updated', 'VTrust']]
|
140 |
|
141 |
+
# Data functions first
|
142 |
+
def fetch_data():
|
143 |
+
# your data fetching logic
|
144 |
+
pass
|
145 |
+
|
146 |
+
def create_leaderboard():
|
147 |
+
try:
|
148 |
+
data = fetch_data()
|
149 |
+
if not data:
|
150 |
+
return pd.DataFrame()
|
151 |
+
return data
|
152 |
+
except Exception as e:
|
153 |
+
print(f"Error creating leaderboard: {e}")
|
154 |
+
return pd.DataFrame()
|
155 |
+
|
156 |
+
def update_data():
|
157 |
+
try:
|
158 |
+
data = create_leaderboard()
|
159 |
+
error_msg = ""
|
160 |
+
success = True
|
161 |
+
except Exception as e:
|
162 |
+
data = pd.DataFrame()
|
163 |
+
error_msg = f"Error loading data: {str(e)}"
|
164 |
+
success = False
|
165 |
+
return data, error_msg, not success
|
166 |
+
|
167 |
+
# Add this before creating the app
|
168 |
+
header_html = """
|
169 |
+
<div class="header-box">
|
170 |
+
<h1>SN36 Validator Leaderboard</h1>
|
171 |
+
<p>Real-time validator status monitoring</p>
|
172 |
+
</div>
|
173 |
+
"""
|
174 |
+
|
175 |
+
# UI components last
|
176 |
# Create the Gradio interface with custom theme
|
177 |
app = gr.Blocks(
|
178 |
title="SN36 Validator Leaderboard",
|
|
|
183 |
)
|
184 |
)
|
185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
with app:
|
187 |
gr.HTML(header_html)
|
188 |
|
189 |
with gr.Tabs(elem_id="main-tabs"):
|
190 |
with gr.Tab("๐ Leaderboard", elem_id="leaderboard-tab"):
|
191 |
+
# Initialize with preloaded data
|
192 |
leaderboard = gr.DataFrame(
|
193 |
+
value=initial_df,
|
194 |
headers=["Name", "UID", "Axon", "API", "Step", "Recent Bits", "Updated", "VTrust"],
|
195 |
datatype=["str", "number", "str", "html", "number", "str", "number", "number"],
|
196 |
elem_id="leaderboard-table",
|
197 |
render=True
|
198 |
)
|
199 |
|
200 |
+
# Initialize with preloaded timestamp
|
201 |
+
status_message = gr.Markdown(
|
202 |
+
value=f"Last updated: {initial_timestamp}",
|
203 |
+
elem_classes=["status-msg"]
|
204 |
+
)
|
205 |
+
|
206 |
with gr.Row(equal_height=True):
|
207 |
refresh_button = gr.Button("๐ Refresh Data", variant="primary", elem_classes=["refresh-btn"])
|
208 |
auto_refresh = gr.Checkbox(
|
|
|
211 |
interactive=True
|
212 |
)
|
213 |
|
|
|
|
|
214 |
with gr.Tab("โน๏ธ About"):
|
215 |
gr.Markdown(
|
216 |
"""
|