Spaces:
Runtime error
Runtime error
| 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) |