Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,14 +23,11 @@ def load_models_data():
|
|
| 23 |
dataset_dict = load_dataset(HF_DATASET_ID)
|
| 24 |
df = dataset_dict[list(dataset_dict.keys())[0]].to_pandas()
|
| 25 |
if 'params' in df.columns:
|
| 26 |
-
# IMPORTANT CHANGE: Fill NaN/coerce errors with -1 to signify unknown size
|
| 27 |
-
# This aligns with the utility function's return of -1.0 for unknown sizes.
|
| 28 |
df['params'] = pd.to_numeric(df['params'], errors='coerce').fillna(-1)
|
| 29 |
else:
|
| 30 |
-
# If 'params' column doesn't exist, assume all are unknown
|
| 31 |
df['params'] = -1
|
| 32 |
|
| 33 |
-
#
|
| 34 |
if 'createdAt' in df.columns:
|
| 35 |
df['createdAt'] = pd.to_datetime(df['createdAt'], errors='coerce')
|
| 36 |
|
|
@@ -48,12 +45,10 @@ def get_param_range_values(param_range_labels):
|
|
| 48 |
max_val = float('inf') if '>' in max_label else float(max_label.replace('B', ''))
|
| 49 |
return min_val, max_val
|
| 50 |
|
| 51 |
-
def make_treemap_data(df, count_by, top_k=25, tag_filter=None, pipeline_filter=None, param_range=None, skip_orgs=None, include_unknown_param_size=True, created_after_date=None):
|
| 52 |
if df is None or df.empty: return pd.DataFrame()
|
| 53 |
filtered_df = df.copy()
|
| 54 |
|
| 55 |
-
# New: Filter based on unknown parameter size
|
| 56 |
-
# If include_unknown_param_size is False, exclude models where params is -1 (unknown)
|
| 57 |
if not include_unknown_param_size and 'params' in filtered_df.columns:
|
| 58 |
filtered_df = filtered_df[filtered_df['params'] != -1]
|
| 59 |
|
|
@@ -65,17 +60,17 @@ def make_treemap_data(df, count_by, top_k=25, tag_filter=None, pipeline_filter=N
|
|
| 65 |
if param_range:
|
| 66 |
min_params, max_params = get_param_range_values(param_range)
|
| 67 |
is_default_range = (param_range[0] == PARAM_CHOICES[0] and param_range[1] == PARAM_CHOICES[-1])
|
| 68 |
-
# Apply parameter range filter only if it's not the default (all range) AND params column exists
|
| 69 |
-
# This filter will naturally exclude -1 if the min_params is >= 0, as it should.
|
| 70 |
if not is_default_range and 'params' in filtered_df.columns:
|
| 71 |
if min_params is not None: filtered_df = filtered_df[filtered_df['params'] >= min_params]
|
| 72 |
if max_params is not None and max_params != float('inf'): filtered_df = filtered_df[filtered_df['params'] < max_params]
|
| 73 |
|
| 74 |
-
#
|
| 75 |
if created_after_date is not None and 'createdAt' in filtered_df.columns:
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
| 80 |
if skip_orgs and len(skip_orgs) > 0 and "organization" in filtered_df.columns:
|
| 81 |
filtered_df = filtered_df[~filtered_df["organization"].isin(skip_orgs)]
|
|
@@ -98,27 +93,16 @@ def create_treemap(treemap_data, count_by, title=None):
|
|
| 98 |
fig.update_traces(textinfo="label+value+percent root", hovertemplate="<b>%{label}</b><br>%{value:,} " + count_by + "<br>%{percentRoot:.2%} of total<extra></extra>")
|
| 99 |
return fig
|
| 100 |
|
| 101 |
-
# --- FINAL, CORRECTED CSS ---
|
| 102 |
custom_css = """
|
| 103 |
-
/* Hide the extra UI elements from the RangeSlider component */
|
| 104 |
-
#param-slider-wrapper .head,
|
| 105 |
-
#param-slider-wrapper div[data-testid="range-slider"] > span {
|
| 106 |
-
display: none !important;
|
| 107 |
-
}
|
| 108 |
-
/*
|
| 109 |
-
THIS IS THE KEY FIX:
|
| 110 |
-
We target all the individual component containers (divs with class .block)
|
| 111 |
-
that are *direct children* of our custom-classed group.
|
| 112 |
-
|
| 113 |
-
This removes the "box-in-a-box" effect by making the inner component
|
| 114 |
-
containers transparent. The parent gr.Group now acts as the single card,
|
| 115 |
-
which is exactly what we want.
|
| 116 |
-
*/
|
| 117 |
.model-parameters-group > .block {
|
| 118 |
background: none !important;
|
| 119 |
border: none !important;
|
| 120 |
box-shadow: none !important;
|
| 121 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
"""
|
| 123 |
|
| 124 |
with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True, css=custom_css) as demo:
|
|
@@ -131,32 +115,23 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True, css=custom_css
|
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column(scale=1):
|
| 133 |
|
| 134 |
-
# This section remains un-grouped for a consistent flat look
|
| 135 |
count_by_dropdown = gr.Dropdown(label="Metric", choices=[("Downloads (last 30 days)", "downloads"), ("Downloads (All Time)", "downloadsAllTime"), ("Likes", "likes")], value="downloads")
|
| 136 |
filter_choice_radio = gr.Radio(label="Filter Type", choices=["None", "Tag Filter", "Pipeline Filter"], value="None")
|
| 137 |
|
| 138 |
tag_filter_dropdown = gr.Dropdown(label="Select Tag", choices=TAG_FILTER_CHOICES, value=None, visible=False)
|
| 139 |
pipeline_filter_dropdown = gr.Dropdown(label="Select Pipeline Tag", choices=PIPELINE_TAGS, value=None, visible=False)
|
| 140 |
|
| 141 |
-
# This group's styling will be modified by the custom CSS
|
| 142 |
with gr.Group(elem_classes="model-parameters-group"):
|
| 143 |
gr.Markdown("<div style='font-weight: 500;'>Model Parameters</div>")
|
| 144 |
param_range_slider = RangeSlider(
|
| 145 |
-
minimum=0,
|
| 146 |
-
|
| 147 |
-
value=PARAM_CHOICES_DEFAULT_INDICES,
|
| 148 |
-
step=1,
|
| 149 |
-
label=None,
|
| 150 |
-
show_label=False,
|
| 151 |
-
elem_id="param-slider-wrapper"
|
| 152 |
)
|
| 153 |
param_range_display = gr.Markdown(f"Range: `{PARAM_CHOICES[0]}` to `{PARAM_CHOICES[-1]}`")
|
| 154 |
-
# New: Checkbox for including unknown parameter sizes
|
| 155 |
include_unknown_params_checkbox = gr.Checkbox(label="Include models with unknown parameter size", value=True)
|
| 156 |
|
| 157 |
-
#
|
| 158 |
-
|
| 159 |
-
created_after_datepicker = gr.DatePicker(label="Created After", value=None)
|
| 160 |
|
| 161 |
top_k_dropdown = gr.Dropdown(label="Number of Top Organizations", choices=TOP_K_CHOICES, value=25)
|
| 162 |
skip_orgs_textbox = gr.Textbox(label="Organizations to Skip (comma-separated)", value="TheBloke,MaziyarPanahi,unsloth,modularai,Gensyn,bartowski")
|
|
@@ -172,141 +147,80 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True, css=custom_css
|
|
| 172 |
min_idx, max_idx = int(value[0]), int(value[1])
|
| 173 |
return f"Range: `{PARAM_CHOICES[min_idx]}` to `{PARAM_CHOICES[max_idx]}`"
|
| 174 |
|
| 175 |
-
# New function to toggle the unknown params checkbox interactivity
|
| 176 |
def _toggle_unknown_params_checkbox(param_range_indices):
|
| 177 |
min_idx, max_idx = int(param_range_indices[0]), int(param_range_indices[1])
|
| 178 |
-
is_default_range = (min_idx == PARAM_CHOICES_DEFAULT_INDICES[0] and
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
# If a specific range is selected (not the default all-inclusive range), disable the checkbox
|
| 182 |
-
# and uncheck it to ensure consistency.
|
| 183 |
-
if not is_default_range:
|
| 184 |
-
return gr.update(interactive=False, value=False) # Disable and uncheck
|
| 185 |
-
else:
|
| 186 |
-
return gr.update(interactive=True) # Enable
|
| 187 |
|
| 188 |
param_range_slider.change(update_param_display, param_range_slider, param_range_display)
|
| 189 |
-
|
| 190 |
-
param_range_slider.change(
|
| 191 |
-
fn=_toggle_unknown_params_checkbox,
|
| 192 |
-
inputs=[param_range_slider],
|
| 193 |
-
outputs=[include_unknown_params_checkbox]
|
| 194 |
-
)
|
| 195 |
|
| 196 |
-
|
| 197 |
-
loading_complete_state.change(fn=_update_button_interactivity, inputs=loading_complete_state, outputs=generate_plot_button)
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
filter_choice_radio.change(fn=_toggle_filters_visibility, inputs=filter_choice_radio, outputs=[tag_filter_dropdown, pipeline_filter_dropdown])
|
| 202 |
|
| 203 |
-
## CHANGE: Renamed and modified ui_load_data_controller to also generate the initial plot
|
| 204 |
def load_and_generate_initial_plot(progress=gr.Progress()):
|
| 205 |
progress(0, desc=f"Loading dataset '{HF_DATASET_ID}'...")
|
| 206 |
-
|
| 207 |
try:
|
| 208 |
current_df, load_success_flag, status_msg_from_load = load_models_data()
|
| 209 |
if load_success_flag:
|
| 210 |
progress(0.5, desc="Processing data...")
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
data_info_text = f"### Data Information\n- Source: `{HF_DATASET_ID}`\n- Status: {status_msg_from_load}\n- Total models loaded: {len(current_df):,}\n- Models with known parameter counts: {param_count:,}\n- Models with unknown parameter counts: {unknown_param_count:,}\n- Data as of: {date_display}\n"
|
| 220 |
else:
|
| 221 |
data_info_text = f"### Data Load Failed\n- {status_msg_from_load}"
|
| 222 |
except Exception as e:
|
| 223 |
status_msg_from_load = f"An unexpected error occurred: {str(e)}"
|
| 224 |
data_info_text = f"### Critical Error\n- {status_msg_from_load}"
|
| 225 |
-
load_success_flag = False
|
| 226 |
-
current_df = pd.DataFrame()
|
| 227 |
print(f"Critical error in load_and_generate_initial_plot: {e}")
|
| 228 |
|
| 229 |
-
# --- Part 2: Generate Initial Plot ---
|
| 230 |
progress(0.6, desc="Generating initial plot...")
|
| 231 |
-
# Get default values directly from the UI component definitions
|
| 232 |
-
default_metric = "downloads"
|
| 233 |
-
default_filter_type = "None"
|
| 234 |
-
default_tag = None
|
| 235 |
-
default_pipeline = None
|
| 236 |
-
default_param_indices = PARAM_CHOICES_DEFAULT_INDICES
|
| 237 |
-
default_k = 25
|
| 238 |
-
default_skip_orgs = "TheBloke,MaziyarPanahi,unsloth,modularai,Gensyn,bartowski"
|
| 239 |
-
default_include_unknown_params = True
|
| 240 |
-
default_created_after_date = None # NEW: Default for date picker is no filter
|
| 241 |
-
|
| 242 |
-
# Reuse the existing controller function for plotting
|
| 243 |
initial_plot, initial_status = ui_generate_plot_controller(
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
default_created_after_date, # Pass new default date
|
| 247 |
-
current_df, progress
|
| 248 |
)
|
| 249 |
-
|
| 250 |
-
# Return all the necessary updates for the UI
|
| 251 |
return current_df, load_success_flag, data_info_text, initial_status, initial_plot
|
| 252 |
|
| 253 |
def ui_generate_plot_controller(metric_choice, filter_type, tag_choice, pipeline_choice,
|
| 254 |
param_range_indices, k_orgs, skip_orgs_input, include_unknown_param_size_flag,
|
| 255 |
-
created_after_date,
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
return create_treemap(pd.DataFrame(), metric_choice, "Error: Model Data Not Loaded"), "Model data is not loaded. Cannot generate plot."
|
| 259 |
|
| 260 |
progress(0.1, desc="Preparing data...")
|
| 261 |
-
|
| 262 |
-
pipeline_to_use = pipeline_choice if filter_type == "Pipeline Filter" else None
|
| 263 |
-
orgs_to_skip = [org.strip() for org in skip_orgs_input.split(',') if org.strip()]
|
| 264 |
-
|
| 265 |
-
min_label = PARAM_CHOICES[int(param_range_indices[0])]
|
| 266 |
-
max_label = PARAM_CHOICES[int(param_range_indices[1])]
|
| 267 |
-
param_labels_for_filtering = [min_label, max_label]
|
| 268 |
|
| 269 |
treemap_df = make_treemap_data(
|
| 270 |
-
df_current_models,
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
param_labels_for_filtering,
|
| 276 |
-
orgs_to_skip,
|
| 277 |
-
include_unknown_param_size_flag,
|
| 278 |
-
created_after_date # Pass the new date filter value
|
| 279 |
)
|
| 280 |
|
| 281 |
progress(0.7, desc="Generating plot...")
|
| 282 |
title_labels = {"downloads": "Downloads (last 30 days)", "downloadsAllTime": "Downloads (All Time)", "likes": "Likes"}
|
| 283 |
-
|
| 284 |
-
plotly_fig = create_treemap(treemap_df, metric_choice, chart_title)
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
else:
|
| 289 |
-
total_items_in_plot = len(treemap_df['id'].unique())
|
| 290 |
-
total_value_in_plot = treemap_df[metric_choice].sum()
|
| 291 |
-
plot_stats_md = f"## Plot Statistics\n- **Models shown**: {total_items_in_plot:,}\n- **Total {metric_choice}**: {int(total_value_in_plot):,}"
|
| 292 |
return plotly_fig, plot_stats_md
|
| 293 |
|
| 294 |
-
|
| 295 |
-
demo.load(
|
| 296 |
-
fn=load_and_generate_initial_plot,
|
| 297 |
-
inputs=[],
|
| 298 |
-
outputs=[models_data_state, loading_complete_state, data_info_md, status_message_md, plot_output]
|
| 299 |
-
)
|
| 300 |
|
| 301 |
generate_plot_button.click(
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
models_data_state
|
| 308 |
-
],
|
| 309 |
-
outputs=[plot_output, status_message_md]
|
| 310 |
)
|
| 311 |
|
| 312 |
if __name__ == "__main__":
|
|
|
|
| 23 |
dataset_dict = load_dataset(HF_DATASET_ID)
|
| 24 |
df = dataset_dict[list(dataset_dict.keys())[0]].to_pandas()
|
| 25 |
if 'params' in df.columns:
|
|
|
|
|
|
|
| 26 |
df['params'] = pd.to_numeric(df['params'], errors='coerce').fillna(-1)
|
| 27 |
else:
|
|
|
|
| 28 |
df['params'] = -1
|
| 29 |
|
| 30 |
+
# Ensure createdAt is in datetime format, coercing errors
|
| 31 |
if 'createdAt' in df.columns:
|
| 32 |
df['createdAt'] = pd.to_datetime(df['createdAt'], errors='coerce')
|
| 33 |
|
|
|
|
| 45 |
max_val = float('inf') if '>' in max_label else float(max_label.replace('B', ''))
|
| 46 |
return min_val, max_val
|
| 47 |
|
| 48 |
+
def make_treemap_data(df, count_by, top_k=25, tag_filter=None, pipeline_filter=None, param_range=None, skip_orgs=None, include_unknown_param_size=True, created_after_date=None):
|
| 49 |
if df is None or df.empty: return pd.DataFrame()
|
| 50 |
filtered_df = df.copy()
|
| 51 |
|
|
|
|
|
|
|
| 52 |
if not include_unknown_param_size and 'params' in filtered_df.columns:
|
| 53 |
filtered_df = filtered_df[filtered_df['params'] != -1]
|
| 54 |
|
|
|
|
| 60 |
if param_range:
|
| 61 |
min_params, max_params = get_param_range_values(param_range)
|
| 62 |
is_default_range = (param_range[0] == PARAM_CHOICES[0] and param_range[1] == PARAM_CHOICES[-1])
|
|
|
|
|
|
|
| 63 |
if not is_default_range and 'params' in filtered_df.columns:
|
| 64 |
if min_params is not None: filtered_df = filtered_df[filtered_df['params'] >= min_params]
|
| 65 |
if max_params is not None and max_params != float('inf'): filtered_df = filtered_df[filtered_df['params'] < max_params]
|
| 66 |
|
| 67 |
+
# Filter by creation date
|
| 68 |
if created_after_date is not None and 'createdAt' in filtered_df.columns:
|
| 69 |
+
# Filter out rows where createdAt is NaT (Not a Time) before comparison
|
| 70 |
+
filtered_df = filtered_df.dropna(subset=['createdAt'])
|
| 71 |
+
# The 'createdAt' column is already datetime from the loading function
|
| 72 |
+
filtered_df = filtered_df[filtered_df['createdAt'].dt.date > created_after_date]
|
| 73 |
+
|
| 74 |
|
| 75 |
if skip_orgs and len(skip_orgs) > 0 and "organization" in filtered_df.columns:
|
| 76 |
filtered_df = filtered_df[~filtered_df["organization"].isin(skip_orgs)]
|
|
|
|
| 93 |
fig.update_traces(textinfo="label+value+percent root", hovertemplate="<b>%{label}</b><br>%{value:,} " + count_by + "<br>%{percentRoot:.2%} of total<extra></extra>")
|
| 94 |
return fig
|
| 95 |
|
|
|
|
| 96 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
.model-parameters-group > .block {
|
| 98 |
background: none !important;
|
| 99 |
border: none !important;
|
| 100 |
box-shadow: none !important;
|
| 101 |
}
|
| 102 |
+
#param-slider-wrapper .head,
|
| 103 |
+
#param-slider-wrapper div[data-testid="range-slider"] > span {
|
| 104 |
+
display: none !important;
|
| 105 |
+
}
|
| 106 |
"""
|
| 107 |
|
| 108 |
with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True, css=custom_css) as demo:
|
|
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column(scale=1):
|
| 117 |
|
|
|
|
| 118 |
count_by_dropdown = gr.Dropdown(label="Metric", choices=[("Downloads (last 30 days)", "downloads"), ("Downloads (All Time)", "downloadsAllTime"), ("Likes", "likes")], value="downloads")
|
| 119 |
filter_choice_radio = gr.Radio(label="Filter Type", choices=["None", "Tag Filter", "Pipeline Filter"], value="None")
|
| 120 |
|
| 121 |
tag_filter_dropdown = gr.Dropdown(label="Select Tag", choices=TAG_FILTER_CHOICES, value=None, visible=False)
|
| 122 |
pipeline_filter_dropdown = gr.Dropdown(label="Select Pipeline Tag", choices=PIPELINE_TAGS, value=None, visible=False)
|
| 123 |
|
|
|
|
| 124 |
with gr.Group(elem_classes="model-parameters-group"):
|
| 125 |
gr.Markdown("<div style='font-weight: 500;'>Model Parameters</div>")
|
| 126 |
param_range_slider = RangeSlider(
|
| 127 |
+
minimum=0, maximum=len(PARAM_CHOICES) - 1, value=PARAM_CHOICES_DEFAULT_INDICES,
|
| 128 |
+
step=1, label=None, show_label=False, elem_id="param-slider-wrapper"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
)
|
| 130 |
param_range_display = gr.Markdown(f"Range: `{PARAM_CHOICES[0]}` to `{PARAM_CHOICES[-1]}`")
|
|
|
|
| 131 |
include_unknown_params_checkbox = gr.Checkbox(label="Include models with unknown parameter size", value=True)
|
| 132 |
|
| 133 |
+
# --- CORRECTED LINE ---
|
| 134 |
+
created_after_datepicker = gr.Date(label="Created After", value=None)
|
|
|
|
| 135 |
|
| 136 |
top_k_dropdown = gr.Dropdown(label="Number of Top Organizations", choices=TOP_K_CHOICES, value=25)
|
| 137 |
skip_orgs_textbox = gr.Textbox(label="Organizations to Skip (comma-separated)", value="TheBloke,MaziyarPanahi,unsloth,modularai,Gensyn,bartowski")
|
|
|
|
| 147 |
min_idx, max_idx = int(value[0]), int(value[1])
|
| 148 |
return f"Range: `{PARAM_CHOICES[min_idx]}` to `{PARAM_CHOICES[max_idx]}`"
|
| 149 |
|
|
|
|
| 150 |
def _toggle_unknown_params_checkbox(param_range_indices):
|
| 151 |
min_idx, max_idx = int(param_range_indices[0]), int(param_range_indices[1])
|
| 152 |
+
is_default_range = (min_idx == PARAM_CHOICES_DEFAULT_INDICES[0] and max_idx == PARAM_CHOICES_DEFAULT_INDICES[1])
|
| 153 |
+
return gr.update(interactive=is_default_range, value=True if is_default_range else False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
param_range_slider.change(update_param_display, param_range_slider, param_range_display)
|
| 156 |
+
param_range_slider.change(_toggle_unknown_params_checkbox, param_range_slider, include_unknown_params_checkbox)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
+
loading_complete_state.change(lambda is_loaded: gr.update(interactive=is_loaded), loading_complete_state, generate_plot_button)
|
|
|
|
| 159 |
|
| 160 |
+
filter_choice_radio.change(lambda choice: (gr.update(visible=choice == "Tag Filter"), gr.update(visible=choice == "Pipeline Filter")),
|
| 161 |
+
filter_choice_radio, [tag_filter_dropdown, pipeline_filter_dropdown])
|
|
|
|
| 162 |
|
|
|
|
| 163 |
def load_and_generate_initial_plot(progress=gr.Progress()):
|
| 164 |
progress(0, desc=f"Loading dataset '{HF_DATASET_ID}'...")
|
| 165 |
+
current_df, load_success_flag, status_msg_from_load = pd.DataFrame(), False, ""
|
| 166 |
try:
|
| 167 |
current_df, load_success_flag, status_msg_from_load = load_models_data()
|
| 168 |
if load_success_flag:
|
| 169 |
progress(0.5, desc="Processing data...")
|
| 170 |
+
ts = pd.to_datetime(current_df['data_download_timestamp'].iloc[0], utc=True) if 'data_download_timestamp' in current_df.columns and pd.notna(current_df['data_download_timestamp'].iloc[0]) else None
|
| 171 |
+
date_display = ts.strftime('%B %d, %Y, %H:%M:%S %Z') if ts else "Pre-processed (date unavailable)"
|
| 172 |
+
|
| 173 |
+
param_count = (current_df['params'] != -1).sum()
|
| 174 |
+
data_info_text = (f"### Data Information\n- Source: `{HF_DATASET_ID}`\n- Status: {status_msg_from_load}\n"
|
| 175 |
+
f"- Total models loaded: {len(current_df):,}\n- Models with known parameter counts: {param_count:,}\n"
|
| 176 |
+
f"- Models with unknown parameter counts: {len(current_df) - param_count:,}\n- Data as of: {date_display}\n")
|
|
|
|
|
|
|
| 177 |
else:
|
| 178 |
data_info_text = f"### Data Load Failed\n- {status_msg_from_load}"
|
| 179 |
except Exception as e:
|
| 180 |
status_msg_from_load = f"An unexpected error occurred: {str(e)}"
|
| 181 |
data_info_text = f"### Critical Error\n- {status_msg_from_load}"
|
|
|
|
|
|
|
| 182 |
print(f"Critical error in load_and_generate_initial_plot: {e}")
|
| 183 |
|
|
|
|
| 184 |
progress(0.6, desc="Generating initial plot...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
initial_plot, initial_status = ui_generate_plot_controller(
|
| 186 |
+
"downloads", "None", None, None, PARAM_CHOICES_DEFAULT_INDICES, 25,
|
| 187 |
+
"TheBloke,MaziyarPanahi,unsloth,modularai,Gensyn,bartowski", True, None, current_df, progress
|
|
|
|
|
|
|
| 188 |
)
|
|
|
|
|
|
|
| 189 |
return current_df, load_success_flag, data_info_text, initial_status, initial_plot
|
| 190 |
|
| 191 |
def ui_generate_plot_controller(metric_choice, filter_type, tag_choice, pipeline_choice,
|
| 192 |
param_range_indices, k_orgs, skip_orgs_input, include_unknown_param_size_flag,
|
| 193 |
+
created_after_date, df_current_models, progress=gr.Progress()):
|
| 194 |
+
if df_current_models.empty:
|
| 195 |
+
return create_treemap(pd.DataFrame(), metric_choice, "Error: Model Data Not Loaded"), "Model data is not loaded."
|
|
|
|
| 196 |
|
| 197 |
progress(0.1, desc="Preparing data...")
|
| 198 |
+
param_labels = [PARAM_CHOICES[int(param_range_indices[0])], PARAM_CHOICES[int(param_range_indices[1])]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
treemap_df = make_treemap_data(
|
| 201 |
+
df_current_models, metric_choice, k_orgs,
|
| 202 |
+
tag_choice if filter_type == "Tag Filter" else None,
|
| 203 |
+
pipeline_choice if filter_type == "Pipeline Filter" else None,
|
| 204 |
+
param_labels, [org.strip() for org in skip_orgs_input.split(',') if org.strip()],
|
| 205 |
+
include_unknown_param_size_flag, created_after_date
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
)
|
| 207 |
|
| 208 |
progress(0.7, desc="Generating plot...")
|
| 209 |
title_labels = {"downloads": "Downloads (last 30 days)", "downloadsAllTime": "Downloads (All Time)", "likes": "Likes"}
|
| 210 |
+
plotly_fig = create_treemap(treemap_df, metric_choice, f"HuggingFace Models - {title_labels.get(metric_choice, metric_choice)} by Organization")
|
|
|
|
| 211 |
|
| 212 |
+
plot_stats_md = (f"## Plot Statistics\n- **Models shown**: {len(treemap_df['id'].unique()):,}\n"
|
| 213 |
+
f"- **Total {metric_choice}**: {int(treemap_df[metric_choice].sum()):,}") if not treemap_df.empty else "No data matches the selected filters."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
return plotly_fig, plot_stats_md
|
| 215 |
|
| 216 |
+
demo.load(load_and_generate_initial_plot, None, [models_data_state, loading_complete_state, data_info_md, status_message_md, plot_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
generate_plot_button.click(
|
| 219 |
+
ui_generate_plot_controller,
|
| 220 |
+
[count_by_dropdown, filter_choice_radio, tag_filter_dropdown, pipeline_filter_dropdown,
|
| 221 |
+
param_range_slider, top_k_dropdown, skip_orgs_textbox, include_unknown_params_checkbox,
|
| 222 |
+
created_after_datepicker, models_data_state],
|
| 223 |
+
[plot_output, status_message_md]
|
|
|
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|