|
import streamlit as st |
|
import pandas as pd |
|
from datasets import load_dataset |
|
from ast import literal_eval |
|
import altair as alt |
|
import plotly.graph_objs as go |
|
import matplotlib.pyplot as plt |
|
|
|
def main(): |
|
print("Build") |
|
nlp_tasks = ["text-classification", "text-generation", "text2text-generation", "token-classification", "fill-mask", "question-answering", |
|
"translation", "conversational", "sentence-similarity", "summarization", "multiple-choice", "zero-shot-classification", "table-question-answering" |
|
] |
|
audio_tasks = ["automatic-speech-recognition", "audio-classification", "text-to-speech", "audio-to-audio", "voice-activity-detection"] |
|
cv_tasks = ["image-classification", "image-segmentation", "zero-shot-image-classification", "image-to-image", "unconditional-image-generation", "object-detection"] |
|
multimodal = ["feature-extraction", "text-to-image", "visual-question-answering", "image-to-text", "document-question-answering"] |
|
tabular = ["tabular-classification", "tabular-regression"] |
|
|
|
modalities = { |
|
"nlp": nlp_tasks, |
|
"audio": audio_tasks, |
|
"cv": cv_tasks, |
|
"multimodal": multimodal, |
|
"tabular": tabular, |
|
"rl": ["reinforcement-learning"] |
|
} |
|
|
|
def modality(row): |
|
pipeline = row["pipeline"] |
|
for modality, tasks in modalities.items(): |
|
if pipeline in tasks: |
|
return modality |
|
if type(pipeline) == "str": |
|
return "unk_modality" |
|
return None |
|
|
|
supported_revisions = ["03_10_22", "27_09_22"] |
|
|
|
st.cache(allow_output_mutation=True) |
|
def process_dataset(version): |
|
|
|
dataset = load_dataset("open-source-metrics/model-repos-stats", revision=version) |
|
|
|
|
|
data = dataset["train"].to_pandas() |
|
|
|
|
|
data["modality"] = data.apply(modality, axis=1) |
|
|
|
|
|
data["length_bins"] = pd.cut(data["text_length"], [0, 200, 1000, 2000, 3000, 4000, 5000, 7500, 10000, 20000, 50000]) |
|
|
|
return data |
|
|
|
col1, col2 = st.columns(2) |
|
with col1: |
|
base = st.selectbox( |
|
'Old revision', |
|
supported_revisions, |
|
index=1) |
|
with col2: |
|
new = st.selectbox( |
|
'Last revision', |
|
supported_revisions, |
|
index=0) |
|
|
|
old_data = process_dataset(base) |
|
data = process_dataset(new) |
|
|
|
def eval_tags(row): |
|
tags = row["tags"] |
|
if tags == "none" or tags == [] or tags == "{}": |
|
return [] |
|
if tags[0] != "[": |
|
tags = str([tags]) |
|
val = literal_eval(tags) |
|
if isinstance(val, dict): |
|
return [] |
|
return val |
|
|
|
old_data["tags"] = old_data.apply(eval_tags, axis=1) |
|
data["tags"] = data.apply(eval_tags, axis=1) |
|
|
|
total_samples_old = old_data.shape[0] |
|
total_samples = data.shape[0] |
|
st.metric(label="Total models", value=total_samples, delta=total_samples-total_samples_old) |
|
|
|
|
|
|
|
|
|
tab = st.selectbox( |
|
'Topic of interest', |
|
["Language", "License", "Pipeline", "Discussion Features", "Libraries", "Model Cards", "Super Users", "Raw Data"]) |
|
|
|
|
|
if tab == "Language": |
|
st.header("Languages info") |
|
|
|
data.loc[data.languages == "False", 'languages'] = None |
|
data.loc[data.languages == {}, 'languages'] = None |
|
old_data.loc[old_data.languages == "False", 'languages'] = None |
|
old_data.loc[old_data.languages == {}, 'languages'] = None |
|
|
|
no_lang_count = data["languages"].isna().sum() |
|
no_lang_count_old = old_data["languages"].isna().sum() |
|
data["languages"] = data["languages"].fillna('none') |
|
old_data["languages"] = old_data["languages"].fillna('none') |
|
|
|
def make_list(row): |
|
languages = row["languages"] |
|
if languages == "none": |
|
return [] |
|
return literal_eval(languages) |
|
|
|
def language_count(row): |
|
languages = row["languages"] |
|
leng = len(languages) |
|
return leng |
|
|
|
data["languages"] = data.apply(make_list, axis=1) |
|
data["language_count"] = data.apply(language_count, axis=1) |
|
old_data["languages"] = old_data.apply(make_list, axis=1) |
|
old_data["language_count"] = old_data.apply(language_count, axis=1) |
|
|
|
models_with_langs = data[data["language_count"] > 0] |
|
langs = models_with_langs["languages"].explode() |
|
langs = langs[langs != {}] |
|
total_langs = len(langs.unique()) |
|
|
|
models_with_langs_old = old_data[old_data["language_count"] > 0] |
|
langs_old = models_with_langs_old["languages"].explode() |
|
langs_old = langs_old[langs_old != {}] |
|
total_langs_old = len(langs_old.unique()) |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
v = total_samples-no_lang_count |
|
v_old = total_samples_old-no_lang_count_old |
|
st.metric(label="Language Specified", value=v, delta=int(v-v_old)) |
|
with col2: |
|
st.metric(label="No Language Specified", value=no_lang_count, delta=int(no_lang_count-no_lang_count_old)) |
|
with col3: |
|
st.metric(label="Total Unique Languages", value=total_langs, delta=int(total_langs-total_langs_old)) |
|
|
|
st.subheader("Count of languages per model repo") |
|
st.text("Some repos are for multiple languages, so the count is greater than 1") |
|
linguality = st.selectbox( |
|
'All or just Multilingual', |
|
["All", "Just Multilingual", "Three or more languages"]) |
|
|
|
filter = 0 |
|
st.text("Tofix: This just takes into account count of languages, it misses the multilingual tag") |
|
if linguality == "Just Multilingual": |
|
filter = 1 |
|
elif linguality == "Three or more languages": |
|
filter = 2 |
|
|
|
models_with_langs = data[data["language_count"] > filter] |
|
df1 = models_with_langs['language_count'].value_counts() |
|
models_with_langs_old = old_data[old_data["language_count"] > filter] |
|
df1_old = models_with_langs_old['language_count'].value_counts() |
|
st.bar_chart(df1) |
|
|
|
st.subheader("Most frequent languages") |
|
linguality_2 = st.selectbox( |
|
'All or filtered', |
|
["All", "No English", "Remove top 10"]) |
|
|
|
filter = 0 |
|
if linguality_2 == "All": |
|
filter = 0 |
|
elif linguality_2 == "No English": |
|
filter = 1 |
|
else: |
|
filter = 2 |
|
|
|
models_with_langs = data[data["language_count"] > 0] |
|
langs = models_with_langs["languages"].explode() |
|
langs = langs[langs != {}] |
|
orig_d = langs.value_counts().rename_axis("language").to_frame('counts').reset_index() |
|
d = orig_d |
|
|
|
models_with_langs_old = old_data[old_data["language_count"] > 0] |
|
langs = models_with_langs_old["languages"].explode() |
|
langs = langs[langs != {}] |
|
orig_d_old = langs.value_counts().rename_axis("language").to_frame('counts').reset_index() |
|
|
|
if filter == 1: |
|
d = orig_d.iloc[1:] |
|
elif filter == 2: |
|
d = orig_d.iloc[10:] |
|
|
|
|
|
d = d.iloc[:25] |
|
|
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('language', sort=None) |
|
)) |
|
|
|
st.subheader("Raw Data") |
|
l = df1.rename_axis("lang_count").reset_index().rename(columns={"language_count": "r_c"}) |
|
l_old = df1_old.rename_axis("lang_count").reset_index().rename(columns={"language_count": "old_r_c"}) |
|
final_data = pd.merge( |
|
l, l_old, how="outer", on="lang_count" |
|
) |
|
final_data["diff"] = final_data["r_c"] - final_data["old_r_c"] |
|
st.dataframe(final_data) |
|
|
|
d = orig_d.astype(str) |
|
orig_d_old = orig_d_old.astype(str).rename(columns={"counts": "old_c"}) |
|
final_data = pd.merge( |
|
d, orig_d_old, how="outer", on="language" |
|
) |
|
final_data["diff"] = final_data["counts"].astype(int) - final_data["old_c"].astype(int) |
|
|
|
st.dataframe(final_data) |
|
|
|
|
|
|
|
|
|
if tab == "License": |
|
st.header("License info") |
|
|
|
no_license_count = data["license"].isna().sum() |
|
no_license_count_old = old_data["license"].isna().sum() |
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
v = total_samples-no_license_count |
|
v_old = total_samples_old-no_license_count_old |
|
st.metric(label="License Specified", value=v, delta=int(v-v_old)) |
|
with col2: |
|
st.metric(label="No license Specified", value=no_license_count, delta=int(no_license_count-no_license_count_old)) |
|
with col3: |
|
unique_licenses = len(data["license"].unique()) |
|
unique_licenses_old = len(old_data["license"].unique()) |
|
st.metric(label="Total Unique Licenses", value=unique_licenses, delta=int(unique_licenses-unique_licenses_old)) |
|
|
|
st.subheader("Distribution of licenses per model repo") |
|
license_filter = st.selectbox( |
|
'All or filtered', |
|
["All", "No Apache 2.0", "Remove top 10"]) |
|
|
|
filter = 0 |
|
if license_filter == "All": |
|
filter = 0 |
|
elif license_filter == "No Apache 2.0": |
|
filter = 1 |
|
else: |
|
filter = 2 |
|
|
|
d = data["license"].value_counts().rename_axis("license").to_frame('counts').reset_index() |
|
if filter == 1: |
|
d = d.iloc[1:] |
|
elif filter == 2: |
|
d = d.iloc[10:] |
|
|
|
|
|
d = d.iloc[:25] |
|
|
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('license', sort=None) |
|
)) |
|
st.text("There are some edge cases, as old repos using lists of licenses.") |
|
|
|
st.subheader("Raw Data") |
|
d = data["license"].value_counts().rename_axis("license").to_frame('counts').reset_index() |
|
d_old = old_data["license"].value_counts().rename_axis("license").to_frame('counts').reset_index().rename(columns={"counts": "old_c"}) |
|
final_data = pd.merge( |
|
d, d_old, how="outer", on="license" |
|
) |
|
final_data["diff"] = final_data["counts"] - final_data["old_c"] |
|
st.dataframe(final_data) |
|
|
|
|
|
if tab == "Pipeline": |
|
st.header("Pipeline info") |
|
|
|
tags = data["tags"].explode() |
|
tags = tags[tags.notna()].value_counts().rename_axis("tag").to_frame('counts').reset_index() |
|
s = tags["tag"] |
|
s = s[s.apply(type) == str] |
|
unique_tags = len(s.unique()) |
|
|
|
tags_old = old_data["tags"].explode() |
|
tags_old = tags_old[tags_old.notna()].value_counts().rename_axis("tag").to_frame('counts').reset_index() |
|
s = tags_old["tag"] |
|
s = s[s.apply(type) == str] |
|
unique_tags_old = len(s.unique()) |
|
|
|
no_pipeline_count = data["pipeline"].isna().sum() |
|
no_pipeline_count_old = old_data["pipeline"].isna().sum() |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
v = total_samples-no_pipeline_count |
|
v_old = total_samples_old-no_pipeline_count_old |
|
st.metric(label="# models that have any pipeline", value=v, delta=int(v-v_old)) |
|
with col2: |
|
st.metric(label="No pipeline Specified", value=no_pipeline_count, delta=int(no_pipeline_count-no_pipeline_count_old)) |
|
with col3: |
|
st.metric(label="Total Unique Tags", value=unique_tags, delta=int(unique_tags-unique_tags_old)) |
|
|
|
pipeline_filter = st.selectbox( |
|
'Modalities', |
|
["All", "NLP", "CV", "Audio", "RL", "Multimodal", "Tabular"]) |
|
|
|
filter = 0 |
|
if pipeline_filter == "All": |
|
filter = 0 |
|
elif pipeline_filter == "NLP": |
|
filter = 1 |
|
elif pipeline_filter == "CV": |
|
filter = 2 |
|
elif pipeline_filter == "Audio": |
|
filter = 3 |
|
elif pipeline_filter == "RL": |
|
filter = 4 |
|
elif pipeline_filter == "Multimodal": |
|
filter = 5 |
|
elif pipeline_filter == "Tabular": |
|
filter = 6 |
|
|
|
st.subheader("High-level metrics") |
|
filtered_data = data[data['pipeline'].notna()] |
|
filtered_data_old = old_data[old_data['pipeline'].notna()] |
|
|
|
if filter == 1: |
|
filtered_data = data[data["modality"] == "nlp"] |
|
filtered_data_old = old_data[old_data["modality"] == "nlp"] |
|
elif filter == 2: |
|
filtered_data = data[data["modality"] == "cv"] |
|
filtered_data_old = old_data[old_data["modality"] == "cv"] |
|
elif filter == 3: |
|
filtered_data = data[data["modality"] == "audio"] |
|
filtered_data_old = old_data[old_data["modality"] == "audio"] |
|
elif filter == 4: |
|
filtered_data = data[data["modality"] == "rl"] |
|
filtered_data_old = old_data[old_data["modality"] == "rl"] |
|
elif filter == 5: |
|
filtered_data = data[data["modality"] == "multimodal"] |
|
filtered_data_old = old_data[old_data["modality"] == "multimodal"] |
|
elif filter == 6: |
|
filtered_data = data[data["modality"] == "tabular"] |
|
filtered_data_old = old_data[old_data["modality"] == "tabular"] |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
p = st.selectbox( |
|
'What pipeline do you want to see?', |
|
["all", *filtered_data["pipeline"].unique()] |
|
) |
|
with col2: |
|
l = st.selectbox( |
|
'What library do you want to see?', |
|
["all", "not transformers", *filtered_data["library"].unique()] |
|
) |
|
with col3: |
|
f = st.selectbox( |
|
'What framework support? (transformers)', |
|
["all", "py", "tf", "jax"] |
|
) |
|
|
|
col1, col2 = st.columns(2) |
|
with col1: |
|
filt = st.multiselect( |
|
label="Tags (All by default)", |
|
options=s.unique(), |
|
default=None) |
|
with col2: |
|
o = st.selectbox( |
|
label="Operation (for tags)", |
|
options=["Any", "All", "None"] |
|
) |
|
|
|
def filter_fn(row): |
|
tags = row["tags"] |
|
tags[:] = [d for d in tags if isinstance(d, str)] |
|
if o == "All": |
|
if all(elem in tags for elem in filt): |
|
return True |
|
|
|
s1 = set(tags) |
|
s2 = set(filt) |
|
if o == "Any": |
|
if bool(s1 & s2): |
|
return True |
|
if o == "None": |
|
if len(s1.intersection(s2)) == 0: |
|
return True |
|
return False |
|
|
|
|
|
if p != "all": |
|
filtered_data = filtered_data[filtered_data["pipeline"] == p] |
|
filtered_data_old = filtered_data_old[filtered_data_old["pipeline"] == p] |
|
if l != "all" and l != "not transformers": |
|
filtered_data = filtered_data[filtered_data["library"] == l] |
|
filtered_data_old = filtered_data_old[filtered_data_old["library"] == l] |
|
if l == "not transformers": |
|
filtered_data = filtered_data[filtered_data["library"] != "transformers"] |
|
filtered_data_old = filtered_data_old[filtered_data_old["library"] != "transformers"] |
|
if f != "all": |
|
if f == "py": |
|
filtered_data = filtered_data[filtered_data["pytorch"] == 1] |
|
filtered_data_old = filtered_data_old[filtered_data_old["pytorch"] == 1] |
|
elif f == "tf": |
|
filtered_data = filtered_data[filtered_data["tensorflow"] == 1] |
|
filtered_data_old = filtered_data_old[filtered_data_old["tensorflow"] == 1] |
|
elif f == "jax": |
|
filtered_data = filtered_data[filtered_data["jax"] == 1] |
|
filtered_data_old = filtered_data_old[filtered_data_old["jax"] == 1] |
|
if filt != []: |
|
filtered_data = filtered_data[filtered_data.apply(filter_fn, axis=1)] |
|
filtered_data_old = filtered_data_old[filtered_data_old.apply(filter_fn, axis=1)] |
|
|
|
|
|
d = filtered_data["pipeline"].value_counts().rename_axis("pipeline").to_frame('counts').reset_index() |
|
columns_of_interest = ["downloads_30d", "likes", "pytorch", "tensorflow", "jax"] |
|
grouped_data = filtered_data.groupby("pipeline").sum()[columns_of_interest] |
|
final_data = pd.merge( |
|
d, grouped_data, how="outer", on="pipeline" |
|
) |
|
sums = grouped_data.sum() |
|
|
|
d_old = filtered_data_old["pipeline"].value_counts().rename_axis("pipeline").to_frame('counts').reset_index() |
|
grouped_data_old = filtered_data_old.groupby("pipeline").sum()[columns_of_interest] |
|
final_data_old = pd.merge( |
|
d_old, grouped_data_old, how="outer", on="pipeline" |
|
) |
|
sums = grouped_data.sum() |
|
sums_old = grouped_data_old.sum() |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
st.metric(label="Total models", value=filtered_data.shape[0], delta=int(filtered_data.shape[0] - filtered_data_old.shape[0])) |
|
with col2: |
|
st.metric(label="Cumulative Downloads (30d)", value=sums["downloads_30d"], delta=int(sums["downloads_30d"] - sums_old["downloads_30d"])) |
|
with col3: |
|
st.metric(label="Cumulative likes", value=sums["likes"], delta=int(sums["likes"] - sums_old["likes"])) |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
st.metric(label="Total in PT", value=sums["pytorch"], delta=int(sums["pytorch"] - sums_old["pytorch"])) |
|
with col2: |
|
st.metric(label="Total in TF", value=sums["tensorflow"], delta=int(sums["tensorflow"] - sums_old["tensorflow"])) |
|
with col3: |
|
st.metric(label="Total in JAX", value=sums["jax"], delta=int(sums["jax"] - sums_old["jax"])) |
|
|
|
st.metric(label="Unique Tags", value=unique_tags, delta=int(unique_tags - unique_tags_old)) |
|
|
|
|
|
|
|
st.subheader("Count of models per pipeline") |
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('pipeline', sort=None) |
|
)) |
|
|
|
st.subheader("Aggregated data") |
|
st.dataframe(final_data) |
|
|
|
st.subheader("Most common model types (specific to transformers)") |
|
d = filtered_data["model_type"].value_counts().rename_axis("model_type").to_frame('counts').reset_index() |
|
d = d.iloc[:15] |
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('model_type', sort=None) |
|
)) |
|
|
|
st.subheader("Most common library types (Learn more in library tab)") |
|
d = filtered_data["library"].value_counts().rename_axis("library").to_frame('counts').reset_index().head(15) |
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('library', sort=None) |
|
)) |
|
|
|
st.subheader("Tags by count") |
|
tags = filtered_data["tags"].explode() |
|
tags = tags[tags.notna()].value_counts().rename_axis("tag").to_frame('counts').reset_index() |
|
st.write(alt.Chart(tags.head(30)).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('tag', sort=None) |
|
)) |
|
|
|
st.subheader("Raw Data") |
|
columns_of_interest = [ |
|
"repo_id", "author", "model_type", "files_per_repo", "library", |
|
"downloads_30d", "likes", "pytorch", "tensorflow", "jax"] |
|
raw_data = filtered_data[columns_of_interest] |
|
st.dataframe(raw_data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if tab == "Discussion Features": |
|
st.header("Discussions Tab info") |
|
|
|
columns_of_interest = ["prs_count", "prs_open", "prs_merged", "prs_closed", "discussions_count", "discussions_open", "discussions_closed"] |
|
sums = data[columns_of_interest].sum() |
|
sums_old = old_data[columns_of_interest].sum() |
|
|
|
col1, col2, col3, col4 = st.columns(4) |
|
with col1: |
|
st.metric(label="Total PRs", value=sums["prs_count"],delta=int(sums["prs_count"] - sums_old["prs_count"])) |
|
with col2: |
|
st.metric(label="PRs opened", value=sums["prs_open"], delta=int(sums["prs_open"] - sums_old["prs_open"])) |
|
with col3: |
|
st.metric(label="PRs merged", value=sums["prs_merged"], delta=int(sums["prs_merged"] - sums_old["prs_merged"])) |
|
with col4: |
|
st.metric(label="PRs closed", value=sums["prs_closed"], delta=int(sums["prs_closed"] - sums_old["prs_closed"])) |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
st.metric(label="Total discussions", value=sums["discussions_count"], delta=int(sums["discussions_count"] - sums_old["discussions_count"])) |
|
with col2: |
|
st.metric(label="Discussions open", value=sums["discussions_open"], delta=int(sums["discussions_open"] - sums_old["discussions_open"])) |
|
with col3: |
|
st.metric(label="Discussions closed", value=sums["discussions_closed"], delta=int(sums["discussions_closed"] - sums_old["discussions_closed"])) |
|
|
|
filtered_data = data[["repo_id", "prs_count", "prs_open", "prs_merged", "prs_closed", "discussions_count", "discussions_open", "discussions_closed"]].sort_values("prs_count", ascending=False).reset_index(drop=True) |
|
st.dataframe(filtered_data) |
|
|
|
|
|
if tab == "Libraries": |
|
st.header("Library info") |
|
|
|
no_library_count = data["library"].isna().sum() |
|
no_library_count_old = old_data["library"].isna().sum() |
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
v = total_samples-no_library_count |
|
v_old = total_samples_old-no_library_count_old |
|
st.metric(label="# models that have any library", value=v, delta=int(v-v_old)) |
|
with col2: |
|
st.metric(label="No library Specified", value=no_library_count, delta=int(no_library_count-no_library_count_old)) |
|
with col3: |
|
v = len(data["library"].unique()) |
|
v_old = len(old_data["library"].unique()) |
|
st.metric(label="Total Unique library", value=v, delta=int(v-v_old)) |
|
|
|
|
|
st.subheader("High-level metrics") |
|
filtered_data = data[data['library'].notna()] |
|
filtered_data_old = old_data[old_data['library'].notna()] |
|
|
|
col1, col2 = st.columns(2) |
|
with col1: |
|
lib = st.selectbox( |
|
'What library do you want to see? ', |
|
["all", "not transformers", *filtered_data["library"].unique()] |
|
) |
|
with col2: |
|
pip = st.selectbox( |
|
'What pipeline do you want to see? ', |
|
["all", *filtered_data["pipeline"].unique()] |
|
) |
|
|
|
if pip != "all" : |
|
filtered_data = filtered_data[filtered_data["pipeline"] == pip] |
|
filtered_data_old = filtered_data_old[filtered_data_old["pipeline"] == pip] |
|
if lib != "all" and lib != "not transformers": |
|
filtered_data = filtered_data[filtered_data["library"] == lib] |
|
filtered_data_old = filtered_data_old[filtered_data_old["library"] == lib] |
|
if lib == "not transformers": |
|
filtered_data = filtered_data[filtered_data["library"] != "transformers"] |
|
filtered_data_old = filtered_data_old[filtered_data_old["library"] != "transformers"] |
|
|
|
d = filtered_data["library"].value_counts().rename_axis("library").to_frame('counts').reset_index() |
|
grouped_data = filtered_data.groupby("library").sum()[["downloads_30d", "likes"]] |
|
final_data = pd.merge( |
|
d, grouped_data, how="outer", on="library" |
|
) |
|
sums = grouped_data.sum() |
|
|
|
d_old = filtered_data_old["library"].value_counts().rename_axis("library").to_frame('counts').reset_index() |
|
grouped_data_old = filtered_data_old.groupby("library").sum()[["downloads_30d", "likes"]] |
|
final_data_old = pd.merge( |
|
d_old, grouped_data_old, how="outer", on="library" |
|
).add_suffix('_old') |
|
final_data_old = final_data_old.rename(index=str, columns={"library_old": "library"}) |
|
sums_old = grouped_data_old.sum() |
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
v = filtered_data.shape[0] |
|
v_old = filtered_data_old.shape[0] |
|
st.metric(label="Total models", value=v, delta=int(v-v_old)) |
|
with col2: |
|
st.metric(label="Cumulative Downloads (30d)", value=sums["downloads_30d"], delta=int(sums["downloads_30d"]-sums_old["downloads_30d"])) |
|
with col3: |
|
st.metric(label="Cumulative likes", value=sums["likes"], delta=int(sums["likes"]-sums_old["likes"])) |
|
|
|
st.subheader("Most common library types (Learn more in library tab)") |
|
d = filtered_data["library"].value_counts().rename_axis("library").to_frame('counts').reset_index().head(15) |
|
st.write(alt.Chart(d).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('library', sort=None) |
|
)) |
|
|
|
|
|
|
|
st.subheader("Aggregated Data") |
|
final_data = pd.merge( |
|
final_data, final_data_old, how="outer", on="library" |
|
) |
|
final_data["counts_diff"] = final_data["counts"] - final_data["counts_old"] |
|
final_data["downloads_diff"] = final_data["downloads_30d"] - final_data["downloads_30d_old"] |
|
final_data["likes_diff"] = final_data["likes"] - final_data["likes_old"] |
|
|
|
st.dataframe(final_data) |
|
|
|
st.subheader("Raw Data") |
|
columns_of_interest = ["repo_id", "author", "files_per_repo", "library", "downloads_30d", "likes"] |
|
filtered_data = filtered_data[columns_of_interest] |
|
st.dataframe(filtered_data) |
|
|
|
|
|
if tab == "Model Cards": |
|
st.header("Model cards") |
|
|
|
columns_of_interest = ["has_model_index", "has_metadata", "has_text", "text_length"] |
|
rows = data.shape[0] |
|
rows_old = old_data.shape[0] |
|
|
|
cond = data["has_model_index"] | data["has_text"] |
|
with_model_card = data[cond] |
|
c_model_card = with_model_card.shape[0] |
|
|
|
cond = old_data["has_model_index"] | old_data["has_text"] |
|
with_model_card_old = old_data[cond] |
|
c_model_card_old = with_model_card_old.shape[0] |
|
|
|
st.subheader("High-level metrics") |
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
st.metric(label="# models with model card file", value=c_model_card, delta=int(c_model_card-c_model_card_old)) |
|
with col2: |
|
st.metric(label="# models without model card file", value=rows-c_model_card, delta=int((rows-c_model_card)-(rows_old-c_model_card_old))) |
|
|
|
with_index = data["has_model_index"].sum() |
|
with_index_old = old_data["has_model_index"].sum() |
|
with col1: |
|
st.metric(label="# models with model index", value=with_index, delta=int(with_index-with_index_old)) |
|
with col2: |
|
st.metric(label="# models without model index", value=rows-with_index, delta=int((rows-with_index)-(rows_old-with_index_old))) |
|
|
|
with_text = data["has_text"] |
|
with_text_old = old_data["has_text"] |
|
with col1: |
|
st.metric(label="# models with model card text", value=with_text.sum(), delta=int(with_text.sum()-with_text_old.sum())) |
|
with col2: |
|
st.metric(label="# models without model card text", value=rows-with_text.sum(), delta=int((rows-with_text.sum())-(rows_old-with_text_old.sum()))) |
|
|
|
|
|
st.subheader("Length (chars) of model card content") |
|
fig, ax = plt.subplots() |
|
ax = data["length_bins"].value_counts().plot.bar() |
|
st.metric(label="# average length of model card (chars)", value=data[with_text]["text_length"].mean()) |
|
st.pyplot(fig) |
|
|
|
st.subheader("Tags (Read more in Pipeline tab)") |
|
tags = data["tags"].explode() |
|
tags = tags[tags.notna()].value_counts().rename_axis("tag").to_frame('counts').reset_index() |
|
st.write(alt.Chart(tags.head(30)).mark_bar().encode( |
|
x='counts', |
|
y=alt.X('tag', sort=None) |
|
)) |
|
|
|
|
|
if tab == "Super Users": |
|
st.header("Authors") |
|
st.text("This info corresponds to the repos owned by the authors") |
|
authors = data.groupby("author").sum().drop(["text_length", "Unnamed: 0"], axis=1).sort_values("downloads_30d", ascending=False) |
|
d = data["author"].value_counts().rename_axis("author").to_frame('counts').reset_index() |
|
final_data = pd.merge( |
|
d, authors, how="outer", on="author" |
|
) |
|
st.dataframe(final_data) |
|
|
|
|
|
if tab == "Raw Data": |
|
st.header("Raw Data") |
|
d = data.astype(str) |
|
st.dataframe(d) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|
|
|
|
|
|
|