evijit HF Staff commited on
Commit
eec69ec
·
verified ·
1 Parent(s): 59d14c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,14 +1,14 @@
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import plotly.express as px
4
  import time
5
  from datasets import load_dataset
6
- # --- FIX 1: Import the new, stable RangeSlider component ---
7
  from gradio_rangeslider import RangeSlider
8
 
9
  # --- Constants ---
10
  PARAM_CHOICES = ['< 1B', '1B', '5B', '12B', '32B', '64B', '128B', '256B', '> 500B']
11
- # The new component uses a tuple for its default value
12
  PARAM_CHOICES_DEFAULT_INDICES = (0, len(PARAM_CHOICES) - 1)
13
 
14
  TOP_K_CHOICES = list(range(5, 51, 5))
@@ -80,6 +80,10 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
80
  models_data_state = gr.State(pd.DataFrame())
81
  loading_complete_state = gr.State(False)
82
 
 
 
 
 
83
  with gr.Row():
84
  with gr.Column(scale=1):
85
  count_by_dropdown = gr.Dropdown(label="Metric", choices=[("Downloads (last 30 days)", "downloads"), ("Downloads (All Time)", "downloadsAllTime"), ("Likes", "likes")], value="downloads")
@@ -87,7 +91,6 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
87
  tag_filter_dropdown = gr.Dropdown(label="Select Tag", choices=TAG_FILTER_CHOICES, value=None, visible=False)
88
  pipeline_filter_dropdown = gr.Dropdown(label="Select Pipeline Tag", choices=PIPELINE_TAGS, value=None, visible=False)
89
 
90
- # --- FIX 2: Replace all previous slider attempts with the stable custom component ---
91
  param_range_slider = RangeSlider(
92
  minimum=0,
93
  maximum=len(PARAM_CHOICES) - 1,
@@ -95,7 +98,7 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
95
  step=1,
96
  label="Parameters"
97
  )
98
- # This markdown will display the selected range labels
99
  param_range_display = gr.Markdown(f"Range: `{PARAM_CHOICES[0]}` to `{PARAM_CHOICES[-1]}`")
100
 
101
  top_k_dropdown = gr.Dropdown(label="Number of Top Organizations", choices=TOP_K_CHOICES, value=25)
@@ -107,7 +110,6 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
107
  status_message_md = gr.Markdown("Initializing...")
108
  data_info_md = gr.Markdown("")
109
 
110
- # Event handler to update the text display when the slider changes
111
  def update_param_display(value: tuple):
112
  min_idx, max_idx = int(value[0]), int(value[1])
113
  return f"Range: `{PARAM_CHOICES[min_idx]}` to `{PARAM_CHOICES[max_idx]}`"
@@ -168,12 +170,10 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
168
  plot_stats_md = "No data matches the selected filters. Please try different options."
169
  else:
170
  total_items_in_plot = len(treemap_df['id'].unique())
171
- # --- FIX 3: Corrected the NameError from the traceback ---
172
  total_value_in_plot = treemap_df[metric_choice].sum()
173
  plot_stats_md = f"## Plot Statistics\n- **Models shown**: {total_items_in_plot:,}\n- **Total {metric_choice}**: {int(total_value_in_plot):,}"
174
  return plotly_fig, plot_stats_md
175
 
176
- # A standard load event, no JS needed anymore.
177
  demo.load(
178
  fn=ui_load_data_controller,
179
  inputs=[],
@@ -189,4 +189,6 @@ with gr.Blocks(title="🤗 ModelVerse Explorer", fill_width=True) as demo:
189
 
190
  if __name__ == "__main__":
191
  print(f"Application starting...")
192
- demo.queue().launch()
 
 
 
1
+ # --- START OF FINAL POLISHED FILE app.py ---
2
+
3
  import gradio as gr
4
  import pandas as pd
5
  import plotly.express as px
6
  import time
7
  from datasets import load_dataset
 
8
  from gradio_rangeslider import RangeSlider
9
 
10
  # --- Constants ---
11
  PARAM_CHOICES = ['< 1B', '1B', '5B', '12B', '32B', '64B', '128B', '256B', '> 500B']
 
12
  PARAM_CHOICES_DEFAULT_INDICES = (0, len(PARAM_CHOICES) - 1)
13
 
14
  TOP_K_CHOICES = list(range(5, 51, 5))
 
80
  models_data_state = gr.State(pd.DataFrame())
81
  loading_complete_state = gr.State(False)
82
 
83
+ # --- FIX 1: The application title is restored here ---
84
+ with gr.Row():
85
+ gr.Markdown("# 🤗 ModelVerse Explorer")
86
+
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
  count_by_dropdown = gr.Dropdown(label="Metric", choices=[("Downloads (last 30 days)", "downloads"), ("Downloads (All Time)", "downloadsAllTime"), ("Likes", "likes")], value="downloads")
 
91
  tag_filter_dropdown = gr.Dropdown(label="Select Tag", choices=TAG_FILTER_CHOICES, value=None, visible=False)
92
  pipeline_filter_dropdown = gr.Dropdown(label="Select Pipeline Tag", choices=PIPELINE_TAGS, value=None, visible=False)
93
 
 
94
  param_range_slider = RangeSlider(
95
  minimum=0,
96
  maximum=len(PARAM_CHOICES) - 1,
 
98
  step=1,
99
  label="Parameters"
100
  )
101
+ # This markdown provides the meaningful labels for the slider's numeric range
102
  param_range_display = gr.Markdown(f"Range: `{PARAM_CHOICES[0]}` to `{PARAM_CHOICES[-1]}`")
103
 
104
  top_k_dropdown = gr.Dropdown(label="Number of Top Organizations", choices=TOP_K_CHOICES, value=25)
 
110
  status_message_md = gr.Markdown("Initializing...")
111
  data_info_md = gr.Markdown("")
112
 
 
113
  def update_param_display(value: tuple):
114
  min_idx, max_idx = int(value[0]), int(value[1])
115
  return f"Range: `{PARAM_CHOICES[min_idx]}` to `{PARAM_CHOICES[max_idx]}`"
 
170
  plot_stats_md = "No data matches the selected filters. Please try different options."
171
  else:
172
  total_items_in_plot = len(treemap_df['id'].unique())
 
173
  total_value_in_plot = treemap_df[metric_choice].sum()
174
  plot_stats_md = f"## Plot Statistics\n- **Models shown**: {total_items_in_plot:,}\n- **Total {metric_choice}**: {int(total_value_in_plot):,}"
175
  return plotly_fig, plot_stats_md
176
 
 
177
  demo.load(
178
  fn=ui_load_data_controller,
179
  inputs=[],
 
189
 
190
  if __name__ == "__main__":
191
  print(f"Application starting...")
192
+ demo.queue().launch()
193
+
194
+ # --- END OF FINAL POLISHED FILE app.py ---