Spaces:
Running
Running
File size: 2,444 Bytes
6c858ba 4ebccb1 6c858ba 4ebccb1 b190717 4ebccb1 b190717 4ebccb1 b190717 6c858ba b190717 6c858ba 4ebccb1 6c858ba 4ebccb1 6c858ba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import gradio as gr
import pandas as pd
from chain_data import WEIGHTS_BY_MINER, UIDS_BY_HOTKEY, get_nodes, sync_metagraph, Weight
from wandb_data import Hotkey, get_current_runs
def get_color_by_weight(weight: float) -> str:
if weight < 0.001:
return "gray"
elif weight < 0.3:
r = int(255)
g = int((weight / 0.3) * 165)
return f"rgb({r}, {g}, 0)"
elif weight < 0.8:
progress = (weight - 0.3) / 0.5
r = int(255 - (progress * 255))
g = int(165 + (progress * 90))
return f"rgb({r}, {g}, 0)"
else:
progress = (weight - 0.8) / 0.2
g = int(255 - ((1 - progress) * 50))
return f"rgb(0, {g}, 0)"
def get_active_weights() -> dict[Hotkey, list[tuple[Hotkey, Weight]]]:
runs = get_current_runs()
weights: dict[Hotkey, list[tuple[Hotkey, Weight]]] = {}
for hotkey, validator_weights in WEIGHTS_BY_MINER.items():
new_weights: list[tuple[Hotkey, Weight]] = []
for validator_hotkey, weight in validator_weights:
if validator_hotkey in [run.hotkey for run in runs]:
new_weights.append((validator_hotkey, weight))
weights[hotkey] = new_weights
return weights
def create_weights(include_inactive: bool) -> gr.Dataframe:
data: list[list] = []
sync_metagraph()
headers = ["Miner UID", "Incentive"]
datatype = ["number", "markdown"]
weights = WEIGHTS_BY_MINER if include_inactive else get_active_weights()
validator_uids = set()
for _, validator_weights in weights.items():
for validator_hotkey, _ in validator_weights:
validator_uids.add(UIDS_BY_HOTKEY[validator_hotkey])
for validator_uid in sorted(validator_uids):
headers.append(str(validator_uid))
datatype.append("markdown")
for hotkey, validator_weights in weights.items():
incentive = get_nodes().get(hotkey, 0).incentive / 2 ** 16
row = [UIDS_BY_HOTKEY[hotkey], f"<span style='color: {get_color_by_weight(incentive)}'>{incentive:.{3}f}</span>"]
for _, weight in validator_weights:
row.append(f"<span style='color: {get_color_by_weight(weight)}'>{weight:.{3}f}</span>")
data.append(row)
data.sort(key=lambda val: float(val[1].split(">")[1].split("<")[0]), reverse=True)
return gr.Dataframe(
pd.DataFrame(data, columns=headers),
datatype=datatype,
interactive=False,
)
|