Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,64 +6,10 @@ import requests
|
|
| 6 |
from io import BytesIO
|
| 7 |
import traceback
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
space_data = daily_ranks_df[daily_ranks_df['id'] == space_id].copy()
|
| 15 |
-
if space_data.empty:
|
| 16 |
-
return None
|
| 17 |
-
|
| 18 |
-
space_data = space_data.sort_values('date')
|
| 19 |
-
|
| 20 |
-
fig = px.line(
|
| 21 |
-
space_data,
|
| 22 |
-
x='date',
|
| 23 |
-
y='rank',
|
| 24 |
-
title=f'Daily Rank Trend for {space_id}',
|
| 25 |
-
labels={'date': 'Date', 'rank': 'Rank'},
|
| 26 |
-
markers=True,
|
| 27 |
-
height=400
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
fig.update_layout(
|
| 31 |
-
xaxis_title="Date",
|
| 32 |
-
yaxis_title="Rank",
|
| 33 |
-
yaxis=dict(
|
| 34 |
-
range=[100, 1], # ๋ญํน์ด 1์ด ์ต๊ณ ์ด๋ฏ๋ก y์ถ์ ๋ค์ง์ด์ ํ์
|
| 35 |
-
tickmode='linear',
|
| 36 |
-
tick0=1,
|
| 37 |
-
dtick=10
|
| 38 |
-
),
|
| 39 |
-
hovermode='x unified',
|
| 40 |
-
plot_bgcolor='white',
|
| 41 |
-
paper_bgcolor='white',
|
| 42 |
-
showlegend=False,
|
| 43 |
-
margin=dict(t=50, r=20, b=40, l=40)
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
| 47 |
-
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
| 48 |
-
|
| 49 |
-
fig.update_traces(
|
| 50 |
-
line_color='#2563eb',
|
| 51 |
-
line_width=2,
|
| 52 |
-
marker=dict(size=8, color='#2563eb')
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
return fig
|
| 56 |
-
except Exception as e:
|
| 57 |
-
print(f"Error creating trend chart: {e}")
|
| 58 |
-
traceback.print_exc()
|
| 59 |
-
return None
|
| 60 |
-
|
| 61 |
def load_and_process_data():
|
| 62 |
-
"""
|
| 63 |
-
1) spaces.parquet๋ฅผ ๋ค์ด๋ก๋ํ์ฌ DataFrame์ผ๋ก ๋ณํ
|
| 64 |
-
2) ์ต๊ทผ 30์ผ์น ๋ฐ์ดํฐ๋ง ํํฐ๋ง
|
| 65 |
-
3) ๋งค ์ผ์๋ณ๋ก trendingScore ๋ด๋ฆผ์ฐจ์์ผ๋ก rank๋ฅผ ๋งค๊ธด ๋ค, ๋์
|
| 66 |
-
"""
|
| 67 |
try:
|
| 68 |
url = "https://huggingface.co/datasets/cfahlgren1/hub-stats/resolve/main/spaces.parquet"
|
| 69 |
response = requests.get(url)
|
|
@@ -74,7 +20,7 @@ def load_and_process_data():
|
|
| 74 |
df['createdAt'] = pd.to_datetime(df['createdAt'])
|
| 75 |
df = df[df['createdAt'] >= thirty_days_ago].copy()
|
| 76 |
|
| 77 |
-
# 30์ผ ๋์์ ๋ชจ๋ ๋ ์ง์ ๋ํด
|
| 78 |
dates = pd.date_range(start=thirty_days_ago, end=datetime.now(), freq='D')
|
| 79 |
daily_ranks = []
|
| 80 |
|
|
@@ -85,64 +31,58 @@ def load_and_process_data():
|
|
| 85 |
date_data = date_data.sort_values(['trendingScore', 'id'], ascending=[False, True])
|
| 86 |
date_data['rank'] = range(1, len(date_data) + 1)
|
| 87 |
date_data['date'] = date.date()
|
| 88 |
-
|
| 89 |
daily_ranks.append(
|
| 90 |
date_data[['id', 'date', 'rank', 'trendingScore', 'createdAt']]
|
| 91 |
)
|
| 92 |
|
| 93 |
-
# ํ๋ฃจํ๋ฃจ ์์ธ rank ๊ธฐ๋ก์ ๋ชจ๋ ํฉ์นจ
|
| 94 |
daily_ranks_df = pd.concat(daily_ranks, ignore_index=True)
|
| 95 |
|
| 96 |
-
# ์ต์ ๋ ์ง์
|
| 97 |
latest_date = daily_ranks_df['date'].max()
|
| 98 |
-
|
| 99 |
(daily_ranks_df['date'] == latest_date) &
|
| 100 |
-
(daily_ranks_df['rank'] <=
|
| 101 |
].sort_values('rank').copy()
|
| 102 |
|
| 103 |
-
return daily_ranks_df,
|
| 104 |
except Exception as e:
|
| 105 |
print(f"Error loading data: {e}")
|
| 106 |
traceback.print_exc()
|
| 107 |
return pd.DataFrame(), pd.DataFrame()
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
"""
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
"""
|
| 114 |
-
if
|
| 115 |
return pd.DataFrame()
|
| 116 |
|
| 117 |
try:
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
# ์ต์ ๋ ์ง์ Top100๋ง ํํฐ๋ง
|
| 122 |
-
latest_top100 = daily_ranks_df[
|
| 123 |
-
(daily_ranks_df['date'] == latest_date) & (daily_ranks_df['rank'] <= 100)
|
| 124 |
-
].copy()
|
| 125 |
-
|
| 126 |
-
# id๋ณ ๋ฑ์ฅ ํ์ (Top100 ๋ด)
|
| 127 |
-
id_counts = latest_top100['id'].value_counts()
|
| 128 |
# 2๊ฐ ์ด์ ๋ฑ์ฅํ๋ id๋ง ์ถ์ถ
|
| 129 |
multiple_ids = id_counts[id_counts >= 2].index
|
| 130 |
|
| 131 |
if len(multiple_ids) == 0:
|
| 132 |
-
# ์ค๋ณต id๊ฐ ์์
|
| 133 |
return pd.DataFrame()
|
| 134 |
|
| 135 |
-
# ์ค๋ณต๋ id์ ํด๋นํ๋ ํ๋ง
|
| 136 |
-
multiple_entries =
|
| 137 |
|
| 138 |
-
# id
|
| 139 |
df_sum = (multiple_entries
|
| 140 |
.groupby('id')['trendingScore']
|
| 141 |
.sum()
|
| 142 |
.reset_index()
|
| 143 |
.rename(columns={'trendingScore': 'total_score'}))
|
| 144 |
|
| 145 |
-
# ํฉ์ฐ๋ total_score
|
| 146 |
df_sum = df_sum.sort_values(by='total_score', ascending=False).head(20)
|
| 147 |
|
| 148 |
return df_sum
|
|
@@ -151,14 +91,16 @@ def get_top20_multiple_ids(daily_ranks_df):
|
|
| 151 |
traceback.print_exc()
|
| 152 |
return pd.DataFrame()
|
| 153 |
|
|
|
|
|
|
|
|
|
|
| 154 |
def create_score_chart(multiple_ids_df):
|
| 155 |
"""
|
| 156 |
-
|
| 157 |
-
id๋ณ total_score ๋ง๋ ์ฐจํธ๋ฅผ ์์ฑ. ์์ 20๊ฐ๋ง ํ์.
|
| 158 |
"""
|
| 159 |
try:
|
| 160 |
if multiple_ids_df.empty:
|
| 161 |
-
# ์ค๋ณต๋ id
|
| 162 |
placeholder_df = pd.DataFrame({"id": ["No multiple entries"], "total_score": [0]})
|
| 163 |
fig = px.bar(
|
| 164 |
placeholder_df,
|
|
@@ -167,7 +109,7 @@ def create_score_chart(multiple_ids_df):
|
|
| 167 |
orientation='h'
|
| 168 |
)
|
| 169 |
fig.update_layout(
|
| 170 |
-
title="No multiple entries found in Top
|
| 171 |
xaxis_title="Total Trending Score",
|
| 172 |
yaxis_title="Space ID",
|
| 173 |
plot_bgcolor='white',
|
|
@@ -177,17 +119,15 @@ def create_score_chart(multiple_ids_df):
|
|
| 177 |
)
|
| 178 |
return fig
|
| 179 |
|
| 180 |
-
#
|
| 181 |
-
df = multiple_ids_df.copy()
|
| 182 |
-
|
| 183 |
fig = px.bar(
|
| 184 |
-
|
| 185 |
y='id',
|
| 186 |
x='total_score',
|
| 187 |
orientation='h',
|
| 188 |
-
title=
|
| 189 |
-
|
| 190 |
-
|
| 191 |
)
|
| 192 |
|
| 193 |
fig.update_layout(
|
|
@@ -197,7 +137,7 @@ def create_score_chart(multiple_ids_df):
|
|
| 197 |
paper_bgcolor='white',
|
| 198 |
showlegend=False,
|
| 199 |
margin=dict(l=200, r=20, t=40, b=40),
|
| 200 |
-
yaxis={'categoryorder': 'total ascending'}
|
| 201 |
)
|
| 202 |
|
| 203 |
fig.update_traces(
|
|
@@ -214,10 +154,71 @@ def create_score_chart(multiple_ids_df):
|
|
| 214 |
traceback.print_exc()
|
| 215 |
return None
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
def update_display(selection):
|
| 218 |
"""
|
| 219 |
-
์ฌ์ฉ์๊ฐ
|
| 220 |
-
๊ทธ id
|
|
|
|
| 221 |
"""
|
| 222 |
global daily_ranks_df
|
| 223 |
|
|
@@ -227,6 +228,7 @@ def update_display(selection):
|
|
| 227 |
try:
|
| 228 |
space_id = selection
|
| 229 |
|
|
|
|
| 230 |
latest_data = daily_ranks_df[
|
| 231 |
daily_ranks_df['id'] == space_id
|
| 232 |
].sort_values('date').iloc[-1]
|
|
@@ -256,59 +258,54 @@ def update_display(selection):
|
|
| 256 |
print(f"Error in update_display: {e}")
|
| 257 |
return None, gr.HTML(value=f"<div style='color: red;'>Error processing data: {str(e)}</div>")
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
print("Loading initial data...")
|
| 263 |
-
daily_ranks_df,
|
| 264 |
print("Data loaded successfully!")
|
| 265 |
|
| 266 |
-
#
|
| 267 |
-
multiple_ids_df = get_top20_multiple_ids(
|
| 268 |
score_chart = create_score_chart(multiple_ids_df)
|
| 269 |
|
| 270 |
-
# Gradio ์ธํฐํ์ด์ค
|
| 271 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 272 |
gr.Markdown("""
|
| 273 |
# HF Space Ranking Tracker
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
providing detailed analytics and daily ranking changes for the top 100 performers.
|
| 278 |
""")
|
| 279 |
|
| 280 |
with gr.Tabs():
|
| 281 |
with gr.Tab("Dashboard"):
|
| 282 |
with gr.Row(variant="panel"):
|
| 283 |
-
# ์ผ์ชฝ(Trend Plot)
|
| 284 |
with gr.Column(scale=7):
|
| 285 |
trend_plot = gr.Plot(
|
| 286 |
label="Daily Rank Trend",
|
| 287 |
container=True
|
| 288 |
)
|
| 289 |
-
# ์ค๋ฅธ์ชฝ(Score Chart)
|
| 290 |
with gr.Column(scale=3):
|
| 291 |
-
# multiple_ids_df ๊ธฐ๋ฐ ์ฐจํธ
|
| 292 |
score_plot = gr.Plot(
|
| 293 |
value=score_chart,
|
| 294 |
label="Multiple-Entry IDs (Top 20)",
|
| 295 |
container=True
|
| 296 |
)
|
| 297 |
|
| 298 |
-
# Space ์์ธ ์ ๋ณด
|
| 299 |
with gr.Row():
|
| 300 |
info_box = gr.HTML(
|
| 301 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 302 |
)
|
| 303 |
|
| 304 |
-
# ๋ผ๋์ค ๋ฒํผ(
|
| 305 |
space_selection = gr.Radio(
|
| 306 |
-
choices=[row['id'] for _, row in
|
| 307 |
value=None,
|
| 308 |
visible=False
|
| 309 |
)
|
| 310 |
|
| 311 |
-
#
|
| 312 |
html_content = """
|
| 313 |
<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>
|
| 314 |
""" + "".join([
|
|
@@ -320,7 +317,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 320 |
border-radius: 8px;
|
| 321 |
padding: 16px;
|
| 322 |
margin: 8px;
|
| 323 |
-
background-color: hsl(210, {max(30, 90 - (row['rank'] /
|
| 324 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 325 |
display: inline-block;
|
| 326 |
width: 250px;
|
|
@@ -354,7 +351,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 354 |
</div>
|
| 355 |
</div>
|
| 356 |
"""
|
| 357 |
-
for _, row in
|
| 358 |
]) + """
|
| 359 |
</div>
|
| 360 |
<script>
|
|
@@ -374,42 +371,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 374 |
|
| 375 |
with gr.Tab("About"):
|
| 376 |
gr.Markdown("""
|
| 377 |
-
###
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
- Daily ranking changes for all Hugging Face Spaces
|
| 381 |
-
- Comprehensive trending scores based on 30-day activity
|
| 382 |
-
- Detailed performance metrics for top 100 Spaces
|
| 383 |
-
- Historical ranking data with daily granularity
|
| 384 |
-
|
| 385 |
-
#### Key Features
|
| 386 |
-
- **Real-time Rankings**: Stay updated with daily rank changes
|
| 387 |
-
- **Interactive Visualizations**: Track ranking trajectories over time
|
| 388 |
-
- **Trend Analysis**: Identify emerging popular AI applications
|
| 389 |
-
- **Direct Access**: Quick links to explore trending Spaces
|
| 390 |
-
- **Performance Metrics**: Detailed trending scores and statistics
|
| 391 |
-
|
| 392 |
-
### Why Use HF Space Ranking Tracker?
|
| 393 |
-
- Discover trending AI demos and applications
|
| 394 |
-
- Monitor your Space's performance and popularity
|
| 395 |
-
- Identify emerging trends in the AI community
|
| 396 |
-
- Make data-driven decisions about your AI projects
|
| 397 |
-
- Stay ahead of the curve in AI application development
|
| 398 |
-
|
| 399 |
-
Our dashboard provides a comprehensive view of the Hugging Face Spaces ecosystem,
|
| 400 |
-
helping developers, researchers, and enthusiasts track and understand
|
| 401 |
-
the dynamics of popular AI applications.
|
| 402 |
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
| 405 |
""")
|
| 406 |
|
| 407 |
-
# ๋ผ๋์ค ๋ฒํผ change ์ด๋ฒคํธ -> update_display ํจ์
|
| 408 |
space_selection.change(
|
| 409 |
fn=update_display,
|
| 410 |
inputs=[space_selection],
|
| 411 |
-
outputs=[trend_plot, info_box]
|
| 412 |
-
api_name="update_display"
|
| 413 |
)
|
| 414 |
|
| 415 |
if __name__ == "__main__":
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
import traceback
|
| 8 |
|
| 9 |
+
######################################
|
| 10 |
+
# 1) ๋ฐ์ดํฐ ๋ก๋ & 30์ผ์น ๋ญํน ์ฐ์ถ
|
| 11 |
+
######################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def load_and_process_data():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
url = "https://huggingface.co/datasets/cfahlgren1/hub-stats/resolve/main/spaces.parquet"
|
| 15 |
response = requests.get(url)
|
|
|
|
| 20 |
df['createdAt'] = pd.to_datetime(df['createdAt'])
|
| 21 |
df = df[df['createdAt'] >= thirty_days_ago].copy()
|
| 22 |
|
| 23 |
+
# 30์ผ ๋์์ ๋ชจ๋ ๋ ์ง์ ๋ํด ์ํ
|
| 24 |
dates = pd.date_range(start=thirty_days_ago, end=datetime.now(), freq='D')
|
| 25 |
daily_ranks = []
|
| 26 |
|
|
|
|
| 31 |
date_data = date_data.sort_values(['trendingScore', 'id'], ascending=[False, True])
|
| 32 |
date_data['rank'] = range(1, len(date_data) + 1)
|
| 33 |
date_data['date'] = date.date()
|
|
|
|
| 34 |
daily_ranks.append(
|
| 35 |
date_data[['id', 'date', 'rank', 'trendingScore', 'createdAt']]
|
| 36 |
)
|
| 37 |
|
|
|
|
| 38 |
daily_ranks_df = pd.concat(daily_ranks, ignore_index=True)
|
| 39 |
|
| 40 |
+
# ์ต์ ๋ ์ง์ (๋ญํน 1000์ ์ดํ)๋ง ์ถ์ถ โ ์ฌ๊ธฐ์ ๋ฒ์๋ฅผ 1000์ผ๋ก ํ์ฅ!
|
| 41 |
latest_date = daily_ranks_df['date'].max()
|
| 42 |
+
top_1000_spaces = daily_ranks_df[
|
| 43 |
(daily_ranks_df['date'] == latest_date) &
|
| 44 |
+
(daily_ranks_df['rank'] <= 1000)
|
| 45 |
].sort_values('rank').copy()
|
| 46 |
|
| 47 |
+
return daily_ranks_df, top_1000_spaces
|
| 48 |
except Exception as e:
|
| 49 |
print(f"Error loading data: {e}")
|
| 50 |
traceback.print_exc()
|
| 51 |
return pd.DataFrame(), pd.DataFrame()
|
| 52 |
|
| 53 |
+
######################################
|
| 54 |
+
# 2) ์ค๋ณต ID(2๊ฐ ์ด์) ํฉ์ฐ -> ์์ 20
|
| 55 |
+
######################################
|
| 56 |
+
def get_top20_multiple_ids(top_n_spaces_df):
|
| 57 |
"""
|
| 58 |
+
์ฃผ์ด์ง ๋ฐ์ดํฐํ๋ ์(์: top_1000_spaces)์์,
|
| 59 |
+
๋์ผํ id๊ฐ 2๋ฒ ์ด์ ๋ฑ์ฅํ๋ ๊ฒฝ์ฐ 'trendingScore'๋ฅผ ํฉ์ฐํ๊ณ ,
|
| 60 |
+
ํฉ์ฐ ์ ์๊ฐ ๋์ ์์ผ๋ก ์์ 20๊ฐ๋ง ๋ฐํ
|
| 61 |
"""
|
| 62 |
+
if top_n_spaces_df.empty:
|
| 63 |
return pd.DataFrame()
|
| 64 |
|
| 65 |
try:
|
| 66 |
+
# id๋ณ ๋ฑ์ฅ ํ์
|
| 67 |
+
id_counts = top_n_spaces_df['id'].value_counts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# 2๊ฐ ์ด์ ๋ฑ์ฅํ๋ id๋ง ์ถ์ถ
|
| 69 |
multiple_ids = id_counts[id_counts >= 2].index
|
| 70 |
|
| 71 |
if len(multiple_ids) == 0:
|
| 72 |
+
# ์ค๋ณต id๊ฐ ์์ ์์ผ๋ฉด ๋น DF
|
| 73 |
return pd.DataFrame()
|
| 74 |
|
| 75 |
+
# ์ค๋ณต๋ id์ ํด๋นํ๋ ํ๋ง ํํฐ๋ง
|
| 76 |
+
multiple_entries = top_n_spaces_df[top_n_spaces_df['id'].isin(multiple_ids)].copy()
|
| 77 |
|
| 78 |
+
# id๋ณ ์ค์ฝ์ด ํฉ์ฐ
|
| 79 |
df_sum = (multiple_entries
|
| 80 |
.groupby('id')['trendingScore']
|
| 81 |
.sum()
|
| 82 |
.reset_index()
|
| 83 |
.rename(columns={'trendingScore': 'total_score'}))
|
| 84 |
|
| 85 |
+
# ํฉ์ฐ๋ total_score ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ -> ์์ 20
|
| 86 |
df_sum = df_sum.sort_values(by='total_score', ascending=False).head(20)
|
| 87 |
|
| 88 |
return df_sum
|
|
|
|
| 91 |
traceback.print_exc()
|
| 92 |
return pd.DataFrame()
|
| 93 |
|
| 94 |
+
######################################
|
| 95 |
+
# 3) ๋ง๋ ์ฐจํธ ์์ฑ (์์ 20๊ฐ)
|
| 96 |
+
######################################
|
| 97 |
def create_score_chart(multiple_ids_df):
|
| 98 |
"""
|
| 99 |
+
multiple_ids_df = [ id, total_score ] ํํ
|
|
|
|
| 100 |
"""
|
| 101 |
try:
|
| 102 |
if multiple_ids_df.empty:
|
| 103 |
+
# ์ค๋ณต๋ id๊ฐ ์ ํ ์๋ ๊ฒฝ์ฐ (or ๋ฌด์์ธ๊ฐ ์๋ชป๋ ๊ฒฝ์ฐ)
|
| 104 |
placeholder_df = pd.DataFrame({"id": ["No multiple entries"], "total_score": [0]})
|
| 105 |
fig = px.bar(
|
| 106 |
placeholder_df,
|
|
|
|
| 109 |
orientation='h'
|
| 110 |
)
|
| 111 |
fig.update_layout(
|
| 112 |
+
title="No multiple entries found (in Top 1000)",
|
| 113 |
xaxis_title="Total Trending Score",
|
| 114 |
yaxis_title="Space ID",
|
| 115 |
plot_bgcolor='white',
|
|
|
|
| 119 |
)
|
| 120 |
return fig
|
| 121 |
|
| 122 |
+
# ๋ง๋ ์ฐจํธ ์์ฑ
|
|
|
|
|
|
|
| 123 |
fig = px.bar(
|
| 124 |
+
multiple_ids_df,
|
| 125 |
y='id',
|
| 126 |
x='total_score',
|
| 127 |
orientation='h',
|
| 128 |
+
title="Top 20 IDs with Multiple Entries (Rank โค 1000)",
|
| 129 |
+
text=[f"{score:.2f}" for score in multiple_ids_df['total_score']],
|
| 130 |
+
height=500
|
| 131 |
)
|
| 132 |
|
| 133 |
fig.update_layout(
|
|
|
|
| 137 |
paper_bgcolor='white',
|
| 138 |
showlegend=False,
|
| 139 |
margin=dict(l=200, r=20, t=40, b=40),
|
| 140 |
+
yaxis={'categoryorder': 'total ascending'} # ํฐ ์ ์ ์์ผ๋ก
|
| 141 |
)
|
| 142 |
|
| 143 |
fig.update_traces(
|
|
|
|
| 154 |
traceback.print_exc()
|
| 155 |
return None
|
| 156 |
|
| 157 |
+
######################################
|
| 158 |
+
# 4) ์คํ์ด์ค ์์ธ/ํธ๋ ๋ ์ฐจํธ
|
| 159 |
+
######################################
|
| 160 |
+
def create_trend_chart(space_id, daily_ranks_df):
|
| 161 |
+
"""
|
| 162 |
+
์ ํํ id์ ๋ํ (30์ผ๊ฐ) rank ๋ณํ๋ฅผ ๋ผ์ธ์ฐจํธ๋ก ํ์
|
| 163 |
+
"""
|
| 164 |
+
try:
|
| 165 |
+
if space_id is None or daily_ranks_df.empty:
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
# ํด๋น id ํํฐ๋ง
|
| 169 |
+
space_data = daily_ranks_df[daily_ranks_df['id'] == space_id].copy()
|
| 170 |
+
if space_data.empty:
|
| 171 |
+
return None
|
| 172 |
+
|
| 173 |
+
space_data = space_data.sort_values('date')
|
| 174 |
+
|
| 175 |
+
fig = px.line(
|
| 176 |
+
space_data,
|
| 177 |
+
x='date',
|
| 178 |
+
y='rank',
|
| 179 |
+
title=f'Daily Rank Trend for {space_id}',
|
| 180 |
+
labels={'date': 'Date', 'rank': 'Rank'},
|
| 181 |
+
markers=True,
|
| 182 |
+
height=400
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
# y์ถ์ ๋ญํน์ด 1์ด ๊ฐ์ฅ ๋์ ์์ด๋ฏ๋ก ๋ค์ง์ด์ ํ์ํ๋ ค๋ฉด range=[100, 1] ๋ฑ์ผ๋ก ์ค์
|
| 186 |
+
fig.update_layout(
|
| 187 |
+
xaxis_title="Date",
|
| 188 |
+
yaxis_title="Rank",
|
| 189 |
+
yaxis=dict(
|
| 190 |
+
range=[space_data['rank'].max()+1, 1],
|
| 191 |
+
tickmode='linear',
|
| 192 |
+
tick0=1,
|
| 193 |
+
dtick=10
|
| 194 |
+
),
|
| 195 |
+
hovermode='x unified',
|
| 196 |
+
plot_bgcolor='white',
|
| 197 |
+
paper_bgcolor='white',
|
| 198 |
+
showlegend=False,
|
| 199 |
+
margin=dict(t=50, r=20, b=40, l=40)
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
| 203 |
+
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
|
| 204 |
+
|
| 205 |
+
fig.update_traces(
|
| 206 |
+
line_color='#2563eb',
|
| 207 |
+
line_width=2,
|
| 208 |
+
marker=dict(size=8, color='#2563eb')
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
return fig
|
| 212 |
+
except Exception as e:
|
| 213 |
+
print(f"Error creating trend chart: {e}")
|
| 214 |
+
traceback.print_exc()
|
| 215 |
+
return None
|
| 216 |
+
|
| 217 |
def update_display(selection):
|
| 218 |
"""
|
| 219 |
+
์ฌ์ฉ์๊ฐ ํน์ id๋ฅผ ์ ํํ์ ๋,
|
| 220 |
+
1) ๊ทธ id์ ์ผ๊ฐ Rank ๋ณํ๋ฅผ Trend Chart๋ก ํ์
|
| 221 |
+
2) ์์ธ ์ ๋ณด HTML
|
| 222 |
"""
|
| 223 |
global daily_ranks_df
|
| 224 |
|
|
|
|
| 228 |
try:
|
| 229 |
space_id = selection
|
| 230 |
|
| 231 |
+
# ์ต์ ๋ฐ์ดํฐ (๊ฐ์ฅ ๋ง์ง๋ง ๋ ์ง์, ํด๋น id) ํ๋ ๊ฐ์ ธ์ค๊ธฐ
|
| 232 |
latest_data = daily_ranks_df[
|
| 233 |
daily_ranks_df['id'] == space_id
|
| 234 |
].sort_values('date').iloc[-1]
|
|
|
|
| 258 |
print(f"Error in update_display: {e}")
|
| 259 |
return None, gr.HTML(value=f"<div style='color: red;'>Error processing data: {str(e)}</div>")
|
| 260 |
|
| 261 |
+
######################################
|
| 262 |
+
# ๋ฉ์ธ
|
| 263 |
+
######################################
|
| 264 |
print("Loading initial data...")
|
| 265 |
+
daily_ranks_df, top_n_spaces = load_and_process_data() # ์ฌ๊ธฐ์ n=1000
|
| 266 |
print("Data loaded successfully!")
|
| 267 |
|
| 268 |
+
# ์ค๋ณต๋ ID๊ฐ 2๋ฒ ์ด์ ๋ฑ์ฅํ๋ ๊ฒ๋ง ์ง๊ณ -> ์์ 20
|
| 269 |
+
multiple_ids_df = get_top20_multiple_ids(top_n_spaces)
|
| 270 |
score_chart = create_score_chart(multiple_ids_df)
|
| 271 |
|
| 272 |
+
# Gradio ์ธํฐํ์ด์ค
|
| 273 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 274 |
gr.Markdown("""
|
| 275 |
# HF Space Ranking Tracker
|
| 276 |
|
| 277 |
+
**Note**: ์ด ๋ฐ๋ชจ๋ ์ค์ 'Top 1000'์ ๋์์ผ๋ก ์ค๋ณต๋ ID(2๊ฐ ์ด์)๋ฅผ ์ฐพ์ ํฉ์ฐ ์ค์ฝ์ด๋ฅผ ํ์ํฉ๋๋ค.
|
| 278 |
+
๋ง์ฝ ๋ฐ์ดํฐ์ ์ค๋ณต ID๊ฐ ์๋ค๋ฉด(๋๋ ๊ทนํ ์ ๋ค๋ฉด), ์ฐ์ธก ๋ง๋ ์ฐจํธ๊ฐ 'No multiple entries found'์ผ ์ ์์ต๋๋ค.
|
|
|
|
| 279 |
""")
|
| 280 |
|
| 281 |
with gr.Tabs():
|
| 282 |
with gr.Tab("Dashboard"):
|
| 283 |
with gr.Row(variant="panel"):
|
|
|
|
| 284 |
with gr.Column(scale=7):
|
| 285 |
trend_plot = gr.Plot(
|
| 286 |
label="Daily Rank Trend",
|
| 287 |
container=True
|
| 288 |
)
|
|
|
|
| 289 |
with gr.Column(scale=3):
|
|
|
|
| 290 |
score_plot = gr.Plot(
|
| 291 |
value=score_chart,
|
| 292 |
label="Multiple-Entry IDs (Top 20)",
|
| 293 |
container=True
|
| 294 |
)
|
| 295 |
|
|
|
|
| 296 |
with gr.Row():
|
| 297 |
info_box = gr.HTML(
|
| 298 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 299 |
)
|
| 300 |
|
| 301 |
+
# ๋ผ๋์ค ๋ฒํผ (Top n=1000)
|
| 302 |
space_selection = gr.Radio(
|
| 303 |
+
choices=[row['id'] for _, row in top_n_spaces.iterrows()],
|
| 304 |
value=None,
|
| 305 |
visible=False
|
| 306 |
)
|
| 307 |
|
| 308 |
+
# HTML ์นด๋ (๋ญํน ์์ผ๋ก ํ์)
|
| 309 |
html_content = """
|
| 310 |
<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>
|
| 311 |
""" + "".join([
|
|
|
|
| 317 |
border-radius: 8px;
|
| 318 |
padding: 16px;
|
| 319 |
margin: 8px;
|
| 320 |
+
background-color: hsl(210, {max(30, 90 - (row['rank'] / 1000 * 60))}%, {min(97, 85 + (row['rank'] / 1000 * 10))}%);
|
| 321 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 322 |
display: inline-block;
|
| 323 |
width: 250px;
|
|
|
|
| 351 |
</div>
|
| 352 |
</div>
|
| 353 |
"""
|
| 354 |
+
for _, row in top_n_spaces.iterrows()
|
| 355 |
]) + """
|
| 356 |
</div>
|
| 357 |
<script>
|
|
|
|
| 371 |
|
| 372 |
with gr.Tab("About"):
|
| 373 |
gr.Markdown("""
|
| 374 |
+
### Why might the chart be empty?
|
| 375 |
+
- ์ด ๋ฐ๋ชจ๋ Top 1000 ์์์ **๋์ผํ `id`๊ฐ 2๋ฒ ์ด์** ๋ฑ์ฅํ๋ ๊ฒฝ์ฐ์๋ง ์ ์๋ฅผ ํฉ์ฐํด ๋ง๋์ฐจํธ๋ฅผ ๊ทธ๋ฆฝ๋๋ค.
|
| 376 |
+
- ๋ฐ์ดํฐ์
์ ์ค์ ๋ก ์ค๋ณต๋ `id`๊ฐ ๋ง์ง ์๋ค๋ฉด ์ฐจํธ๊ฐ ๋น์ด์์ ์ ์์ต๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
+
### What can you do?
|
| 379 |
+
- (A) ์ฝ๋๋ฅผ ์์ ํด Top 100 โ 1000, 5000 ๋ฑ์ผ๋ก ๋๋ ค๋ณด๊ฑฐ๋,
|
| 380 |
+
- (B) ์์ rank ์ ํ ์์ด ์ ์ฒด ๋ฐ์ดํฐ์์ ์ค๋ณต ์ฌ๋ถ๋ฅผ ํ์ธํ ์๋ ์์ต๋๋ค.
|
| 381 |
+
- (C) ํ
์คํธ์ฉ์ผ๋ก ๊ฐ์ง ์ค๋ณต ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด๋ ๋ฉ๋๋ค.
|
| 382 |
""")
|
| 383 |
|
|
|
|
| 384 |
space_selection.change(
|
| 385 |
fn=update_display,
|
| 386 |
inputs=[space_selection],
|
| 387 |
+
outputs=[trend_plot, info_box]
|
|
|
|
| 388 |
)
|
| 389 |
|
| 390 |
if __name__ == "__main__":
|