Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,31 @@ import altair as alt
|
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
|
|
|
5 |
from datasets import load_dataset
|
6 |
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
# Convert dataset to a pandas DataFrame and sort by commit_dates
|
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[['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)
|
@@ -65,6 +75,7 @@ def make_plot(plot_type):
|
|
65 |
)
|
66 |
|
67 |
return points + lines
|
|
|
68 |
|
69 |
with gr.Blocks() as demo:
|
70 |
button = gr.Radio(
|
@@ -72,9 +83,13 @@ with gr.Blocks() as demo:
|
|
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 |
-
|
|
|
|
|
77 |
demo.load(make_plot, inputs=[button], outputs=[plot])
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
-
demo.launch()
|
|
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
|
5 |
+
from functools import partial
|
6 |
from datasets import load_dataset
|
7 |
|
8 |
+
def get_data():
|
9 |
+
model_id = "ybelkada/model_cards_correct_tag"
|
10 |
+
dataset = load_dataset(model_id, split="train").to_pandas()
|
11 |
|
12 |
+
# Convert dataset to a pandas DataFrame and sort by commit_dates
|
13 |
+
df = pd.DataFrame(dataset)
|
14 |
+
df["commit_dates"] = pd.to_datetime(df["commit_dates"]) # Convert commit_dates to datetime format
|
15 |
+
df = df.sort_values(by="commit_dates")
|
16 |
+
melted_df = pd.melt(df, id_vars=['commit_dates'], value_vars=['total_transformers_model', 'missing_library_name'], var_name='type')
|
17 |
|
18 |
+
df['ratio'] = (1 - df['missing_library_name'] / df['total_transformers_model']) * 100
|
19 |
+
ratio_df = df[['commit_dates', 'ratio']].copy()
|
20 |
+
return ratio_df, melted_df
|
21 |
+
|
22 |
+
ratio_df, melted_df = get_data()
|
23 |
+
|
24 |
+
def make_plot(plot_type, refresh=False):
|
25 |
+
global ratio_df, melted_df
|
26 |
+
|
27 |
+
if refresh:
|
28 |
+
ratio_df, melted_df = get_data()
|
29 |
|
|
|
30 |
if plot_type == "Total models with missing 'transformers' tag":
|
31 |
highlight = alt.selection(type='single', on='mouseover',
|
32 |
fields=['type'], nearest=True)
|
|
|
75 |
)
|
76 |
|
77 |
return points + lines
|
78 |
+
|
79 |
|
80 |
with gr.Blocks() as demo:
|
81 |
button = gr.Radio(
|
|
|
83 |
choices=["Total models with missing 'transformers' tag", "Proportion of models correctly tagged with 'transformers' tag"],
|
84 |
value="Total models with missing 'transformers' tag"
|
85 |
)
|
86 |
+
refresh_button = gr.Button(value="Fetch latest data")
|
87 |
+
|
88 |
plot = gr.Plot(label="Plot")
|
89 |
+
|
90 |
+
button.change(make_plot, inputs=[button], outputs=[plot])
|
91 |
+
refresh_button.click(partial(make_plot, True), inputs=[button], outputs=[plot])
|
92 |
demo.load(make_plot, inputs=[button], outputs=[plot])
|
93 |
|
94 |
if __name__ == "__main__":
|
95 |
+
demo.launch()
|