Spaces:
Sleeping
Sleeping
File size: 2,284 Bytes
3da2f6b c5fb572 3da2f6b c5fb572 3da2f6b c5fb572 3da2f6b fa3a59f 3da2f6b 3a76714 3da2f6b c5fb572 |
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 |
import gradio as gr
import pandas as pd
import plotly.express as px
def split_multi_users(dfs):
df = dfs.copy()
df["usernames"] = df["username"].apply(lambda x: x.split(", "))
df["count"] = 1
new_df = []
for row in df.to_dict(orient="records"):
gpu_users_num = len(row["usernames"])
for username in row["usernames"]:
new_row = row.copy()
new_row["count"] = 1 / gpu_users_num
new_row["username"] = username
new_df.append(new_row)
df = pd.DataFrame(new_df)
return df
def plot_now():
dfs = pd.read_csv("hf://spaces/pluslab/PLUS_Lab_GPUs/gpus.csv")
dfs = dfs.drop(columns=["Unnamed: 0"])
dfs = dfs.fillna("FREE")
dfs_plot = split_multi_users(dfs)
fig = px.bar(
dfs_plot, x="count", y="server", color="username",
title=f"Last Updated {min(dfs['timestamp'])}",
color_discrete_map={
"FREE": "black",
},
text=dfs_plot['username'].astype(str) + "<br>" + dfs_plot['device'].astype(str),
)
fig.update_layout(
yaxis={'categoryorder': 'array', 'categoryarray': dfs_plot["server"].unique()[::-1]},
barcornerradius=50,
)
fig.update_traces(textposition='inside', insidetextanchor='middle')
return fig, dfs
def plot_history():
dfh = pd.read_pickle("hf://spaces/pluslab/PLUS_Lab_GPUs/history.pkl.gz", )
dfh = dfh.fillna("FREE")
dfh = split_multi_users(dfh)
dfh = dfh[["polling_timestamp", "username", "count"]]
dfh = dfh.groupby(["polling_timestamp", "username"]).sum()
dfh = dfh.reset_index()
dfh = dfh.sort_values(by=["polling_timestamp", "count"], ascending=False)
fig = px.area(dfh, x="polling_timestamp", y="count", color='username', color_discrete_map={"FREE": "black",}, markers=True, line_shape='spline',)
return fig, dfh
def plot_figs():
return '<h1> Moved to <a target="_blank" href="https://huggingface.co/spaces/pluslab/PLUS_Lab_GPUs">https://huggingface.co/spaces/pluslab/PLUS_Lab_GPUs</a> </h1>'
demo = gr.Interface(
fn=plot_figs,
inputs = [],
outputs = [
gr.HTML(),
],
live=True,
flagging_options=[],
css=".plotcss {max-width: 820px !important;}"
)
if __name__ == "__main__":
demo.launch(debug=False) |