Spaces:
Runtime error
Runtime error
alex n
commited on
Commit
·
ddbfd8d
1
Parent(s):
c074aa5
fixed order of functions
Browse files
app.py
CHANGED
@@ -4,62 +4,9 @@ import bittensor as bt
|
|
4 |
import requests
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
6 |
|
7 |
-
|
8 |
-
#Enhanced Custom CSS
|
9 |
-
custom_css = """
|
10 |
-
#component-0 {
|
11 |
-
max-width: 100% !important;
|
12 |
-
padding: 0 !important;
|
13 |
-
margin: 0 !important;
|
14 |
-
}
|
15 |
-
|
16 |
-
.gradio-container {
|
17 |
-
max-width: 100% !important;
|
18 |
-
padding: 0 !important;
|
19 |
-
margin: 0 !important;
|
20 |
-
background-image: url('""" + background_url + """') !important;
|
21 |
-
background-size: cover !important;
|
22 |
-
background-position: center !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:
|
62 |
-
# Return empty DataFrame with correct columns if initialization failed
|
63 |
return pd.DataFrame(columns=['Name', 'UID', 'Axon', 'API', 'Step', 'Recent Bits', 'Updated', 'VTrust'])
|
64 |
|
65 |
try:
|
@@ -138,6 +85,59 @@ def get_validator_data() -> pd.DataFrame:
|
|
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
|
|
|
4 |
import requests
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
6 |
|
7 |
+
# 1. Define data functions first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def get_validator_data() -> pd.DataFrame:
|
9 |
if subtensor is None or metagraph is None:
|
|
|
10 |
return pd.DataFrame(columns=['Name', 'UID', 'Axon', 'API', 'Step', 'Recent Bits', 'Updated', 'VTrust'])
|
11 |
|
12 |
try:
|
|
|
85 |
df['VTrust'] = df['VTrust'].round(4)
|
86 |
return df.sort_values('Step', ascending=False)[['Name', 'UID', 'Axon', 'API', 'Step', 'Recent Bits', 'Updated', 'VTrust']]
|
87 |
|
88 |
+
# 2. Initialize bittensor and load data
|
89 |
+
try:
|
90 |
+
subtensor = bt.subtensor()
|
91 |
+
metagraph = bt.metagraph(netuid=36)
|
92 |
+
initial_df = get_validator_data()
|
93 |
+
initial_timestamp = pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S UTC")
|
94 |
+
print("✅ Data loaded successfully")
|
95 |
+
except Exception as e:
|
96 |
+
print(f"❌ Failed to initialize: {e}")
|
97 |
+
initial_df = pd.DataFrame()
|
98 |
+
initial_timestamp = "Failed to load initial data"
|
99 |
+
|
100 |
+
# 3. Then CSS and UI components
|
101 |
+
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"
|
102 |
+
custom_css = """
|
103 |
+
#component-0 {
|
104 |
+
max-width: 100% !important;
|
105 |
+
padding: 0 !important;
|
106 |
+
margin: 0 !important;
|
107 |
+
}
|
108 |
+
|
109 |
+
.gradio-container {
|
110 |
+
max-width: 100% !important;
|
111 |
+
padding: 0 !important;
|
112 |
+
margin: 0 !important;
|
113 |
+
background-image: url('""" + background_url + """') !important;
|
114 |
+
background-size: cover !important;
|
115 |
+
background-position: center !important;
|
116 |
+
background-repeat: no-repeat !important;
|
117 |
+
min-height: 100vh !important;
|
118 |
+
}
|
119 |
+
|
120 |
+
.header-box {
|
121 |
+
text-align: center;
|
122 |
+
max-width: 100%;
|
123 |
+
margin: 20px auto;
|
124 |
+
padding: 1rem;
|
125 |
+
background-color: rgba(17, 24, 39, 0.95); /* Darker, more opaque background */
|
126 |
+
border-radius: 1rem;
|
127 |
+
}
|
128 |
+
|
129 |
+
.header-box h1 {
|
130 |
+
color: white;
|
131 |
+
margin: 0;
|
132 |
+
font-size: 2rem;
|
133 |
+
}
|
134 |
+
|
135 |
+
.header-box p {
|
136 |
+
color: white; /* Changed to white instead of gray */
|
137 |
+
margin-top: 0.5rem;
|
138 |
+
}
|
139 |
+
"""
|
140 |
+
|
141 |
# Data functions first
|
142 |
def fetch_data():
|
143 |
# your data fetching logic
|