ginipick commited on
Commit
9c3e995
ยท
verified ยท
1 Parent(s): b867b8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -49
app.py CHANGED
@@ -57,52 +57,64 @@ 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].sort_values(ascending=False)
64
- return duplicates
 
 
 
 
 
 
65
 
66
  def create_duplicates_chart(duplicates):
67
- if duplicates.empty:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  return None
69
-
70
- # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
71
- df = pd.DataFrame({'id': duplicates.index, 'count': duplicates.values}).reset_index(drop=True)
72
-
73
- fig = px.bar(
74
- df,
75
- x='count',
76
- y='id',
77
- orientation='h', # ์ˆ˜ํ‰ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„
78
- title="Spaces with Multiple Entries in Top 100",
79
- labels={'count': 'Number of Entries', 'id': 'Space ID'},
80
- height=400,
81
- text='count' # ๊ฐ’ ํ‘œ์‹œ
82
- )
83
-
84
- fig.update_layout(
85
- showlegend=False,
86
- margin=dict(t=50, r=20, b=40, l=200), # ์™ผ์ชฝ ์—ฌ๋ฐฑ ์ฆ๊ฐ€
87
- plot_bgcolor='white',
88
- paper_bgcolor='white',
89
- yaxis={'categoryorder': 'total ascending'}, # ID๋ฅผ ๊ฐ’์— ๋”ฐ๋ผ ์ •๋ ฌ
90
- xaxis_title="Number of Entries",
91
- yaxis_title="Space ID",
92
- hoverlabel=dict(bgcolor="white"),
93
- hovermode='y'
94
- )
95
-
96
- fig.update_traces(
97
- marker_color='#4CAF50',
98
- textposition='outside',
99
- textfont=dict(size=12)
100
- )
101
-
102
- # ๊ทธ๋ฆฌ๋“œ ์ถ”๊ฐ€
103
- fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
104
-
105
- return fig
106
 
107
  def update_display(selection):
108
  global daily_ranks_df
@@ -182,6 +194,11 @@ print("Loading initial data...")
182
  daily_ranks_df, top_100_spaces = load_and_process_data()
183
  print("Data loaded successfully!")
184
 
 
 
 
 
 
185
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
186
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
187
  gr.Markdown("""
@@ -199,12 +216,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
199
  container=True
200
  )
201
  with gr.Column(scale=3):
202
- duplicates_chart = create_duplicates_chart(get_duplicate_spaces(top_100_spaces))
203
- duplicates_plot = gr.Plot(
204
- value=duplicates_chart,
205
- label="Multiple Entries Analysis",
206
- container=True
207
- )
 
 
 
 
 
208
 
209
  with gr.Row():
210
  info_box = gr.HTML(
 
57
  return None
58
 
59
  def get_duplicate_spaces(top_100_spaces):
60
+ try:
61
+ # ID๋ณ„ ๋“ฑ์žฅ ํšŸ์ˆ˜ ๊ณ„์‚ฐ
62
+ id_counts = top_100_spaces['id'].value_counts()
63
+ # 2ํšŒ ์ด์ƒ ๋“ฑ์žฅํ•˜๋Š” ID๋งŒ ํ•„ํ„ฐ๋งํ•˜๊ณ  ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
64
+ duplicates = id_counts[id_counts >= 2].sort_values(ascending=False)
65
+ print(f"Found {len(duplicates)} duplicate spaces")
66
+ print("Duplicate spaces data:", duplicates)
67
+ return duplicates
68
+ except Exception as e:
69
+ print(f"Error in get_duplicate_spaces: {e}")
70
+ return pd.Series()
71
 
72
  def create_duplicates_chart(duplicates):
73
+ try:
74
+ if duplicates.empty:
75
+ print("No duplicate spaces found")
76
+ return None
77
+
78
+ # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์œผ๋กœ ๋ณ€ํ™˜
79
+ df = pd.DataFrame({'Space ID': duplicates.index, 'Entries': duplicates.values})
80
+ print("Creating chart with data:", df)
81
+
82
+ # ์ˆ˜ํ‰ ๋ง‰๋Œ€ ์ฐจํŠธ ์ƒ์„ฑ
83
+ fig = px.bar(
84
+ df,
85
+ x='Entries',
86
+ y='Space ID',
87
+ orientation='h',
88
+ title=f"Top {len(df)} Spaces with Multiple Entries",
89
+ height=400
90
+ )
91
+
92
+ # ์ฐจํŠธ ์Šคํƒ€์ผ ์„ค์ •
93
+ fig.update_layout(
94
+ xaxis_title="Number of Entries in Top 100",
95
+ yaxis_title="Space ID",
96
+ plot_bgcolor='white',
97
+ paper_bgcolor='white',
98
+ showlegend=False,
99
+ margin=dict(l=200, r=20, t=40, b=40),
100
+ yaxis={'categoryorder': 'total ascending'}
101
+ )
102
+
103
+ # ๋ง‰๋Œ€ ์Šคํƒ€์ผ ์„ค์ •
104
+ fig.update_traces(
105
+ marker_color='#4CAF50',
106
+ texttemplate='%{x}',
107
+ textposition='outside',
108
+ )
109
+
110
+ # ๊ทธ๋ฆฌ๋“œ ์ถ”๊ฐ€
111
+ fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
112
+
113
+ print("Chart created successfully")
114
+ return fig
115
+ except Exception as e:
116
+ print(f"Error creating duplicates chart: {e}")
117
  return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  def update_display(selection):
120
  global daily_ranks_df
 
194
  daily_ranks_df, top_100_spaces = load_and_process_data()
195
  print("Data loaded successfully!")
196
 
197
+ # ์ค‘๋ณต ๋ฐ์ดํ„ฐ ๋ถ„์„
198
+ print("Analyzing duplicate spaces...")
199
+ duplicates = get_duplicate_spaces(top_100_spaces)
200
+ duplicates_chart = create_duplicates_chart(duplicates)
201
+
202
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
203
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
204
  gr.Markdown("""
 
216
  container=True
217
  )
218
  with gr.Column(scale=3):
219
+ if duplicates_chart:
220
+ duplicates_plot = gr.Plot(
221
+ value=duplicates_chart,
222
+ label=f"Multiple Entries Analysis (Found: {len(duplicates)})",
223
+ container=True
224
+ )
225
+ else:
226
+ duplicates_plot = gr.Plot(
227
+ label="No duplicate spaces found",
228
+ container=True
229
+ )
230
 
231
  with gr.Row():
232
  info_box = gr.HTML(