ybelkada commited on
Commit
bf0b4e7
1 Parent(s): ce67f77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -10
app.py CHANGED
@@ -22,6 +22,9 @@ def fetch_dataset_and_init():
22
  df = string_counts_series.sort_values(ascending=False).to_frame()
23
  df.columns = ["count"]
24
  df = df.reset_index()
 
 
 
25
  df_log = df.copy()
26
  df_log['count'] = np.log(df_log['count'])
27
 
@@ -37,24 +40,35 @@ def get_current_nb_models():
37
 
38
  plot_height = 512
39
  plot_width = 1512
 
40
  top_k = len(df)
41
 
42
- def bar_plot_fn(display, top_k):
43
  if display == "simple":
 
 
 
 
 
44
  return gr.BarPlot(
45
- df[:top_k],
46
- x="index",
47
  y="count",
48
- tooltip=["index", "count"],
49
  height=plot_height,
50
  width=plot_width
51
  )
52
  elif display == "log":
 
 
 
 
 
53
  return gr.BarPlot(
54
- df_log[:top_k],
55
- x="index",
56
  y="count",
57
- tooltip=["index", "count"],
58
  height=plot_height,
59
  width=plot_width
60
  )
@@ -72,7 +86,7 @@ with gr.Blocks() as bar_plot:
72
  label="Type of Bar Plot",
73
  )
74
  top_k = gr.Slider(
75
- label="Select top-K most used library_name",
76
  value=len(df),
77
  minimum=1,
78
  maximum=len(df),
@@ -85,8 +99,16 @@ with gr.Blocks() as bar_plot:
85
  fetch_button = gr.Button(value="Fetch current number of models without model cards (takes up to 1min to fetch everything)")
86
  text_box = gr.Textbox(value="", label="Number of models without model cards")
87
 
88
- top_k.change(bar_plot_fn, inputs=[display, top_k], outputs=plot)
89
- display.change(bar_plot_fn, inputs=[display, top_k], outputs=plot)
 
 
 
 
 
 
 
 
90
  fetch_button.click(get_current_nb_models, outputs=[text_box])
91
  bar_plot.load(fn=bar_plot_fn, inputs=[display, top_k], outputs=plot)
92
 
 
22
  df = string_counts_series.sort_values(ascending=False).to_frame()
23
  df.columns = ["count"]
24
  df = df.reset_index()
25
+ df = df.rename(columns={"index": "library_name"})
26
+
27
+ df.replace(to_replace=[None], value="No library_name", inplace=True)
28
  df_log = df.copy()
29
  df_log['count'] = np.log(df_log['count'])
30
 
 
40
 
41
  plot_height = 512
42
  plot_width = 1512
43
+ select_box = ["all"]
44
  top_k = len(df)
45
 
46
+ def bar_plot_fn(display, top_k, select_box):
47
  if display == "simple":
48
+ if select_box is not None and ("all" not in select_box or select_box != ["all"]):
49
+ current_df = df[df["library_name"].isin(select_box)]
50
+ else:
51
+ current_df = df[:top_k]
52
+
53
  return gr.BarPlot(
54
+ current_df,
55
+ x="library_name",
56
  y="count",
57
+ tooltip=["library_name", "count"],
58
  height=plot_height,
59
  width=plot_width
60
  )
61
  elif display == "log":
62
+ if select_box is not None and ("all" not in select_box or select_box != ["all"]):
63
+ current_df = df_log[df_log["library_name"].isin(select_box)]
64
+ else:
65
+ current_df = df_log[:top_k]
66
+
67
  return gr.BarPlot(
68
+ current_df,
69
+ x="library_name",
70
  y="count",
71
+ tooltip=["library_name", "count"],
72
  height=plot_height,
73
  width=plot_width
74
  )
 
86
  label="Type of Bar Plot",
87
  )
88
  top_k = gr.Slider(
89
+ label="Select top-K most used library_name (This leads to a no-op if you selected something else than 'all' in the columns below)",
90
  value=len(df),
91
  minimum=1,
92
  maximum=len(df),
 
99
  fetch_button = gr.Button(value="Fetch current number of models without model cards (takes up to 1min to fetch everything)")
100
  text_box = gr.Textbox(value="", label="Number of models without model cards")
101
 
102
+ with gr.Column():
103
+ select_box = gr.Dropdown(
104
+ ["all"] + df["library_name"].tolist(), value=["all"], multiselect=True, label="Libraries to inspect", info="Select specific libraries to inspect"
105
+ )
106
+
107
+
108
+ top_k.change(bar_plot_fn, inputs=[display, top_k, select_box], outputs=plot)
109
+ display.change(bar_plot_fn, inputs=[display, top_k, select_box], outputs=plot)
110
+ select_box.change(bar_plot_fn, inputs=[display, top_k, select_box], outputs=plot)
111
+
112
  fetch_button.click(get_current_nb_models, outputs=[text_box])
113
  bar_plot.load(fn=bar_plot_fn, inputs=[display, top_k], outputs=plot)
114