Michael Yuan commited on
Commit ·
6128e62
1
Parent(s): 40f0461
Reorganize functions
Browse files
app.py
CHANGED
|
@@ -11,6 +11,8 @@ USER_BLACKLIST = ["gdm", "necl", "ncel", "root"]
|
|
| 11 |
|
| 12 |
|
| 13 |
def get_plot_df(df):
|
|
|
|
|
|
|
| 14 |
df["users"] = df["users"].str.split(",")
|
| 15 |
|
| 16 |
# Clean users list with "Free" as the empty placeholder value
|
|
@@ -18,7 +20,7 @@ def get_plot_df(df):
|
|
| 18 |
lambda user_list: [u for u in user_list if u and u not in USER_BLACKLIST] or ["Free"]
|
| 19 |
)
|
| 20 |
|
| 21 |
-
# Construct a new DataFrame for the
|
| 22 |
new_df = []
|
| 23 |
for _, row_series in df.iterrows():
|
| 24 |
users_list = row_series["users"]
|
|
@@ -57,7 +59,36 @@ def username_to_hsl(username):
|
|
| 57 |
return f"hsl({hue}, {saturation}%, {lightness}%)"
|
| 58 |
|
| 59 |
|
| 60 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
fs = HfFileSystem()
|
| 62 |
|
| 63 |
try:
|
|
@@ -82,48 +113,19 @@ def plot():
|
|
| 82 |
return None, pd.DataFrame()
|
| 83 |
|
| 84 |
df = pd.concat(df_list, ignore_index=True)
|
| 85 |
-
df = df.fillna({"fan_speed": "N/A", "users": ""})
|
| 86 |
df = get_plot_df(df)
|
| 87 |
|
| 88 |
-
|
| 89 |
-
last_update_time = datetime.fromisoformat(last_update_time).strftime("%Y-%m-%d %H:%M:%S")
|
| 90 |
-
|
| 91 |
-
# Create the bar plot
|
| 92 |
-
fig = go.Figure()
|
| 93 |
-
|
| 94 |
-
for _, row_series in df.iterrows():
|
| 95 |
-
fig.add_bar(
|
| 96 |
-
x=[row_series["count"]],
|
| 97 |
-
y=[row_series["server"]],
|
| 98 |
-
orientation="h",
|
| 99 |
-
marker_color=username_to_hsl(row_series["username"]),
|
| 100 |
-
text=f"{row_series['index']}<br>{row_series['username']}",
|
| 101 |
-
insidetextanchor="middle",
|
| 102 |
-
hoverinfo="none",
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
fig.update_layout(
|
| 106 |
-
barmode="stack",
|
| 107 |
-
title=f"Last Updated {last_update_time}",
|
| 108 |
-
showlegend=False,
|
| 109 |
-
xaxis_showticklabels=False,
|
| 110 |
-
yaxis_categoryorder="category descending",
|
| 111 |
-
)
|
| 112 |
|
| 113 |
-
return
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
print(f"Global error in plot: {e}")
|
| 117 |
return None, pd.DataFrame()
|
| 118 |
|
| 119 |
|
| 120 |
-
def generate_interface():
|
| 121 |
-
fig, df = plot()
|
| 122 |
-
return fig, df
|
| 123 |
-
|
| 124 |
-
|
| 125 |
demo = gr.Interface(
|
| 126 |
-
fn=
|
| 127 |
inputs=[],
|
| 128 |
outputs=[
|
| 129 |
gr.Plot(label="GPU Status", elem_classes="plotcss"),
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def get_plot_df(df):
|
| 14 |
+
df = df.fillna({"fan_speed": "N/A", "users": ""})
|
| 15 |
+
|
| 16 |
df["users"] = df["users"].str.split(",")
|
| 17 |
|
| 18 |
# Clean users list with "Free" as the empty placeholder value
|
|
|
|
| 20 |
lambda user_list: [u for u in user_list if u and u not in USER_BLACKLIST] or ["Free"]
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Construct a new DataFrame for the bar chart
|
| 24 |
new_df = []
|
| 25 |
for _, row_series in df.iterrows():
|
| 26 |
users_list = row_series["users"]
|
|
|
|
| 59 |
return f"hsl({hue}, {saturation}%, {lightness}%)"
|
| 60 |
|
| 61 |
|
| 62 |
+
def get_bar_chart(df):
|
| 63 |
+
last_update_time = max(df["query_time"])
|
| 64 |
+
last_update_time = datetime.fromisoformat(last_update_time).strftime("%Y-%m-%d %H:%M:%S")
|
| 65 |
+
|
| 66 |
+
# Create the bar chart
|
| 67 |
+
fig = go.Figure()
|
| 68 |
+
|
| 69 |
+
for _, row_series in df.iterrows():
|
| 70 |
+
fig.add_bar(
|
| 71 |
+
x=[row_series["count"]],
|
| 72 |
+
y=[row_series["server"]],
|
| 73 |
+
orientation="h",
|
| 74 |
+
marker_color=username_to_hsl(row_series["username"]),
|
| 75 |
+
text=f"{row_series['index']}<br>{row_series['username']}",
|
| 76 |
+
insidetextanchor="middle",
|
| 77 |
+
hoverinfo="none",
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
fig.update_layout(
|
| 81 |
+
barmode="stack",
|
| 82 |
+
title=f"Last Updated {last_update_time}",
|
| 83 |
+
showlegend=False,
|
| 84 |
+
xaxis_showticklabels=False,
|
| 85 |
+
yaxis_categoryorder="category descending",
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return fig
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def get_interface_elements():
|
| 92 |
fs = HfFileSystem()
|
| 93 |
|
| 94 |
try:
|
|
|
|
| 113 |
return None, pd.DataFrame()
|
| 114 |
|
| 115 |
df = pd.concat(df_list, ignore_index=True)
|
|
|
|
| 116 |
df = get_plot_df(df)
|
| 117 |
|
| 118 |
+
plot = get_bar_chart(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
return plot, df
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
print(f"Global error in plot: {e}")
|
| 124 |
return None, pd.DataFrame()
|
| 125 |
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
demo = gr.Interface(
|
| 128 |
+
fn=get_interface_elements,
|
| 129 |
inputs=[],
|
| 130 |
outputs=[
|
| 131 |
gr.Plot(label="GPU Status", elem_classes="plotcss"),
|