kolaslab commited on
Commit
8b6deaa
ยท
verified ยท
1 Parent(s): c7a534b

Update app-backup.py

Browse files
Files changed (1) hide show
  1. 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=400
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
- id_counts = top_100_spaces['id'].value_counts()
62
- # 2ํšŒ ์ด์ƒ ๋“ฑ์žฅํ•˜๋Š” ID๋งŒ ํ•„ํ„ฐ๋ง
63
- duplicates = id_counts[id_counts >= 2]
64
- return duplicates
 
 
 
 
 
 
 
 
 
65
 
66
- def create_duplicates_chart(duplicates):
67
- if duplicates.empty:
68
  return None
69
 
 
 
 
 
 
 
 
 
 
 
 
70
  fig = px.bar(
71
- x=duplicates.index,
72
- y=duplicates.values,
73
- title="Spaces with Multiple Entries in Top 100",
74
- labels={'x': 'Space ID', 'y': 'Number of Entries'},
75
- height=400
 
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=7):
186
  trend_plot = gr.Plot(
187
  label="Daily Rank Trend",
188
  container=True
189
  )
190
- with gr.Column(scale=3):
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)