fdaudens HF Staff commited on
Commit
0c70ea0
·
verified ·
1 Parent(s): 209042f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -35
app.py CHANGED
@@ -86,70 +86,60 @@ def create_stats_html():
86
  """Create HTML for displaying statistics"""
87
  original_df, derivative_df = fetch_stats()
88
 
 
89
  total_originals = len(original_df)
90
  total_derivatives = len(derivative_df)
91
  total_downloads_orig = original_df['downloads_30d'].sum()
92
  total_downloads_deriv = derivative_df['downloads_30d'].sum()
93
 
 
94
  if len(derivative_df) > 0:
 
95
  type_dist = derivative_df.groupby('model_type').agg({
96
  'model_id': 'count',
97
  'downloads_30d': 'sum'
98
  }).reset_index()
99
- type_dist['model_type'] = type_dist['model_type'].str.capitalize()
100
- type_dist = type_dist.sort_values('downloads_30d', ascending=True)
101
 
 
 
 
 
 
 
 
 
 
102
  fig_types = go.Figure(data=[
103
  go.Bar(
104
- x=list(type_dist['model_type']),
105
- y=list(type_dist['downloads_30d'].values),
106
  marker_color='rgb(55, 83, 109)'
107
  )
108
  ])
109
-
110
  fig_types.update_layout(
111
- yaxis=dict(
112
- type='log',
113
- title='Downloads (log scale)'
114
- ),
115
- showlegend=False,
116
  plot_bgcolor='white',
117
- autosize=True,
118
- margin=dict(
119
- l=50,
120
- r=50,
121
- t=100,
122
- b=50,
123
- pad=4
124
- )
125
  )
126
-
127
  fig_types.update_traces(
128
- textposition='outside',
129
- cliponaxis=False
130
  )
131
-
132
- fig_types.update_layout(
133
- {
134
- 'xaxis': {'automargin': True},
135
- 'yaxis': {'automargin': True},
136
- 'autosize': True,
137
- }
138
- )
139
-
140
  else:
141
  fig_types = px.bar(title='No data available')
142
-
143
- # Create top models table
144
  if len(derivative_df) > 0:
145
  top_models = derivative_df.nlargest(10, 'downloads_30d')[
146
  ['model_id', 'model_type', 'downloads_30d', 'likes']
147
- ].copy()
148
 
149
- # Capitalize model types in the table
150
  top_models['model_type'] = top_models['model_type'].str.capitalize()
151
 
152
- # Format download numbers
153
  top_models['downloads_30d'] = top_models['downloads_30d'].apply(format_number)
154
  else:
155
  top_models = pd.DataFrame(columns=['model_id', 'model_type', 'downloads_30d', 'likes'])
 
86
  """Create HTML for displaying statistics"""
87
  original_df, derivative_df = fetch_stats()
88
 
89
+ # Create summary statistics
90
  total_originals = len(original_df)
91
  total_derivatives = len(derivative_df)
92
  total_downloads_orig = original_df['downloads_30d'].sum()
93
  total_downloads_deriv = derivative_df['downloads_30d'].sum()
94
 
95
+ # Create derivative type distribution chart
96
  if len(derivative_df) > 0:
97
+ # Create distribution by model type
98
  type_dist = derivative_df.groupby('model_type').agg({
99
  'model_id': 'count',
100
  'downloads_30d': 'sum'
101
  }).reset_index()
 
 
102
 
103
+ type_dist = derivative_df.groupby('model_type').agg({
104
+ 'model_id': 'count',
105
+ 'downloads_30d': 'sum'
106
+ }).reset_index()
107
+
108
+ type_dist['model_type'] = type_dist['model_type'].str.capitalize()
109
+
110
+ type_dist = type_dist.sort_values('downloads_30d', ascending=True)
111
+
112
  fig_types = go.Figure(data=[
113
  go.Bar(
114
+ x=list(type_dist['model_type']), # Convert to list
115
+ y=list(type_dist['downloads_30d'].values), # Convert series to list of values
116
  marker_color='rgb(55, 83, 109)'
117
  )
118
  ])
119
+
120
  fig_types.update_layout(
121
+ title='Downloads by Model Type',
122
+ #xaxis_title='Model Type',
123
+ yaxis_title='Downloads',
 
 
124
  plot_bgcolor='white',
125
+ showlegend=False,
126
+ bargap=0.3
 
 
 
 
 
 
127
  )
128
+
129
  fig_types.update_traces(
130
+ text=type_dist['downloads_30d'].apply(format_number),
131
+ textposition='outside'
132
  )
 
 
 
 
 
 
 
 
 
133
  else:
134
  fig_types = px.bar(title='No data available')
135
+
 
136
  if len(derivative_df) > 0:
137
  top_models = derivative_df.nlargest(10, 'downloads_30d')[
138
  ['model_id', 'model_type', 'downloads_30d', 'likes']
139
+ ].copy() # Create a copy to avoid SettingWithCopyWarning
140
 
 
141
  top_models['model_type'] = top_models['model_type'].str.capitalize()
142
 
 
143
  top_models['downloads_30d'] = top_models['downloads_30d'].apply(format_number)
144
  else:
145
  top_models = pd.DataFrame(columns=['model_id', 'model_type', 'downloads_30d', 'likes'])