ybelkada commited on
Commit
885c364
·
verified ·
1 Parent(s): 88faaa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -21
app.py CHANGED
@@ -1,8 +1,9 @@
1
- import gradio as gr
2
  import altair as alt
3
- from datasets import load_dataset
4
  import pandas as pd
5
 
 
 
6
  model_id = "ybelkada/model_cards_correct_tag"
7
  dataset = load_dataset(model_id, split="train").to_pandas()
8
 
@@ -10,29 +11,70 @@ dataset = load_dataset(model_id, split="train").to_pandas()
10
  df = pd.DataFrame(dataset)
11
  df["commit_dates"] = pd.to_datetime(df["commit_dates"]) # Convert commit_dates to datetime format
12
  df = df.sort_values(by="commit_dates")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def plot_fn():
15
- line_chart = alt.Chart(df).mark_line().encode(
16
- x=alt.X('commit_dates:T', axis=alt.Axis(title='Date')),
17
- y=alt.Y('total_transformers_model:Q', axis=alt.Axis(title='Count'), scale=alt.Scale(zero=False)),
18
- color=alt.value('blue'),
19
- tooltip=['commit_dates:T', 'total_transformers_model:Q'],
20
- ).properties(width=600, height=400)
21
-
22
- line_chart_missing_library = alt.Chart(df).mark_line().encode(
23
- x=alt.X('commit_dates:T', axis=alt.Axis(title='Date')),
24
- y=alt.Y('missing_library_name:Q', axis=alt.Axis(title='Count'), scale=alt.Scale(zero=False)),
25
- color=alt.value('orange'),
26
- tooltip=['commit_dates:T', 'missing_library_name:Q'],
27
- ).properties(width=600, height=400)
28
-
29
- chart = (line_chart + line_chart_missing_library).properties(width=600, height=400)
30
-
31
- return chart
32
 
33
  with gr.Blocks() as demo:
 
 
 
 
 
34
  plot = gr.Plot(label="Plot")
35
- demo.load(plot_fn, inputs=[], outputs=[plot])
 
36
 
37
  if __name__ == "__main__":
38
  demo.launch()
 
 
1
  import altair as alt
2
+ import gradio as gr
3
  import pandas as pd
4
 
5
+ from datasets import load_dataset
6
+
7
  model_id = "ybelkada/model_cards_correct_tag"
8
  dataset = load_dataset(model_id, split="train").to_pandas()
9
 
 
11
  df = pd.DataFrame(dataset)
12
  df["commit_dates"] = pd.to_datetime(df["commit_dates"]) # Convert commit_dates to datetime format
13
  df = df.sort_values(by="commit_dates")
14
+ melted_df = pd.melt(df, id_vars=['commit_dates'], value_vars=['total_transformers_model', 'missing_library_name'], var_name='type')
15
+
16
+ df['ratio'] = (1 - df['missing_library_name'] / df['total_transformers_model']) * 100
17
+ ratio_df = df = df[['commit_dates', 'ratio']].copy()
18
+
19
+ def make_plot(plot_type):
20
+ if plot_type == "Total models with missing 'transformers' tag":
21
+ highlight = alt.selection(type='single', on='mouseover',
22
+ fields=['type'], nearest=True)
23
+
24
+
25
+ base = alt.Chart(melted_df).encode(
26
+ x=alt.X('commit_dates:T', title='Date'),
27
+ y=alt.Y('value:Q', scale=alt.Scale(domain=(melted_df['value'].min(), melted_df['value'].max())), title="Count"),
28
+ color='type:N',
29
+ )
30
+
31
+ points = base.mark_circle().encode(
32
+ opacity=alt.value(1),
33
+ ).add_selection(
34
+ highlight
35
+ ).properties(
36
+ width=1200,
37
+ height=800,
38
+ )
39
+
40
+ lines = base.mark_line().encode(
41
+ size=alt.condition(~highlight, alt.value(1), alt.value(3))
42
+ )
43
+
44
+ return points + lines
45
+ else:
46
+ highlight = alt.selection(type='single', on='mouseover',
47
+ fields=['ratio'], nearest=True)
48
+
49
+ base = alt.Chart(ratio_df).encode(
50
+ x=alt.X('commit_dates:T', title='Date'),
51
+ y=alt.Y('ratio:Q', scale=alt.Scale(domain=(ratio_df['ratio'].min(), ratio_df['ratio'].max())), title="(1 - missing_library_name / total_transformers_model) * 100 - Higher is better"),
52
+ )
53
+
54
+ points = base.mark_circle().encode(
55
+ opacity=alt.value(1)
56
+ ).add_selection(
57
+ highlight
58
+ ).properties(
59
+ width=1200,
60
+ height=800,
61
+ )
62
 
63
+ lines = base.mark_line().encode(
64
+ size=alt.condition(~highlight, alt.value(1), alt.value(3))
65
+ )
66
+
67
+ return points + lines
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  with gr.Blocks() as demo:
70
+ button = gr.Radio(
71
+ label="Plot type",
72
+ choices=["Total models with missing 'transformers' tag", "Proportion of models correctly tagged with 'transformers' tag"],
73
+ value="Total models with missing 'transformers' tag"
74
+ )
75
  plot = gr.Plot(label="Plot")
76
+ button.change(make_plot, inputs=button, outputs=[plot])
77
+ demo.load(make_plot, inputs=[button], outputs=[plot])
78
 
79
  if __name__ == "__main__":
80
  demo.launch()