davanstrien HF staff commited on
Commit
1b8daa0
1 Parent(s): 6e94de2

Refactor code to include grandchildren in model

Browse files
Files changed (1) hide show
  1. app.py +34 -6
app.py CHANGED
@@ -76,6 +76,14 @@ grouped_by_base_model = groupby(
76
  all_base_models = df["base_model"].to_list()
77
 
78
 
 
 
 
 
 
 
 
 
79
  def return_models_for_base_model(base_model):
80
  models = grouped_by_base_model.get(base_model)
81
  # sort models by downloads
@@ -91,11 +99,21 @@ def return_models_for_base_model(base_model):
91
  f"`{base_model}`'s children have been"
92
  f" downloaded {total_download_number:,} times\n\n"
93
  )
 
 
 
 
 
 
 
 
 
 
94
  results += "### Children models \n\n"
95
  for model in models:
96
  url = f"https://huggingface.co/{model.modelId}"
97
  results += (
98
- f"- [{model.modelId}]({url}) | number of downloads {model.downloads}"
99
  + "\n\n"
100
  )
101
  return results
@@ -113,17 +131,23 @@ def return_base_model_popularity(pipeline=None):
113
  df_with_pipeline_info["pipeline"] == pipeline
114
  ]
115
  keep_columns = ["base_model", "count"]
116
- df_with_pipeline_info["base_model"] = df_with_pipeline_info["base_model"].apply(render_model_hub_link)
 
 
117
  return df_with_pipeline_info[keep_columns].head(50)
118
 
119
 
120
  def return_base_model_popularity_by_org(pipeline=None):
121
- referenced_base_models = [f"[`{model}`](https://huggingface.co/{model})" for model in base_models]
 
 
122
  df_with_pipeline_info = pd.DataFrame(
123
  {"base_model": base_models, "pipeline": pipeline_tags}
124
  )
125
  df_with_pipeline_info["org"] = df_with_pipeline_info["base_model"].apply(parse_org)
126
- df_with_pipeline_info["org"] = df_with_pipeline_info["org"].apply(render_model_hub_link)
 
 
127
  df_with_pipeline_info = df_with_pipeline_info.dropna(subset=["org"])
128
  df_with_org = df_with_pipeline_info.copy(deep=True)
129
  if pipeline is not None:
@@ -162,10 +186,14 @@ with gr.Blocks() as demo:
162
  label="Filter rankings by task pipeline",
163
  )
164
  with gr.Accordion("Base model popularity ranking", open=False):
165
- df_popularity = gr.DataFrame(return_base_model_popularity(None), datatype="markdown")
 
 
166
  dropdown.change(return_base_model_popularity, dropdown, df_popularity)
167
  with gr.Accordion("Base model popularity ranking by organization", open=False):
168
- df_popularity_org = gr.DataFrame(return_base_model_popularity_by_org(None), datatype="markdown")
 
 
169
  dropdown.change(
170
  return_base_model_popularity_by_org, dropdown, df_popularity_org
171
  )
 
76
  all_base_models = df["base_model"].to_list()
77
 
78
 
79
+ def get_grandchildren(base_model):
80
+ grandchildren = []
81
+ for model in tqdm(grouped_by_base_model[base_model]):
82
+ model_id = model.modelId
83
+ grandchildren.extend(grouped_by_base_model.get(model_id, []))
84
+ return grandchildren
85
+
86
+
87
  def return_models_for_base_model(base_model):
88
  models = grouped_by_base_model.get(base_model)
89
  # sort models by downloads
 
99
  f"`{base_model}`'s children have been"
100
  f" downloaded {total_download_number:,} times\n\n"
101
  )
102
+ grandchildren = get_grandchildren(base_model)
103
+ number_of_grandchildren = len(grandchildren)
104
+ results += f"`{base_model}` has {number_of_grandchildren} grandchildren\n\n"
105
+ grandchildren_download_count = sum(model.downloads for model in grandchildren)
106
+ results += (
107
+ f"`{base_model}`'s grandchildren have been"
108
+ f" downloaded {grandchildren_download_count:,} times\n\n"
109
+ )
110
+ results += f"Including grandchildren, `{base_model}` has {number_of_grandchildren + len(models):,} descendants\n\n"
111
+ results += f"Including grandchildren, `{base_model}`'s descendants have been downloaded {grandchildren_download_count + total_download_number:,} times\n\n"
112
  results += "### Children models \n\n"
113
  for model in models:
114
  url = f"https://huggingface.co/{model.modelId}"
115
  results += (
116
+ f"- [{model.modelId}]({url}) | number of downloads {model.downloads:,}"
117
  + "\n\n"
118
  )
119
  return results
 
131
  df_with_pipeline_info["pipeline"] == pipeline
132
  ]
133
  keep_columns = ["base_model", "count"]
134
+ df_with_pipeline_info["base_model"] = df_with_pipeline_info["base_model"].apply(
135
+ render_model_hub_link
136
+ )
137
  return df_with_pipeline_info[keep_columns].head(50)
138
 
139
 
140
  def return_base_model_popularity_by_org(pipeline=None):
141
+ referenced_base_models = [
142
+ f"[`{model}`](https://huggingface.co/{model})" for model in base_models
143
+ ]
144
  df_with_pipeline_info = pd.DataFrame(
145
  {"base_model": base_models, "pipeline": pipeline_tags}
146
  )
147
  df_with_pipeline_info["org"] = df_with_pipeline_info["base_model"].apply(parse_org)
148
+ df_with_pipeline_info["org"] = df_with_pipeline_info["org"].apply(
149
+ render_model_hub_link
150
+ )
151
  df_with_pipeline_info = df_with_pipeline_info.dropna(subset=["org"])
152
  df_with_org = df_with_pipeline_info.copy(deep=True)
153
  if pipeline is not None:
 
186
  label="Filter rankings by task pipeline",
187
  )
188
  with gr.Accordion("Base model popularity ranking", open=False):
189
+ df_popularity = gr.DataFrame(
190
+ return_base_model_popularity(None), datatype="markdown"
191
+ )
192
  dropdown.change(return_base_model_popularity, dropdown, df_popularity)
193
  with gr.Accordion("Base model popularity ranking by organization", open=False):
194
+ df_popularity_org = gr.DataFrame(
195
+ return_base_model_popularity_by_org(None), datatype="markdown"
196
+ )
197
  dropdown.change(
198
  return_base_model_popularity_by_org, dropdown, df_popularity_org
199
  )