Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,172 +5,7 @@ from datetime import datetime, timedelta
|
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
|
8 |
-
|
9 |
-
if space_id is None or daily_ranks_df.empty:
|
10 |
-
return None
|
11 |
-
|
12 |
-
try:
|
13 |
-
space_data = daily_ranks_df[daily_ranks_df['id'] == space_id].copy()
|
14 |
-
if space_data.empty:
|
15 |
-
return None
|
16 |
-
|
17 |
-
space_data = space_data.sort_values('date')
|
18 |
-
|
19 |
-
fig = px.line(
|
20 |
-
space_data,
|
21 |
-
x='date',
|
22 |
-
y='rank',
|
23 |
-
title=f'Daily Rank Trend for {space_id}',
|
24 |
-
labels={'date': 'Date', 'rank': 'Rank'},
|
25 |
-
markers=True
|
26 |
-
)
|
27 |
-
|
28 |
-
fig.update_layout(
|
29 |
-
height=500,
|
30 |
-
xaxis_title="Date",
|
31 |
-
yaxis_title="Rank",
|
32 |
-
yaxis=dict(
|
33 |
-
range=[100, 1],
|
34 |
-
tickmode='linear',
|
35 |
-
tick0=1,
|
36 |
-
dtick=10
|
37 |
-
),
|
38 |
-
hovermode='x unified',
|
39 |
-
plot_bgcolor='white',
|
40 |
-
paper_bgcolor='white',
|
41 |
-
showlegend=False,
|
42 |
-
margin=dict(t=50, r=20, b=40, l=40)
|
43 |
-
)
|
44 |
-
|
45 |
-
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
46 |
-
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
47 |
-
|
48 |
-
fig.update_traces(
|
49 |
-
line_color='#2563eb',
|
50 |
-
line_width=2,
|
51 |
-
marker=dict(size=8, color='#2563eb')
|
52 |
-
)
|
53 |
-
|
54 |
-
return fig
|
55 |
-
except Exception as e:
|
56 |
-
print(f"Error creating chart: {e}")
|
57 |
-
return None
|
58 |
-
|
59 |
-
def create_space_card(space_info):
|
60 |
-
return f"""
|
61 |
-
<div class="space-card"
|
62 |
-
data-space-id="{space_info['id']}"
|
63 |
-
style="
|
64 |
-
border: 1px solid #e5e7eb;
|
65 |
-
border-radius: 8px;
|
66 |
-
padding: 16px;
|
67 |
-
margin: 8px;
|
68 |
-
background-color: white;
|
69 |
-
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
70 |
-
display: inline-block;
|
71 |
-
width: 250px;
|
72 |
-
vertical-align: top;
|
73 |
-
cursor: pointer;
|
74 |
-
transition: all 0.2s;
|
75 |
-
"
|
76 |
-
onmouseover="this.style.transform='translateY(-2px)';this.style.boxShadow='0 4px 6px rgba(0,0,0,0.1)';"
|
77 |
-
onmouseout="this.style.transform='none';this.style.boxShadow='0 1px 3px rgba(0,0,0,0.1)';"
|
78 |
-
>
|
79 |
-
<div style="font-size: 1.2em; font-weight: bold; margin-bottom: 8px;">
|
80 |
-
#{int(space_info['rank'])}
|
81 |
-
</div>
|
82 |
-
<div style="margin-bottom: 8px;">
|
83 |
-
<a href="https://huggingface.co/spaces/{space_info['id']}"
|
84 |
-
target="_blank"
|
85 |
-
style="color: #2563eb; text-decoration: none;"
|
86 |
-
onclick="event.stopPropagation();">
|
87 |
-
{space_info['id']}
|
88 |
-
<span style="font-size: 0.8em;">↗</span>
|
89 |
-
</a>
|
90 |
-
</div>
|
91 |
-
<div style="color: #666;">
|
92 |
-
Score: {space_info['trendingScore']:.2f}
|
93 |
-
</div>
|
94 |
-
</div>
|
95 |
-
"""
|
96 |
-
|
97 |
-
def update_display(selection):
|
98 |
-
global daily_ranks_df
|
99 |
-
|
100 |
-
if not selection:
|
101 |
-
return None, gr.HTML(value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>")
|
102 |
-
|
103 |
-
try:
|
104 |
-
space_id = selection
|
105 |
-
|
106 |
-
latest_data = daily_ranks_df[
|
107 |
-
daily_ranks_df['id'] == space_id
|
108 |
-
].sort_values('date').iloc[-1]
|
109 |
-
|
110 |
-
info_text = f"""
|
111 |
-
<div style="padding: 16px; background-color: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
112 |
-
<h3 style="margin: 0 0 12px 0;">Space Details</h3>
|
113 |
-
<p style="margin: 4px 0;"><strong>ID:</strong> {space_id}</p>
|
114 |
-
<p style="margin: 4px 0;"><strong>Current Rank:</strong> {int(latest_data['rank'])}</p>
|
115 |
-
<p style="margin: 4px 0;"><strong>Trending Score:</strong> {latest_data['trendingScore']:.2f}</p>
|
116 |
-
<p style="margin: 4px 0;"><strong>Created At:</strong> {latest_data['createdAt'].strftime('%Y-%m-%d')}</p>
|
117 |
-
<p style="margin: 12px 0 0 0;">
|
118 |
-
<a href="https://huggingface.co/spaces/{space_id}"
|
119 |
-
target="_blank"
|
120 |
-
style="color: #2563eb; text-decoration: none;">
|
121 |
-
View Space ↗
|
122 |
-
</a>
|
123 |
-
</p>
|
124 |
-
</div>
|
125 |
-
"""
|
126 |
-
|
127 |
-
chart = create_trend_chart(space_id, daily_ranks_df)
|
128 |
-
|
129 |
-
return chart, gr.HTML(value=info_text)
|
130 |
-
|
131 |
-
except Exception as e:
|
132 |
-
print(f"Error in update_display: {e}")
|
133 |
-
return None, gr.HTML(value=f"<div style='color: red;'>Error processing data: {str(e)}</div>")
|
134 |
-
|
135 |
-
def load_and_process_data():
|
136 |
-
try:
|
137 |
-
url = "https://huggingface.co/datasets/cfahlgren1/hub-stats/resolve/main/spaces.parquet"
|
138 |
-
response = requests.get(url)
|
139 |
-
df = pd.read_parquet(BytesIO(response.content))
|
140 |
-
|
141 |
-
thirty_days_ago = datetime.now() - timedelta(days=30)
|
142 |
-
df['createdAt'] = pd.to_datetime(df['createdAt'])
|
143 |
-
df = df[df['createdAt'] >= thirty_days_ago].copy()
|
144 |
-
|
145 |
-
dates = pd.date_range(start=thirty_days_ago, end=datetime.now(), freq='D')
|
146 |
-
daily_ranks = []
|
147 |
-
|
148 |
-
for date in dates:
|
149 |
-
date_data = df[df['createdAt'].dt.date <= date.date()].copy()
|
150 |
-
date_data = date_data.sort_values(['trendingScore', 'id'], ascending=[False, True])
|
151 |
-
date_data['rank'] = range(1, len(date_data) + 1)
|
152 |
-
date_data['date'] = date.date()
|
153 |
-
daily_ranks.append(
|
154 |
-
date_data[['id', 'date', 'rank', 'trendingScore', 'createdAt']]
|
155 |
-
)
|
156 |
-
|
157 |
-
daily_ranks_df = pd.concat(daily_ranks, ignore_index=True)
|
158 |
-
|
159 |
-
latest_date = daily_ranks_df['date'].max()
|
160 |
-
top_100_spaces = daily_ranks_df[
|
161 |
-
(daily_ranks_df['date'] == latest_date) &
|
162 |
-
(daily_ranks_df['rank'] <= 100)
|
163 |
-
].sort_values('rank').copy()
|
164 |
-
|
165 |
-
return daily_ranks_df, top_100_spaces
|
166 |
-
except Exception as e:
|
167 |
-
print(f"Error loading data: {e}")
|
168 |
-
return pd.DataFrame(), pd.DataFrame()
|
169 |
-
|
170 |
-
# 데이터 로드
|
171 |
-
print("Loading initial data...")
|
172 |
-
daily_ranks_df, top_100_spaces = load_and_process_data()
|
173 |
-
print("Data loaded successfully!")
|
174 |
|
175 |
# Gradio 인터페이스 생성
|
176 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
@@ -178,27 +13,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
178 |
# HF Space Ranking Tracker
|
179 |
|
180 |
Track, analyze, and discover trending AI applications in the Hugging Face ecosystem. Our service continuously monitors and ranks all Spaces over a 30-day period, providing detailed analytics and daily ranking changes for the top 100 performers.
|
181 |
-
|
182 |
-
### What We Track
|
183 |
-
- Daily ranking changes for all Hugging Face Spaces
|
184 |
-
- Comprehensive trending scores based on 30-day activity
|
185 |
-
- Detailed performance metrics for top 100 Spaces
|
186 |
-
- Historical ranking data with daily granularity
|
187 |
-
|
188 |
-
### Key Features
|
189 |
-
- **Real-time Rankings**: Stay updated with daily rank changes
|
190 |
-
- **Interactive Visualizations**: Track ranking trajectories over time
|
191 |
-
- **Trend Analysis**: Identify emerging popular AI applications
|
192 |
-
- **Direct Access**: Quick links to explore trending Spaces
|
193 |
-
- **Performance Metrics**: Detailed trending scores and statistics
|
194 |
""")
|
195 |
|
196 |
with gr.Tabs():
|
197 |
with gr.Tab("Dashboard"):
|
198 |
-
with gr.Row():
|
199 |
trend_plot = gr.Plot(
|
200 |
label="Daily Rank Trend",
|
201 |
-
container=True
|
|
|
202 |
)
|
203 |
|
204 |
with gr.Row():
|
@@ -221,6 +44,21 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
221 |
|
222 |
with gr.Tab("About"):
|
223 |
gr.Markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
### Why Use HF Space Ranking Tracker?
|
225 |
- Discover trending AI demos and applications
|
226 |
- Monitor your Space's performance and popularity
|
@@ -233,7 +71,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
233 |
Experience the pulse of the AI community through our daily updated rankings and discover what's making waves in the world of practical AI applications.
|
234 |
""")
|
235 |
|
236 |
-
#
|
237 |
space_grid.click(
|
238 |
None,
|
239 |
None,
|
|
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
|
8 |
+
[이전 함수들은 동일하게 유지...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Gradio 인터페이스 생성
|
11 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
13 |
# HF Space Ranking Tracker
|
14 |
|
15 |
Track, analyze, and discover trending AI applications in the Hugging Face ecosystem. Our service continuously monitors and ranks all Spaces over a 30-day period, providing detailed analytics and daily ranking changes for the top 100 performers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
""")
|
17 |
|
18 |
with gr.Tabs():
|
19 |
with gr.Tab("Dashboard"):
|
20 |
+
with gr.Row(variant="panel"):
|
21 |
trend_plot = gr.Plot(
|
22 |
label="Daily Rank Trend",
|
23 |
+
container=True,
|
24 |
+
height=400
|
25 |
)
|
26 |
|
27 |
with gr.Row():
|
|
|
44 |
|
45 |
with gr.Tab("About"):
|
46 |
gr.Markdown("""
|
47 |
+
### Our Tracking System
|
48 |
+
|
49 |
+
#### What We Track
|
50 |
+
- Daily ranking changes for all Hugging Face Spaces
|
51 |
+
- Comprehensive trending scores based on 30-day activity
|
52 |
+
- Detailed performance metrics for top 100 Spaces
|
53 |
+
- Historical ranking data with daily granularity
|
54 |
+
|
55 |
+
#### Key Features
|
56 |
+
- **Real-time Rankings**: Stay updated with daily rank changes
|
57 |
+
- **Interactive Visualizations**: Track ranking trajectories over time
|
58 |
+
- **Trend Analysis**: Identify emerging popular AI applications
|
59 |
+
- **Direct Access**: Quick links to explore trending Spaces
|
60 |
+
- **Performance Metrics**: Detailed trending scores and statistics
|
61 |
+
|
62 |
### Why Use HF Space Ranking Tracker?
|
63 |
- Discover trending AI demos and applications
|
64 |
- Monitor your Space's performance and popularity
|
|
|
71 |
Experience the pulse of the AI community through our daily updated rankings and discover what's making waves in the world of practical AI applications.
|
72 |
""")
|
73 |
|
74 |
+
# JavaScript 이벤트 처리
|
75 |
space_grid.click(
|
76 |
None,
|
77 |
None,
|