mohsenfayyaz commited on
Commit
3399938
·
verified ·
1 Parent(s): d377ae7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
  import plotly.express as px
4
 
5
  def split_multi_users(dfs):
@@ -37,7 +38,7 @@ def plot_now():
37
  fig.update_traces(textposition='inside', insidetextanchor='middle')
38
  return fig, dfs
39
 
40
- def plot_history():
41
  dfh = pd.read_pickle("hf://spaces/pluslab/PLUS_Lab_GPUs/history.pkl.gz", )
42
  dfh = dfh.fillna("FREE")
43
  dfh = split_multi_users(dfh)
@@ -45,6 +46,15 @@ def plot_history():
45
  dfh = dfh.groupby(["polling_timestamp", "username"]).sum()
46
  dfh = dfh.reset_index()
47
  dfh = dfh.sort_values(by=["polling_timestamp", "count"], ascending=False)
 
 
 
 
 
 
 
 
 
48
  fig = px.area(dfh, x="polling_timestamp", y="count", color='username', color_discrete_map={"FREE": "black",}, markers=True, line_shape='spline',)
49
  return fig, dfh
50
 
@@ -61,7 +71,9 @@ def plot_figs():
61
 
62
  demo = gr.Interface(
63
  fn=plot_figs,
64
- inputs = [],
 
 
65
  outputs = [
66
  gr.Plot(label="GPU Status", elem_classes="plotcss"),
67
  gr.Dataframe(label="GPU Status Details"),
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import datetime
4
  import plotly.express as px
5
 
6
  def split_multi_users(dfs):
 
38
  fig.update_traces(textposition='inside', insidetextanchor='middle')
39
  return fig, dfs
40
 
41
+ def plot_history(sample=True, sampling_interval_minutes=180):
42
  dfh = pd.read_pickle("hf://spaces/pluslab/PLUS_Lab_GPUs/history.pkl.gz", )
43
  dfh = dfh.fillna("FREE")
44
  dfh = split_multi_users(dfh)
 
46
  dfh = dfh.groupby(["polling_timestamp", "username"]).sum()
47
  dfh = dfh.reset_index()
48
  dfh = dfh.sort_values(by=["polling_timestamp", "count"], ascending=False)
49
+ if sample:
50
+ unique_timestamps = dfh["polling_timestamp"].unique()
51
+ sampled_timestamps = [unique_timestamps[0]]
52
+ for i, t in enumerate(unique_timestamps[1:]):
53
+ diff = sampled_timestamps[-1] - t
54
+ print (sampled_timestamps[-1], t, diff)
55
+ if diff > datetime.timedelta(minutes=sampling_interval_minutes):
56
+ sampled_timestamps.append(t)
57
+ dfh = dfh[dfh["polling_timestamp"].isin(sampled_timestamps)]
58
  fig = px.area(dfh, x="polling_timestamp", y="count", color='username', color_discrete_map={"FREE": "black",}, markers=True, line_shape='spline',)
59
  return fig, dfh
60
 
 
71
 
72
  demo = gr.Interface(
73
  fn=plot_figs,
74
+ inputs = [
75
+
76
+ ],
77
  outputs = [
78
  gr.Plot(label="GPU Status", elem_classes="plotcss"),
79
  gr.Dataframe(label="GPU Status Details"),