app
Browse files- app.py +191 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
import plotly.graph_objects as go
|
5 |
+
from huggingface_hub import HfApi
|
6 |
+
from datetime import datetime
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
def format_number(num):
|
10 |
+
"""Format large numbers with K, M suffix"""
|
11 |
+
if num >= 1e6:
|
12 |
+
return f"{num/1e6:.1f}M"
|
13 |
+
elif num >= 1e3:
|
14 |
+
return f"{num/1e3:.1f}K"
|
15 |
+
return str(num)
|
16 |
+
|
17 |
+
def fetch_stats():
|
18 |
+
"""Fetch all DeepSeek model statistics"""
|
19 |
+
api = HfApi()
|
20 |
+
|
21 |
+
# Fetch original models
|
22 |
+
original_models = [
|
23 |
+
"deepseek-ai/deepseek-r1",
|
24 |
+
"deepseek-ai/deepseek-r1-zero",
|
25 |
+
"deepseek-ai/deepseek-r1-distill-llama-70b",
|
26 |
+
"deepseek-ai/deepseek-r1-distill-qwen-32b",
|
27 |
+
"deepseek-ai/deepseek-r1-distill-qwen-14b",
|
28 |
+
"deepseek-ai/deepseek-r1-distill-llama-8b",
|
29 |
+
"deepseek-ai/deepseek-r1-distill-qwen-7b",
|
30 |
+
"deepseek-ai/deepseek-r1-distill-qwen-1.5b"
|
31 |
+
]
|
32 |
+
|
33 |
+
original_stats = []
|
34 |
+
for model_id in original_models:
|
35 |
+
try:
|
36 |
+
info = api.model_info(model_id)
|
37 |
+
original_stats.append({
|
38 |
+
'model_id': model_id,
|
39 |
+
'downloads_30d': info.downloads if hasattr(info, 'downloads') else 0,
|
40 |
+
'likes': info.likes if hasattr(info, 'likes') else 0
|
41 |
+
})
|
42 |
+
except Exception as e:
|
43 |
+
print(f"Error fetching {model_id}: {str(e)}")
|
44 |
+
|
45 |
+
# Fetch derivative models - using the tag format that works
|
46 |
+
model_types = ["adapter", "finetune", "merge", "quantized"]
|
47 |
+
base_models = [
|
48 |
+
"DeepSeek-R1",
|
49 |
+
"DeepSeek-R1-Zero",
|
50 |
+
"DeepSeek-R1-Distill-Llama-70B",
|
51 |
+
"DeepSeek-R1-Distill-Qwen-32B",
|
52 |
+
"DeepSeek-R1-Distill-Qwen-14B",
|
53 |
+
"DeepSeek-R1-Distill-Llama-8B",
|
54 |
+
"DeepSeek-R1-Distill-Qwen-7B",
|
55 |
+
"DeepSeek-R1-Distill-Qwen-1.5B"
|
56 |
+
]
|
57 |
+
|
58 |
+
derivative_stats = []
|
59 |
+
|
60 |
+
for base_model in base_models:
|
61 |
+
for model_type in model_types:
|
62 |
+
try:
|
63 |
+
# Get models for this type
|
64 |
+
models = list(api.list_models(
|
65 |
+
filter=f"base_model:{model_type}:deepseek-ai/{base_model}",
|
66 |
+
full=True
|
67 |
+
))
|
68 |
+
|
69 |
+
# Add each model to our stats
|
70 |
+
for model in models:
|
71 |
+
derivative_stats.append({
|
72 |
+
'base_model': f"deepseek-ai/{base_model}",
|
73 |
+
'model_type': model_type,
|
74 |
+
'model_id': model.id,
|
75 |
+
'downloads_30d': model.downloads if hasattr(model, 'downloads') else 0,
|
76 |
+
'likes': model.likes if hasattr(model, 'likes') else 0
|
77 |
+
})
|
78 |
+
except Exception as e:
|
79 |
+
print(f"Error fetching {model_type} models for {base_model}: {str(e)}")
|
80 |
+
|
81 |
+
# Create DataFrames
|
82 |
+
original_df = pd.DataFrame(original_stats, columns=['model_id', 'downloads_30d', 'likes'])
|
83 |
+
derivative_df = pd.DataFrame(derivative_stats, columns=['base_model', 'model_type', 'model_id', 'downloads_30d', 'likes'])
|
84 |
+
|
85 |
+
return original_df, derivative_df
|
86 |
+
|
87 |
+
def create_stats_html():
|
88 |
+
"""Create HTML for displaying statistics"""
|
89 |
+
original_df, derivative_df = fetch_stats()
|
90 |
+
|
91 |
+
# Create summary statistics
|
92 |
+
total_originals = len(original_df)
|
93 |
+
total_derivatives = len(derivative_df)
|
94 |
+
total_downloads_orig = original_df['downloads_30d'].sum()
|
95 |
+
total_downloads_deriv = derivative_df['downloads_30d'].sum()
|
96 |
+
|
97 |
+
# Create derivative type distribution chart
|
98 |
+
if len(derivative_df) > 0:
|
99 |
+
# Create distribution by model type
|
100 |
+
type_dist = derivative_df.groupby('model_type').agg({
|
101 |
+
'model_id': 'count',
|
102 |
+
'downloads_30d': 'sum'
|
103 |
+
}).reset_index()
|
104 |
+
|
105 |
+
# Format model types to be more readable
|
106 |
+
type_dist['model_type'] = type_dist['model_type'].str.capitalize()
|
107 |
+
|
108 |
+
# Create bar chart with better formatting
|
109 |
+
fig_types = px.bar(
|
110 |
+
type_dist,
|
111 |
+
x='model_type',
|
112 |
+
y='downloads_30d',
|
113 |
+
title='Downloads by Model Type',
|
114 |
+
labels={
|
115 |
+
'downloads_30d': 'Downloads (last 30 days)',
|
116 |
+
'model_type': 'Model Type'
|
117 |
+
},
|
118 |
+
text=type_dist['downloads_30d'].apply(format_number) # Add value labels
|
119 |
+
)
|
120 |
+
|
121 |
+
# Update layout for better readability
|
122 |
+
fig_types.update_traces(textposition='outside')
|
123 |
+
fig_types.update_layout(
|
124 |
+
uniformtext_minsize=8,
|
125 |
+
uniformtext_mode='hide',
|
126 |
+
xaxis_tickangle=0,
|
127 |
+
yaxis_title="Downloads",
|
128 |
+
plot_bgcolor='white',
|
129 |
+
bargap=0.3
|
130 |
+
)
|
131 |
+
|
132 |
+
else:
|
133 |
+
# Create empty figure if no data
|
134 |
+
fig_types = px.bar(title='No data available')
|
135 |
+
|
136 |
+
# Create top models table
|
137 |
+
if len(derivative_df) > 0:
|
138 |
+
top_models = derivative_df.nlargest(10, 'downloads_30d')[
|
139 |
+
['model_id', 'model_type', 'downloads_30d', 'likes']
|
140 |
+
].copy() # Create a copy to avoid SettingWithCopyWarning
|
141 |
+
|
142 |
+
# Capitalize model types in the table
|
143 |
+
top_models['model_type'] = top_models['model_type'].str.capitalize()
|
144 |
+
|
145 |
+
# Format download numbers
|
146 |
+
top_models['downloads_30d'] = top_models['downloads_30d'].apply(format_number)
|
147 |
+
else:
|
148 |
+
top_models = pd.DataFrame(columns=['model_id', 'model_type', 'downloads_30d', 'likes'])
|
149 |
+
|
150 |
+
|
151 |
+
# Format the summary statistics
|
152 |
+
summary_html = f"""
|
153 |
+
<div style='padding: 20px; background-color: #f5f5f5; border-radius: 10px; margin-bottom: 20px;'>
|
154 |
+
<h3>Summary Statistics</h3>
|
155 |
+
<p>Derivative Models Downloads: {format_number(total_downloads_deriv)} ({total_derivatives} models)</p>
|
156 |
+
<p>Original Models Downloads: {format_number(total_downloads_orig)} ({total_originals} models)</p>
|
157 |
+
<p>Last Updated: {datetime.now().strftime('%Y-%m-%d %H:%M UTC')}</p>
|
158 |
+
</div>
|
159 |
+
"""
|
160 |
+
|
161 |
+
return summary_html, fig_types, top_models
|
162 |
+
|
163 |
+
def create_interface():
|
164 |
+
"""Create Gradio interface"""
|
165 |
+
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
166 |
+
gr.HTML("<h1 style='text-align: center;'>DeepSeek Models Stats</h1>")
|
167 |
+
|
168 |
+
with gr.Row():
|
169 |
+
with gr.Column():
|
170 |
+
summary_html = gr.HTML()
|
171 |
+
with gr.Column():
|
172 |
+
plot = gr.Plot()
|
173 |
+
|
174 |
+
with gr.Row():
|
175 |
+
table = gr.DataFrame(
|
176 |
+
headers=["Model ID", "Type", "Downloads (30d)", "Likes"],
|
177 |
+
label="Top 10 Most Downloaded Models"
|
178 |
+
)
|
179 |
+
|
180 |
+
def update_stats():
|
181 |
+
summary, fig, top_models = create_stats_html()
|
182 |
+
return summary, fig, top_models
|
183 |
+
|
184 |
+
interface.load(update_stats,
|
185 |
+
outputs=[summary_html, plot, table])
|
186 |
+
|
187 |
+
return interface
|
188 |
+
|
189 |
+
# Create and launch the interface
|
190 |
+
demo = create_interface()
|
191 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pandas
|
3 |
+
plotly
|
4 |
+
huggingface_hub
|