File size: 12,389 Bytes
7007406
fd38574
b466419
 
fd38574
 
 
de24f31
fd38574
8206722
 
 
 
 
 
 
 
 
 
7007406
 
 
b466419
fd38574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe161c7
 
 
 
 
 
 
 
 
 
 
 
 
b466419
 
 
 
 
fe161c7
 
b466419
8206722
 
 
b466419
7007406
 
 
b466419
8206722
 
 
b466419
 
 
 
 
 
 
 
 
 
 
8206722
 
b466419
 
 
fd38574
 
 
 
77e9502
 
 
 
b466419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77e9502
b466419
77e9502
 
 
 
 
 
 
 
 
b466419
77e9502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b466419
 
8206722
77e9502
 
 
 
 
 
 
 
 
 
fd38574
77e9502
fd38574
 
b466419
 
 
 
77e9502
 
 
 
 
 
 
 
 
 
 
b466419
 
8206722
 
 
 
 
 
 
 
b466419
8206722
 
 
 
 
b466419
77e9502
b466419
7007406
 
 
 
 
 
 
 
 
 
 
 
 
 
b466419
 
 
8206722
 
77e9502
8206722
 
 
 
 
b466419
8206722
 
 
 
 
 
b466419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd38574
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
from dash import Dash, html, dcc, Input, Output
import pandas as pd
from graphs.model_market_share import create_stacked_area_chart, create_world_map, create_range_slider, create_leaderboard
from graphs.model_characteristics import create_concentration_chart, create_line_plot

# Initialize the app
app = Dash()
server = app.server

# Load pre-processed data frames
model_topk_df = pd.read_pickle("data_frames/model_topk_df.pkl")
model_gini_df = pd.read_pickle("data_frames/model_gini_df.pkl")
model_hhi_df = pd.read_pickle("data_frames/model_hhi_df.pkl")
language_concentration_df = pd.read_pickle("data_frames/language_concentration_df.pkl")
license_concentration_df = pd.read_pickle("data_frames/download_license_cumsum_df.pkl")
download_method_cumsum_df = pd.read_pickle("data_frames/download_method_cumsum_df.pkl")
download_arch_cumsum_df = pd.read_pickle("data_frames/download_arch_cumsum_df.pkl")
nat_topk_df = pd.read_pickle("data_frames/nat_topk_df.pkl")
country_concentration_df = pd.read_pickle("data_frames/country_concentration_df.pkl")
author_concentration_df = pd.read_pickle("data_frames/author_concentration_df.pkl")
model_concentration_df = pd.read_pickle("data_frames/model_concentration_df.pkl")

# Configurations
TEMP_MODEL_EVENTS = {
    # "Yolo World Mirror": "2024-03-01",
    "Llama 3": "2024-04-17",
    "Stable Cascade": "2024-02-02",
    "Stable Diffusion 3": "2024-05-30",
    # "embed/upscale": "2023-03-24",
    "DeepSeek-R1": "2025-01-20",
    "Gemma-3 12B QAT": "2025-04-15", # gemma-3-12b-it-qat-4bit
    # "Qwen": "2025-03-05",
    # "Flux RedFlux": "2025-04-12",
    # "DeepSeek-V3": "2025-03-24",
    # "bloom": "2022-05-19",
    "DALLE2-PyTorch": "2022-06-25",
    "Stable Diffusion": "2022-08-10",
    "CLIP ViT": "2021-01-05",
    "YOLOv8": "2023-04-26",
    "Sentence Transformer MiniLM v2": "2021-08-30",
}

PALETTE_0 = [
    "#335C67",
    "#FFF3B0",
    "#E09F3E",
    "#9E2A2B",
    "#540B0E"
]

LANG_SEGMENT_ORDER = [
    'Monolingual: EN', 'Monolingual: HR', 'Monolingual: M/LR', 
    'Multilingual: HR', 'Multilingual', 'Unknown',
]

LICENSE_SEGMENT_ORDER = [
    "Open Use", "Open Use (Acceptable Use Policy)", "Open Use (Non-Commercial Only)", "Attribution", 
    "Acceptable Use Policy", "Non-Commercial Only", "Undocumented", "Undocumented (Acceptable Use Policy)",
]

METHOD_PLOT_CHOICES = {
    "cumulative": "none", # none, mean, sum
    "y_col": "percent", # percent count
    "y_log": False, # True, False
    "period": "W",
}

ARCHITECTURE_PLOT_CHOICES = {
    "cumulative": "none", # none, mean, sum
    "y_col": "percent", # percent count
    "y_log": False, # True, False
    "period": "W",
}

# Create initial figures
# Model Market Share Tab
model_market_share_area = create_stacked_area_chart(
    model_topk_df, model_gini_df, model_hhi_df, TEMP_MODEL_EVENTS, PALETTE_0
)

world_map = create_world_map(
    country_concentration_df, "time", "metric", "value"
)

leaderboard = create_leaderboard(
    country_concentration_df, author_concentration_df, model_concentration_df
)

slider = create_range_slider(
    model_topk_df
)

# Model Characteristics Tab
language_concentration_area = create_concentration_chart(
    language_concentration_df, 'time', 'metric', 'value', LANG_SEGMENT_ORDER, PALETTE_0
)

license_concentration_area = create_concentration_chart(
    license_concentration_df, 'period', 'status', 'percent', LICENSE_SEGMENT_ORDER, PALETTE_0
)

download_method_cumsum_line = create_line_plot(
    download_method_cumsum_df, METHOD_PLOT_CHOICES, PALETTE_0
)

download_arch_cumsum_line = create_line_plot(
    download_arch_cumsum_df, ARCHITECTURE_PLOT_CHOICES, PALETTE_0
)

# App layout
app.layout = html.Div(
    [
        html.Div(
            [
                html.Div(children='Visualizing the Open Model Ecosystem', style={'fontSize': 28, 'fontWeight': 'bold', 'marginBottom': 6}),
                html.Div(children='An interactive dashboard to explore trends in open models on Hugging Face', style={'fontSize': 16, 'marginBottom': 12}),
                html.Div(
                    children=[
                        html.A(
                            "Data Provenance Initiative",
                            href="https://www.dataprovenance.org/",
                            target="_blank",
                            style={
                                'display': 'inline-block',
                                'padding': '4px 14px',
                                'fontSize': 13,
                                'color': 'white',
                                'backgroundColor': '#2563eb',
                                'border': 'none',
                                'borderRadius': '18px',
                                'textDecoration': 'none',
                                'fontWeight': 'bold',
                                'boxShadow': '0 2px 8px rgba(37,99,235,0.08)',
                                'marginLeft': '6px',
                                'marginBottom': '4px',
                                'transition': 'background 0.2s',
                                'cursor': 'pointer'
                            }
                        )
                    ],
                    style={'fontSize': 14, 'marginBottom': 12}
                ),
                html.Hr(style={'marginTop': 8, 'marginBottom': 8}),
                html.Div(children='Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.', style={'fontSize': 14, 'marginBottom': 12, 'marginLeft': 100, 'marginRight': 100}),
            ],
            style={'textAlign': 'center'}
        ),
        html.Div(
            [
                dcc.Tabs([
                    dcc.Tab(label='Model Market Share', children=[
                        html.Div([
                            html.Div(children='Select time range to update all graphs below:', style={'fontSize': 16, 'marginBottom': 6, 'marginTop': 10}),
                            dcc.Graph(figure=slider, id='time-slider', style={'height': '100px'}),
                            html.Div(
                                id='output-container-range-slider',
                                style={
                                    'textAlign': 'center',
                                    'fontSize': 20,
                                    'marginBottom': 15,
                                    'marginTop': 30,
                                    'backgroundColor': 'white',
                                    'borderRadius': '12px',
                                    'boxShadow': '0 2px 12px rgba(0,0,0,0.10)',
                                    'padding': '18px',
                                    'display': 'inline-block',
                                }
                            ),
                        ], style={'marginBottom': 12, 'justifyContent': 'center', 'textAlign': 'center'}),
                        html.Div([
                            dcc.Graph(id='stacked-area-chart'),
                        ], style={'marginBottom': 12}),
                        html.Div([
                            html.Div(
                                dcc.Graph(id='world-map-with-slider'),
                                style={'display': 'flex', 'justifyContent': 'center'}
                            ),
                            dcc.Graph(id='leaderboard'),
                        ], style={'marginBottom': 12})
                    ]),
                    dcc.Tab(label='Model Characteristics', children=[
                        dcc.Graph(id='language-concentration-chart'),
                        html.Div([
                            dcc.Dropdown(['Language Concentration', 'Architecture', 'License', 'Method'], 'Language Concentration', id='dropdown'),
                        ], style={'marginTop': 6}),
                    ]),
                    dcc.Tab(label='Model Relationships', children=[
                    ]),
                ])
            ],
            style={
                'backgroundColor': 'white',
                'borderRadius': '18px',
                'boxShadow': '0 4px 24px rgba(0,0,0,0.10)',
                'padding': '32px',
                'margin': '32px auto',
                'maxWidth': '1250px',
            }
        )
    ],
    style={'fontFamily': 'Inter', 'backgroundColor': '#f7f7fa', 'minHeight': '100vh'}
)

# Callbacks for interactivity

# Model Market Share Tab
# On slider change, update output text
@app.callback(
    Output('output-container-range-slider', 'children'),
    [Input('time-slider', 'relayoutData')]
)
def update_output(relayout_data):
    if relayout_data and 'xaxis.range[0]' in relayout_data and 'xaxis.range[1]' in relayout_data:
        start_time = pd.to_datetime(relayout_data['xaxis.range[0]']).strftime('%Y-%m-%d')
        end_time = pd.to_datetime(relayout_data['xaxis.range[1]']).strftime('%Y-%m-%d')
        return f'Selected time range: {start_time} to {end_time}'
    else:
        return 'Selected time range: All data'

# On slider change, update world map
@app.callback(
    Output('world-map-with-slider', 'figure'),
    [Input('time-slider', 'relayoutData')]
)
def update_map(relayout_data):
    if relayout_data and 'xaxis.range[0]' in relayout_data and 'xaxis.range[1]' in relayout_data:
        start_time = pd.to_datetime(relayout_data['xaxis.range[0]']).strftime('%Y-%m-%d')
        end_time = pd.to_datetime(relayout_data['xaxis.range[1]']).strftime('%Y-%m-%d')
        updated_fig = create_world_map(
            country_concentration_df, "time", "metric", "value", start_time=start_time, end_time=end_time
        )
        updated_fig.update_layout(font_family="Inter")
        return updated_fig
    else:
        return world_map

# On slider change, update leaderboard
@app.callback(
    Output('leaderboard', 'figure'),
    [Input('time-slider', 'relayoutData')]
)
def update_leaderboard(relayout_data):
    if relayout_data and 'xaxis.range[0]' in relayout_data and 'xaxis.range[1]' in relayout_data:
        start_time = pd.to_datetime(relayout_data['xaxis.range[0]']).strftime('%Y-%m-%d')
        end_time = pd.to_datetime(relayout_data['xaxis.range[1]']).strftime('%Y-%m-%d')
        updated_fig = create_leaderboard(
            country_concentration_df, author_concentration_df, model_concentration_df, start_time=start_time, end_time=end_time
        )
        updated_fig.update_layout(font_family="Inter")
        return updated_fig
    else:
        return leaderboard

# On slider change, update stacked area chart
@app.callback(
    Output('stacked-area-chart', 'figure'),
    [Input('time-slider', 'relayoutData')]
)
def update_stacked_area(relayout_data):
    if relayout_data and 'xaxis.range[0]' in relayout_data and 'xaxis.range[1]' in relayout_data:
        start_time = pd.to_datetime(relayout_data['xaxis.range[0]']).strftime('%Y-%m-%d')
        end_time = pd.to_datetime(relayout_data['xaxis.range[1]']).strftime('%Y-%m-%d')
        updated_fig = create_stacked_area_chart(
            model_topk_df, model_gini_df, model_hhi_df, TEMP_MODEL_EVENTS, PALETTE_0,
            start_time=start_time, end_time=end_time
        )
        updated_fig.update_layout(font_family="Inter")
        return updated_fig
    else:
        return model_market_share_area
    
# Model Characteristics Tab
# On dropdown change, update graph
@app.callback(
    Output('language-concentration-chart', 'figure'),
    [Input('dropdown', 'value')]
)
def update_graph(selected_metric):
    if selected_metric == 'Language Concentration':
        return language_concentration_area
    elif selected_metric == 'License':
        return license_concentration_area
    elif selected_metric == 'Method':
        return download_method_cumsum_line
    elif selected_metric == 'Architecture':
        return download_arch_cumsum_line

# Run the app
if __name__ == '__main__':
    app.run(debug=True)