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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -86
app.py CHANGED
@@ -1,89 +1,38 @@
1
- from datasets import load_dataset
2
- from huggingface_hub import ModelCard
3
- from huggingface_hub import HfApi
4
-
5
  import gradio as gr
 
 
6
  import pandas as pd
7
 
8
- api = HfApi()
9
-
10
- repo_id = "librarian-bots/model_cards_with_metadata"
11
-
12
- dataset = load_dataset(repo_id, split='train')
13
- dataset = dataset.filter(lambda x: x['library_name']=='transformers')
14
-
15
- list_commits = api.list_repo_commits(repo_id, repo_type="dataset")
16
- commits_date_dict = {commit.created_at.strftime("%m/%d/%Y"):commit.commit_id for commit in list_commits}
17
- current_date = "latest"
18
-
19
- def get_data(commit_date="latest"):
20
- ds_kwargs = {}
21
- if commit_date != "latest":
22
- current_date = commit_date
23
- commit_id = commits_date_dict[commit_date]
24
- ds_kwargs = {"revision": commit_id}
25
-
26
- dataset = load_dataset(repo_id, split='train', **ds_kwargs)
27
- dataset = dataset.filter(lambda x: x['library_name']=='transformers')
28
-
29
- def pipeline_tag_not_in_card(card):
30
- try:
31
- model_card_data = ModelCard(card).data
32
- if model_card_data.library_name is None:
33
- return True
34
- return False
35
- except AttributeError:
36
- return False
37
- except Exception:
38
- return False
39
-
40
- ds = dataset.map(lambda x: {"missing_library_name": pipeline_tag_not_in_card(x['card'])}, num_proc=4)
41
-
42
-
43
- data = pd.DataFrame(
44
- {
45
- "name": ["Total Number of transformers Model", "Total number of models with missing 'library_name: transformers' in model card."],
46
- "count": [len(ds), sum(ds["missing_library_name"])],
47
- }
48
- )
49
- return data
50
-
51
- def fetch_fn(commit_date="latest"):
52
- data = get_data(commit_date=commit_date)
53
- return gr.BarPlot(
54
- data,
55
- x="name",
56
- y="count",
57
- title="Count of Model cards with the correct library_name tag",
58
- height=256,
59
- width=1024,
60
- tooltip=["name", "count"],
61
- vertical=False
62
- )
63
-
64
- data = get_data()
65
-
66
- with gr.Blocks() as bar_plot:
67
- with gr.Column():
68
- with gr.Row():
69
- plot = gr.BarPlot(
70
- data,
71
- x="name",
72
- y="count",
73
- title=f"Count of Model cards with the correct library_name tag at the date {current_date}",
74
- height=256,
75
- width=1024,
76
- tooltip=["name", "count"],
77
- vertical=False
78
- )
79
- with gr.Column():
80
- display = gr.Dropdown(
81
- choices=list(commits_date_dict.keys()),
82
- value="latest",
83
- label="Type of Bar Plot",
84
-
85
- )
86
-
87
- display.change(fetch_fn, inputs=display, outputs=plot)
88
-
89
- bar_plot.launch()
 
 
 
 
 
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
+
9
+ # Convert dataset to a pandas DataFrame and sort by commit_dates
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()