Spaces:
Runtime error
Runtime error
rusticluftig
commited on
Commit
·
9a98f07
1
Parent(s):
01728b6
Add more retries for metadata and add last updated time stamp.
Browse files- app.py +14 -15
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import bittensor as bt
|
| 3 |
from typing import Dict, List, Any, Optional, Tuple
|
|
@@ -77,7 +79,7 @@ def run_with_retries(func, *args, **kwargs):
|
|
| 77 |
for i in range(0, RETRIES):
|
| 78 |
try:
|
| 79 |
return func(*args, **kwargs)
|
| 80 |
-
except:
|
| 81 |
if i == RETRIES - 1:
|
| 82 |
raise
|
| 83 |
time.sleep(DELAY_SECS)
|
|
@@ -93,16 +95,6 @@ def get_subtensor_and_metagraph() -> Tuple[bt.subtensor, bt.metagraph]:
|
|
| 93 |
return run_with_retries(_internal)
|
| 94 |
|
| 95 |
|
| 96 |
-
def get_tao_price() -> float:
|
| 97 |
-
return run_with_retries(
|
| 98 |
-
lambda: float(
|
| 99 |
-
requests.get(
|
| 100 |
-
"https://api.kucoin.com/api/v1/market/stats?symbol=TAO-USDT"
|
| 101 |
-
).json()["data"]["last"]
|
| 102 |
-
)
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
|
| 106 |
def get_validator_weights(
|
| 107 |
metagraph: bt.metagraph,
|
| 108 |
) -> Dict[int, Tuple[float, int, Dict[int, float]]]:
|
|
@@ -127,7 +119,12 @@ def get_subnet_data(
|
|
| 127 |
result = []
|
| 128 |
for uid in metagraph.uids.tolist():
|
| 129 |
hotkey = metagraph.hotkeys[uid]
|
| 130 |
-
metadata =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
if not metadata:
|
| 132 |
continue
|
| 133 |
|
|
@@ -228,6 +225,8 @@ def get_next_update_div(current_block: int, next_update_block: int) -> str:
|
|
| 228 |
delta = next_update_time - now
|
| 229 |
return f"""<div align="center" style="font-size: larger;">Next reward update: <b>{blocks_to_go}</b> blocks (~{int(delta.total_seconds() // 60)} minutes)</div>"""
|
| 230 |
|
|
|
|
|
|
|
| 231 |
|
| 232 |
def leaderboard_data(
|
| 233 |
leaderboard: List[ModelData],
|
|
@@ -255,8 +254,6 @@ def restart_space():
|
|
| 255 |
def main():
|
| 256 |
subtensor, metagraph = get_subtensor_and_metagraph()
|
| 257 |
|
| 258 |
-
tao_price = get_tao_price()
|
| 259 |
-
|
| 260 |
model_data: List[ModelData] = get_subnet_data(subtensor, metagraph)
|
| 261 |
model_data.sort(key=lambda x: x.incentive, reverse=True)
|
| 262 |
|
|
@@ -326,11 +323,13 @@ def main():
|
|
| 326 |
interactive=False,
|
| 327 |
visible=True,
|
| 328 |
)
|
|
|
|
|
|
|
| 329 |
|
| 330 |
|
| 331 |
scheduler = BackgroundScheduler()
|
| 332 |
scheduler.add_job(
|
| 333 |
-
restart_space, "interval", seconds=60 *
|
| 334 |
) # restart every 15 minutes
|
| 335 |
scheduler.start()
|
| 336 |
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import traceback
|
| 3 |
import gradio as gr
|
| 4 |
import bittensor as bt
|
| 5 |
from typing import Dict, List, Any, Optional, Tuple
|
|
|
|
| 79 |
for i in range(0, RETRIES):
|
| 80 |
try:
|
| 81 |
return func(*args, **kwargs)
|
| 82 |
+
except (Exception, RuntimeError):
|
| 83 |
if i == RETRIES - 1:
|
| 84 |
raise
|
| 85 |
time.sleep(DELAY_SECS)
|
|
|
|
| 95 |
return run_with_retries(_internal)
|
| 96 |
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def get_validator_weights(
|
| 99 |
metagraph: bt.metagraph,
|
| 100 |
) -> Dict[int, Tuple[float, int, Dict[int, float]]]:
|
|
|
|
| 119 |
result = []
|
| 120 |
for uid in metagraph.uids.tolist():
|
| 121 |
hotkey = metagraph.hotkeys[uid]
|
| 122 |
+
metadata = None
|
| 123 |
+
try:
|
| 124 |
+
metadata = run_with_retries(functools.partial(get_metadata(subtensor, metagraph.netuid, hotkey)))
|
| 125 |
+
except:
|
| 126 |
+
print(f"Failed to get metadata for UID {uid}: {traceback.format_exc()}")
|
| 127 |
+
|
| 128 |
if not metadata:
|
| 129 |
continue
|
| 130 |
|
|
|
|
| 225 |
delta = next_update_time - now
|
| 226 |
return f"""<div align="center" style="font-size: larger;">Next reward update: <b>{blocks_to_go}</b> blocks (~{int(delta.total_seconds() // 60)} minutes)</div>"""
|
| 227 |
|
| 228 |
+
def get_last_updated_div() -> str:
|
| 229 |
+
return f"""<div>Last Updated: f{datetime.datetime.utc().strftime("%Y-%m-%d %H:%M:%S")} (UTC)</div>"""
|
| 230 |
|
| 231 |
def leaderboard_data(
|
| 232 |
leaderboard: List[ModelData],
|
|
|
|
| 254 |
def main():
|
| 255 |
subtensor, metagraph = get_subtensor_and_metagraph()
|
| 256 |
|
|
|
|
|
|
|
| 257 |
model_data: List[ModelData] = get_subnet_data(subtensor, metagraph)
|
| 258 |
model_data.sort(key=lambda x: x.incentive, reverse=True)
|
| 259 |
|
|
|
|
| 323 |
interactive=False,
|
| 324 |
visible=True,
|
| 325 |
)
|
| 326 |
+
gr.HTML(value=get_last_updated_div())
|
| 327 |
+
|
| 328 |
|
| 329 |
|
| 330 |
scheduler = BackgroundScheduler()
|
| 331 |
scheduler.add_job(
|
| 332 |
+
restart_space, "interval", seconds=60 * 30
|
| 333 |
) # restart every 15 minutes
|
| 334 |
scheduler.start()
|
| 335 |
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
bittensor==6.7.
|
| 2 |
requests==2.31.0
|
| 3 |
wandb==0.16.2
|
| 4 |
python-dotenv==1.0.1
|
|
|
|
| 1 |
+
bittensor==6.7.1
|
| 2 |
requests==2.31.0
|
| 3 |
wandb==0.16.2
|
| 4 |
python-dotenv==1.0.1
|