Spaces:
Running
Running
Update app-backup.py
Browse files- app-backup.py +63 -22
app-backup.py
CHANGED
|
@@ -23,7 +23,7 @@ def create_trend_chart(space_id, daily_ranks_df):
|
|
| 23 |
title=f'Daily Rank Trend for {space_id}',
|
| 24 |
labels={'date': 'Date', 'rank': 'Rank'},
|
| 25 |
markers=True,
|
| 26 |
-
height=
|
| 27 |
)
|
| 28 |
|
| 29 |
fig.update_layout(
|
|
@@ -57,22 +57,43 @@ def create_trend_chart(space_id, daily_ranks_df):
|
|
| 57 |
return None
|
| 58 |
|
| 59 |
def get_duplicate_spaces(top_100_spaces):
|
| 60 |
-
# ID
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
def create_duplicates_chart(
|
| 67 |
-
if
|
| 68 |
return None
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
fig = px.bar(
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
height=
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
fig.update_layout(
|
|
@@ -80,11 +101,34 @@ def create_duplicates_chart(duplicates):
|
|
| 80 |
margin=dict(t=50, r=20, b=40, l=40),
|
| 81 |
plot_bgcolor='white',
|
| 82 |
paper_bgcolor='white',
|
| 83 |
-
xaxis_tickangle=-45
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
)
|
| 85 |
|
| 86 |
fig.update_traces(
|
| 87 |
-
marker_color='#4CAF50'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
return fig
|
|
@@ -174,7 +218,7 @@ duplicates_chart = create_duplicates_chart(duplicates)
|
|
| 174 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 175 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 176 |
gr.Markdown("""
|
| 177 |
-
# HF Space Ranking Tracker
|
| 178 |
|
| 179 |
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.
|
| 180 |
""")
|
|
@@ -182,12 +226,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 182 |
with gr.Tabs():
|
| 183 |
with gr.Tab("Dashboard"):
|
| 184 |
with gr.Row(variant="panel"):
|
| 185 |
-
with gr.Column(scale=
|
| 186 |
trend_plot = gr.Plot(
|
| 187 |
label="Daily Rank Trend",
|
| 188 |
container=True
|
| 189 |
)
|
| 190 |
-
with gr.Column(scale=
|
| 191 |
duplicates_plot = gr.Plot(
|
| 192 |
label="Multiple Entries Analysis",
|
| 193 |
value=duplicates_chart,
|
|
@@ -199,14 +243,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 199 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 200 |
)
|
| 201 |
|
| 202 |
-
# ๋ผ๋์ค ๋ฒํผ์ ๋จผ์ ์ ์
|
| 203 |
space_selection = gr.Radio(
|
| 204 |
choices=[row['id'] for _, row in top_100_spaces.iterrows()],
|
| 205 |
value=None,
|
| 206 |
visible=False
|
| 207 |
)
|
| 208 |
|
| 209 |
-
# HTML์์ JavaScript ์ด๋ฒคํธ๋ฅผ ์ง์ ์ฒ๋ฆฌ
|
| 210 |
html_content = """
|
| 211 |
<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>
|
| 212 |
""" + "".join([
|
|
@@ -299,7 +341,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 299 |
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.
|
| 300 |
""")
|
| 301 |
|
| 302 |
-
# ๋ผ๋์ค ๋ฒํผ ๋ณ๊ฒฝ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 303 |
space_selection.change(
|
| 304 |
fn=update_display,
|
| 305 |
inputs=[space_selection],
|
|
@@ -308,4 +349,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 308 |
)
|
| 309 |
|
| 310 |
if __name__ == "__main__":
|
| 311 |
-
demo.launch(share=True)
|
|
|
|
| 23 |
title=f'Daily Rank Trend for {space_id}',
|
| 24 |
labels={'date': 'Date', 'rank': 'Rank'},
|
| 25 |
markers=True,
|
| 26 |
+
height=500 # ์์ ๋ ๋ถ๋ถ
|
| 27 |
)
|
| 28 |
|
| 29 |
fig.update_layout(
|
|
|
|
| 57 |
return None
|
| 58 |
|
| 59 |
def get_duplicate_spaces(top_100_spaces):
|
| 60 |
+
# ID์์ username/spacename ํ์์์ username๋ง ์ถ์ถ
|
| 61 |
+
top_100_spaces['clean_id'] = top_100_spaces['id'].apply(lambda x: x.split('/')[0])
|
| 62 |
+
|
| 63 |
+
# username๋ณ trending score ํฉ์ฐ
|
| 64 |
+
score_sums = top_100_spaces.groupby('clean_id')['trendingScore'].sum()
|
| 65 |
+
|
| 66 |
+
# ๋๋ฒ๊น
์ฉ ์ถ๋ ฅ
|
| 67 |
+
print("\n=== ID๋ณ ์ค์ฝ์ด ํฉ์ฐ ๊ฒฐ๊ณผ ===")
|
| 68 |
+
for id, score in score_sums.sort_values(ascending=False).head(20).items():
|
| 69 |
+
print(f"ID: {id}, Total Score: {score}")
|
| 70 |
+
|
| 71 |
+
# ํฉ์ฐ๋ ์ค์ฝ์ด๋ก ์ ๋ ฌํ์ฌ ์์ 20๊ฐ ์ ํ
|
| 72 |
+
top_20_scores = score_sums.sort_values(ascending=False).head(20)
|
| 73 |
+
return top_20_scores
|
| 74 |
|
| 75 |
+
def create_duplicates_chart(score_sums):
|
| 76 |
+
if score_sums.empty:
|
| 77 |
return None
|
| 78 |
|
| 79 |
+
# ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
| 80 |
+
df = pd.DataFrame({
|
| 81 |
+
'id': score_sums.index,
|
| 82 |
+
'total_score': score_sums.values,
|
| 83 |
+
'rank': range(1, len(score_sums) + 1)
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
# ๋๋ฒ๊น
์ฉ ์ถ๋ ฅ
|
| 87 |
+
print("\n=== ์ฐจํธ ๋ฐ์ดํฐ ===")
|
| 88 |
+
print(df)
|
| 89 |
+
|
| 90 |
fig = px.bar(
|
| 91 |
+
df,
|
| 92 |
+
x='id',
|
| 93 |
+
y='rank',
|
| 94 |
+
title="Top 20 Spaces by Combined Trending Score",
|
| 95 |
+
height=500, # ์์ ๋ ๋ถ๋ถ
|
| 96 |
+
text='total_score'
|
| 97 |
)
|
| 98 |
|
| 99 |
fig.update_layout(
|
|
|
|
| 101 |
margin=dict(t=50, r=20, b=40, l=40),
|
| 102 |
plot_bgcolor='white',
|
| 103 |
paper_bgcolor='white',
|
| 104 |
+
xaxis_tickangle=-45,
|
| 105 |
+
yaxis=dict(
|
| 106 |
+
range=[20.5, 0.5],
|
| 107 |
+
tickmode='linear',
|
| 108 |
+
tick0=1,
|
| 109 |
+
dtick=1
|
| 110 |
+
)
|
| 111 |
)
|
| 112 |
|
| 113 |
fig.update_traces(
|
| 114 |
+
marker_color='#4CAF50',
|
| 115 |
+
texttemplate='%{text:.1f}',
|
| 116 |
+
textposition='outside',
|
| 117 |
+
hovertemplate='ID: %{x}<br>Rank: %{y}<br>Total Score: %{text:.1f}<extra></extra>'
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
fig.update_xaxes(
|
| 121 |
+
title_text="User ID",
|
| 122 |
+
showgrid=True,
|
| 123 |
+
gridwidth=1,
|
| 124 |
+
gridcolor='lightgray'
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
fig.update_yaxes(
|
| 128 |
+
title_text="Rank",
|
| 129 |
+
showgrid=True,
|
| 130 |
+
gridwidth=1,
|
| 131 |
+
gridcolor='lightgray'
|
| 132 |
)
|
| 133 |
|
| 134 |
return fig
|
|
|
|
| 218 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 219 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 220 |
gr.Markdown("""
|
| 221 |
+
# HF Space Ranking Tracker(~30 Dailys)
|
| 222 |
|
| 223 |
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.
|
| 224 |
""")
|
|
|
|
| 226 |
with gr.Tabs():
|
| 227 |
with gr.Tab("Dashboard"):
|
| 228 |
with gr.Row(variant="panel"):
|
| 229 |
+
with gr.Column(scale=5): # ์์ ๋ ๋ถ๋ถ
|
| 230 |
trend_plot = gr.Plot(
|
| 231 |
label="Daily Rank Trend",
|
| 232 |
container=True
|
| 233 |
)
|
| 234 |
+
with gr.Column(scale=5): # ์์ ๋ ๋ถ๋ถ
|
| 235 |
duplicates_plot = gr.Plot(
|
| 236 |
label="Multiple Entries Analysis",
|
| 237 |
value=duplicates_chart,
|
|
|
|
| 243 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 244 |
)
|
| 245 |
|
|
|
|
| 246 |
space_selection = gr.Radio(
|
| 247 |
choices=[row['id'] for _, row in top_100_spaces.iterrows()],
|
| 248 |
value=None,
|
| 249 |
visible=False
|
| 250 |
)
|
| 251 |
|
|
|
|
| 252 |
html_content = """
|
| 253 |
<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>
|
| 254 |
""" + "".join([
|
|
|
|
| 341 |
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.
|
| 342 |
""")
|
| 343 |
|
|
|
|
| 344 |
space_selection.change(
|
| 345 |
fn=update_display,
|
| 346 |
inputs=[space_selection],
|
|
|
|
| 349 |
)
|
| 350 |
|
| 351 |
if __name__ == "__main__":
|
| 352 |
+
demo.launch(share=True)
|