|
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/mohsenfayyaz/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/mohsenfayyaz/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) |
|
return fig, dfh |
|
|
|
|
|
def plot_figs(): |
|
fig_now, dfn = plot_now() |
|
try: |
|
fig_history, dfh = plot_history() |
|
except Exception as e: |
|
print(e) |
|
fig_history = None |
|
dfh = None |
|
return fig_now, dfn, fig_history |
|
|
|
demo = gr.Interface( |
|
fn=plot_figs, |
|
inputs = [], |
|
outputs = [ |
|
gr.Plot(label="GPU Status", elem_classes="plotcss"), |
|
gr.Dataframe(label="GPU Status Details"), |
|
gr.Plot(label="History", elem_classes="plotcss"), |
|
], |
|
live=True, |
|
flagging_options=[], |
|
css=".plotcss {max-width: 820px !important;}" |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch(debug=True) |