import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
from dataset_util import load_data, get_num_rows
import subnet_util
import datetime
import typing
import indexing_util
from io import BytesIO
FONT = """ """
TITLE_FONT = """ """
TITLE = """
D3 Subnet Leaderboard """
DESCRIPTION = """ The D3 Subnet, standing for Decentralized Distributed Data Scraping subnet, plays a crucial role in the advancement of artificial intelligence by ensuring ample training data for all Bittensor AI networks. """
IMAGE = """ """
last_refresh = None
demo = gr.Blocks(css="""
.intersect {font-family: 'Intersect C BRK', sans-serif; font-size:40px}
.promova {font-family: 'Promova', sans-serif; font-size:40px}
""")
twitter_text_dataset = load_data("bittensor-dataset/twitter-text-dataset")
twitter_text_num_rows = get_num_rows(twitter_text_dataset)
twitter_image_dataset = load_data("bittensor-dataset/twitter-image-dataset")
twitter_image_num_rows = get_num_rows(twitter_image_dataset)
tao_price = subnet_util.get_tao_price()
(subtensor, metagraph) = subnet_util.get_subtensor_and_metagraph()
last_refresh = datetime.datetime.now()
miners_data = subnet_util.get_subnet_data(subtensor, metagraph)
daily_indexing_data = indexing_util.get_all(indexing_util.daily_indexing)
daily_df = pd.DataFrame(daily_indexing_data, columns=['Date', 'Value'])
daily_df['Date'] = pd.to_datetime(daily_df['Date'].str.decode('utf-8'))
daily_df['Value'] = daily_df['Value'].astype(int)
hotkey_indexing_data = indexing_util.get_all(indexing_util.hotkey_indexing)
hotkey_df = pd.DataFrame(hotkey_indexing_data, columns=['Hotkey', 'Value'])
hotkey_df['Hotkey'] = hotkey_df['Hotkey'].str.decode('utf-8')
hotkey_df['Value'] = hotkey_df['Value'].astype(int)
hotkey_daily_indexing_data = indexing_util.get_all(indexing_util.hotkey_daily_indexing)
hotkey_daily_df = pd.DataFrame(hotkey_daily_indexing_data, columns=['Hotkey_Date', 'Value'])
hotkey_daily_df_= pd.DataFrame()
hotkey_daily_df_['Hotkey'] = hotkey_daily_df['Hotkey_Date'].str.decode('utf-8').str.split(' ').str[0]
hotkey_daily_df_['Date'] = hotkey_daily_df['Hotkey_Date'].str.decode('utf-8').str.split(' ').str[1]
hotkey_daily_df_['Value'] = hotkey_daily_df['Value'].astype(int)
print(hotkey_daily_df_)
def leaderboard_data(
# show_stale: bool,
# scores: typing.Dict[int, typing.Dict[str, typing.Optional[float | str]]],
# competition_id: str,
):
value = [
[
c.hotkey[0:8],
c.uid,
c.url,
c.block,
]
for c in miners_data
# if c.incentive and c.url[0:8] == "https://"
]
return value
with demo:
gr.HTML(FONT)
gr.HTML(TITLE_FONT)
gr.HTML(TITLE)
gr.HTML(IMAGE)
gr.HTML(DESCRIPTION)
with gr.Tabs():
with gr.Accordion("Dataset Stats"):
with gr.Row():
with gr.Column(scale=1):
gr.HTML(f"Current Size of Text Dataset: {twitter_text_num_rows} ")
with gr.Column(scale=1):
gr.HTML(f"Current Size of Image Dataset: {twitter_image_num_rows} ")
with gr.Accordion("Subnet Stats"):
gr.HTML(f"""""")
with gr.Row():
with gr.Column(scale=1):
gr.BarPlot(
daily_df,
x="Date",
y="Value",
title="Daliy scraped data amount",
# color="Date",
tooltip=["Date", "Value"],
y_lim=[0, 1000],
x_title="Date",
y_title="Amount of data scraped",
height=500,
width=500,
scale=5,
color="Value",
color_legend_position="top",
# elem_classes="daily_scraped_data",
)
with gr.Column(scale=1):
gr.BarPlot(
hotkey_df,
x="Hotkey",
y="Value",
title="Scraped data amount of each Miner",
# color="Date",
tooltip=["Hotkey", "Value"],
y_lim=[0, 1000],
x_title="Date",
y_title="Amount of data scraped",
height=500,
width=500,
scale=5,
color="Value",
x_label_angle=-30,
color_legend_position="top",
# elem_classes="daily_scraped_data",
)
gr.ScatterPlot(
hotkey_daily_df_,
x="Date",
y="Value",
title="Daily scraped data amount of each Miner",
# color="Date",
tooltip=["Hotkey"],
y_lim=[0, 1000],
x_title="Date",
y_title="Amount of data scraped",
height=500,
width=1000,
scale=5,
color="Hotkey",
x_label_angle=-30,
color_legend_position="top",
# elem_classes="daily_scraped_data",
)
with gr.Tab(label="Miners Data"):
class_denominator = sum(
miners_data[i].incentive #TODO: emssion to incentive
for i in range(0, min(10, len(miners_data)))
if miners_data[i].incentive
)
class_values = {
f"(uid={miners_data[i].uid}, hotkey={miners_data[i].hotkey[0:8]}) - {miners_data[i].url} · ${round(miners_data[i].emission * tao_price, 2):,} (τ{round(miners_data[i].emission, 2):,})": miners_data[i].incentive / class_denominator
for i in range(0, min(10, len(miners_data)))
if miners_data[i].incentive
}
gr.Label(
label="Top 10 Miners",
value=class_values,
num_top_classes=10,
)
# miner_table = gr.components.Dataframe(
# value=miners_data
# )
with gr.Accordion("Miner stats"):
gr.HTML(
f"""{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")} """
)
# with gr.Tabs():
# for entry in miners_data:
# name = f"uid={entry.uid} : commit={entry.commit[0:8]} : url={entry.url}"
# with gr.Tab(name):
# gr.Chatbot()
leaderboard_table = gr.components.Dataframe(
value=leaderboard_data(),
headers = [
"Hotkey",
"UID",
"Url",
"Block",
],
datatype=[
"markdown",
"number",
"markdown",
"number",
],
elem_id="leaderboard_table",
interactive=False,
visible=True,
)
demo.launch()