Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def create_duplicates_chart(duplicates):
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
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(
|