ginipick commited on
Commit
9bb8db0
·
verified ·
1 Parent(s): 723852f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -28
app.py CHANGED
@@ -95,22 +95,55 @@ def get_total_scores(daily_ranks_df):
95
  return pd.DataFrame()
96
 
97
  def create_score_chart(total_scores):
 
 
 
 
 
98
  try:
99
  if total_scores.empty:
100
- print("No multiple entries found")
101
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- # 데이터프레임
104
- # 여기서 total_score 기준으로 내림차순 정렬 후 상위 10개만 선택
105
  df = total_scores.reset_index().sort_values('total_score', ascending=False).head(10)
106
 
107
  if df.empty:
108
- print("No multiple entries found in top 10")
109
- return None
110
-
111
- print("Data for chart (top 10):", df)
112
-
113
- # 수평 막대 차트 생성
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  fig = px.bar(
115
  df,
116
  y='id',
@@ -124,7 +157,6 @@ def create_score_chart(total_scores):
124
  ]
125
  )
126
 
127
- # 차트 스타일 설정
128
  fig.update_layout(
129
  xaxis_title="Total Trending Score",
130
  yaxis_title="Space ID",
@@ -132,17 +164,15 @@ def create_score_chart(total_scores):
132
  paper_bgcolor='white',
133
  showlegend=False,
134
  margin=dict(l=200, r=20, t=40, b=40),
135
- yaxis={'categoryorder': 'total ascending'} # 점수 큰 순서대로 나타내도록 설정
136
  )
137
 
138
- # 막대 스타일 설정
139
  fig.update_traces(
140
  marker_color='#4CAF50',
141
  textposition='outside',
142
  textfont=dict(size=12)
143
  )
144
 
145
- # 그리드 추가
146
  fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
147
 
148
  return fig
@@ -151,7 +181,6 @@ def create_score_chart(total_scores):
151
  traceback.print_exc()
152
  return None
153
 
154
-
155
  def update_display(selection):
156
  global daily_ranks_df
157
 
@@ -234,7 +263,7 @@ print("Data loaded successfully!")
234
  # 총 스코어 분석
235
  print("Analyzing total scores...")
236
  total_scores = get_total_scores(daily_ranks_df)
237
- score_chart = create_score_chart(total_scores)
238
 
239
  # Gradio 인터페이스 생성
240
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
@@ -247,23 +276,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
247
  with gr.Tabs():
248
  with gr.Tab("Dashboard"):
249
  with gr.Row(variant="panel"):
 
250
  with gr.Column(scale=7):
251
  trend_plot = gr.Plot(
252
  label="Daily Rank Trend",
253
  container=True
254
  )
 
255
  with gr.Column(scale=3):
256
- if score_chart:
257
- score_plot = gr.Plot(
258
- value=score_chart,
259
- label=f"Multiple Entries Analysis",
260
- container=True
261
- )
262
- else:
263
- score_plot = gr.Plot(
264
- label="No multiple entries found",
265
- container=True
266
- )
267
 
268
  with gr.Row():
269
  info_box = gr.HTML(
@@ -379,4 +405,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
379
  )
380
 
381
  if __name__ == "__main__":
382
- demo.launch(share=True)
 
 
95
  return pd.DataFrame()
96
 
97
  def create_score_chart(total_scores):
98
+ """
99
+ - total_scores가 비었을 경우 'No multiple entries found'라는 제목의
100
+ 간단한 placeholder 차트를 반환하여, 오른쪽 상단 영역이 비어 있지 않도록 함.
101
+ - 상위 10개만 표시 (total_score 기준 내림차순).
102
+ """
103
  try:
104
  if total_scores.empty:
105
+ # 중복된 ID 자체가 전혀 없는 경우
106
+ placeholder_df = pd.DataFrame({"id": ["No multiple entries"], "total_score": [0]})
107
+ fig = px.bar(
108
+ placeholder_df,
109
+ x="total_score",
110
+ y="id",
111
+ orientation='h'
112
+ )
113
+ fig.update_layout(
114
+ title="No multiple entries found in Top 100",
115
+ xaxis_title="Total Trending Score",
116
+ yaxis_title="Space ID",
117
+ plot_bgcolor='white',
118
+ paper_bgcolor='white',
119
+ showlegend=False,
120
+ margin=dict(l=200, r=20, t=40, b=40),
121
+ )
122
+ return fig
123
 
124
+ # total_score 으로 내림차순 정렬 후 상위 10개만 차트에 표시
 
125
  df = total_scores.reset_index().sort_values('total_score', ascending=False).head(10)
126
 
127
  if df.empty:
128
+ # 중복된 ID는 존재하지만 스코어가 0이거나 등등, 의도치 않게 비었을 경우 대비
129
+ placeholder_df = pd.DataFrame({"id": ["No multiple entries"], "total_score": [0]})
130
+ fig = px.bar(
131
+ placeholder_df,
132
+ x="total_score",
133
+ y="id",
134
+ orientation='h'
135
+ )
136
+ fig.update_layout(
137
+ title="No multiple entries found in Top 100",
138
+ xaxis_title="Total Trending Score",
139
+ yaxis_title="Space ID",
140
+ plot_bgcolor='white',
141
+ paper_bgcolor='white',
142
+ showlegend=False,
143
+ margin=dict(l=200, r=20, t=40, b=40),
144
+ )
145
+ return fig
146
+
147
  fig = px.bar(
148
  df,
149
  y='id',
 
157
  ]
158
  )
159
 
 
160
  fig.update_layout(
161
  xaxis_title="Total Trending Score",
162
  yaxis_title="Space ID",
 
164
  paper_bgcolor='white',
165
  showlegend=False,
166
  margin=dict(l=200, r=20, t=40, b=40),
167
+ yaxis={'categoryorder': 'total ascending'}
168
  )
169
 
 
170
  fig.update_traces(
171
  marker_color='#4CAF50',
172
  textposition='outside',
173
  textfont=dict(size=12)
174
  )
175
 
 
176
  fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
177
 
178
  return fig
 
181
  traceback.print_exc()
182
  return None
183
 
 
184
  def update_display(selection):
185
  global daily_ranks_df
186
 
 
263
  # 총 스코어 분석
264
  print("Analyzing total scores...")
265
  total_scores = get_total_scores(daily_ranks_df)
266
+ score_chart = create_score_chart(total_scores) # <- 여기서 차트 생성
267
 
268
  # Gradio 인터페이스 생성
269
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
276
  with gr.Tabs():
277
  with gr.Tab("Dashboard"):
278
  with gr.Row(variant="panel"):
279
+ # 왼쪽(Trend Plot)
280
  with gr.Column(scale=7):
281
  trend_plot = gr.Plot(
282
  label="Daily Rank Trend",
283
  container=True
284
  )
285
+ # 오른쪽(Score Chart)
286
  with gr.Column(scale=3):
287
+ # 이미 생성한 score_chart를 기본값으로 넣어줌
288
+ score_plot = gr.Plot(
289
+ value=score_chart,
290
+ label="Multiple Entries Analysis (Top 10)",
291
+ container=True
292
+ )
 
 
 
 
 
293
 
294
  with gr.Row():
295
  info_box = gr.HTML(
 
405
  )
406
 
407
  if __name__ == "__main__":
408
+ demo.launch(share=True)
409
+