File size: 7,295 Bytes
c13b993
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c70ea0
c13b993
 
 
 
 
0c70ea0
c13b993
0c70ea0
209042f
 
 
 
c13b993
0c70ea0
 
 
 
 
 
 
 
 
209042f
 
0c70ea0
 
209042f
 
 
0c70ea0
c13b993
0c70ea0
 
 
cc73002
0c70ea0
 
cc73002
0c70ea0
cc73002
0c70ea0
 
c13b993
 
cc73002
0c70ea0
c13b993
 
 
0c70ea0
c13b993
181ebc9
c13b993
 
181ebc9
c13b993
181ebc9
68919cf
181ebc9
761d959
181ebc9
c13b993
68919cf
 
c13b993
 
ffed801
 
 
 
6274a38
c13b993
 
 
 
 
 
 
 
3b09729
c13b993
 
 
 
 
 
 
 
68919cf
 
 
 
 
 
c13b993
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from huggingface_hub import HfApi
from datetime import datetime
import numpy as np

def format_number(num):
    """Format large numbers with K, M suffix"""
    if num >= 1e6:
        return f"{num/1e6:.1f}M"
    elif num >= 1e3:
        return f"{num/1e3:.1f}K"
    return str(num)

def fetch_stats():
    """Fetch all DeepSeek model statistics"""
    api = HfApi()
    
    # Fetch original models
    original_models = [
        "deepseek-ai/deepseek-r1",
        "deepseek-ai/deepseek-r1-zero",
        "deepseek-ai/deepseek-r1-distill-llama-70b",
        "deepseek-ai/deepseek-r1-distill-qwen-32b",
        "deepseek-ai/deepseek-r1-distill-qwen-14b",
        "deepseek-ai/deepseek-r1-distill-llama-8b",
        "deepseek-ai/deepseek-r1-distill-qwen-7b",
        "deepseek-ai/deepseek-r1-distill-qwen-1.5b"
    ]
    
    original_stats = []
    for model_id in original_models:
        try:
            info = api.model_info(model_id)
            original_stats.append({
                'model_id': model_id,
                'downloads_30d': info.downloads if hasattr(info, 'downloads') else 0,
                'likes': info.likes if hasattr(info, 'likes') else 0
            })
        except Exception as e:
            print(f"Error fetching {model_id}: {str(e)}")
    
    model_types = ["adapter", "finetune", "merge", "quantized"]
    base_models = [
        "DeepSeek-R1",
        "DeepSeek-R1-Zero",
        "DeepSeek-R1-Distill-Llama-70B",
        "DeepSeek-R1-Distill-Qwen-32B",
        "DeepSeek-R1-Distill-Qwen-14B",
        "DeepSeek-R1-Distill-Llama-8B",
        "DeepSeek-R1-Distill-Qwen-7B",
        "DeepSeek-R1-Distill-Qwen-1.5B"
    ]
    
    derivative_stats = []
    
    for base_model in base_models:
        for model_type in model_types:
            try:
                models = list(api.list_models(
                    filter=f"base_model:{model_type}:deepseek-ai/{base_model}",
                    full=True
                ))
                
                # Add each model to our stats
                for model in models:
                    derivative_stats.append({
                        'base_model': f"deepseek-ai/{base_model}",
                        'model_type': model_type,
                        'model_id': model.id,
                        'downloads_30d': model.downloads if hasattr(model, 'downloads') else 0,
                        'likes': model.likes if hasattr(model, 'likes') else 0
                    })
            except Exception as e:
                print(f"Error fetching {model_type} models for {base_model}: {str(e)}")
    
    # Create DataFrames
    original_df = pd.DataFrame(original_stats, columns=['model_id', 'downloads_30d', 'likes'])
    derivative_df = pd.DataFrame(derivative_stats, columns=['base_model', 'model_type', 'model_id', 'downloads_30d', 'likes'])
    
    return original_df, derivative_df

def create_stats_html():
    """Create HTML for displaying statistics"""
    original_df, derivative_df = fetch_stats()
    
    # Create summary statistics
    total_originals = len(original_df)
    total_derivatives = len(derivative_df)
    total_downloads_orig = original_df['downloads_30d'].sum()
    total_downloads_deriv = derivative_df['downloads_30d'].sum()
    
    # Create derivative type distribution chart
    if len(derivative_df) > 0:
        # Create distribution by model type
        type_dist = derivative_df.groupby('model_type').agg({
            'model_id': 'count',
            'downloads_30d': 'sum'
        }).reset_index()
        
        type_dist = derivative_df.groupby('model_type').agg({
            'model_id': 'count',
            'downloads_30d': 'sum'
        }).reset_index()

        type_dist['model_type'] = type_dist['model_type'].str.capitalize()

        type_dist = type_dist.sort_values('downloads_30d', ascending=True)

        fig_types = go.Figure(data=[
            go.Bar(
                x=list(type_dist['model_type']),  # Convert to list
                y=list(type_dist['downloads_30d'].values),  # Convert series to list of values
                marker_color='rgb(55, 83, 109)'
            )
        ])

        fig_types.update_layout(
            title='Downloads by Model Type',
            #xaxis_title='Model Type',
            yaxis_title='Downloads',
            plot_bgcolor='white',
            showlegend=False,
            bargap=0.3
        )

        fig_types.update_traces(
            text=type_dist['downloads_30d'].apply(format_number),
            textposition='outside'
        )
    else:
        fig_types = px.bar(title='No data available')
    
    if len(derivative_df) > 0:
        top_models = derivative_df.nlargest(10, 'downloads_30d')[
            ['model_id', 'model_type', 'downloads_30d', 'likes']
        ].copy()  # Create a copy to avoid SettingWithCopyWarning
        
        # Capitalize model types in the table
        top_models['model_type'] = top_models['model_type'].str.capitalize()
        
        # Format download numbers
        top_models['downloads_30d'] = top_models['downloads_30d'].apply(format_number)
        
        # Create clickable links for model_id
        top_models['model_id'] = top_models['model_id'].apply(
            lambda x: f'<a href="https://huggingface.co./{x}" target="_blank" onclick="window.open(\'https://huggingface.co./{x}\', \'_blank\')">{x}</a>'
        )
    else:
        top_models = pd.DataFrame(columns=['model_id', 'model_type', 'downloads_30d', 'likes'])

    summary_html = f"""
    <div style='padding: 20px; background-color: #f5f5f5; border-radius: 10px; margin-bottom: 20px;'>
        <h3 style='color: #333333;'>Summary Statistics</h3>
        <p style='color: #333333;'>Derivative Models Downloads: {format_number(total_downloads_deriv)} ({total_derivatives} models)</p>
        <p style='color: #333333;'>Original Models Downloads: {format_number(total_downloads_orig)} ({total_originals} models)</p>
        <p style='color: #333333;'>Last Updated: {datetime.now().strftime('%Y-%m-%d %H:%M UTC')}</p>
        <p style='color: #333333; font-size: 10px;'>* Last 30 days downloads</p>
    </div>
    """
    
    return summary_html, fig_types, top_models

def create_interface():
    """Create Gradio interface"""
    with gr.Blocks(theme=gr.themes.Soft()) as interface:
        gr.HTML("<h1 style='text-align: center;'>DeepSeek-R1 Models Stats</h1>")
        
        with gr.Row():
            with gr.Column():
                summary_html = gr.HTML()
            with gr.Column():
                plot = gr.Plot()

        with gr.Row():
            table = gr.DataFrame(
                headers=["Model ID", "Type", "Downloads (30d)", "Likes"],
                label="Top 10 Most Downloaded Models",
                wrap=True,
                datatype=["html", "str", "str", "number"]
            )
        
        def update_stats():
            summary, fig, top_models = create_stats_html()
            return summary, fig, top_models
        
        interface.load(update_stats, 
                      outputs=[summary_html, plot, table])
        
    return interface

# Create and launch the interface
demo = create_interface()
demo.launch()