Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -996,73 +996,98 @@ def refresh_data():
|
|
| 996 |
|
| 997 |
|
| 998 |
def create_registration_bar_chart(data, type_name="Spaces"):
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
|
| 1037 |
def create_pie_chart(data, total_count, type_name="Spaces"):
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1066 |
|
| 1067 |
def refresh_all_data():
|
| 1068 |
spaces_results = get_spaces_data("trending")
|
|
|
|
| 996 |
|
| 997 |
|
| 998 |
def create_registration_bar_chart(data, type_name="Spaces"):
|
| 999 |
+
try:
|
| 1000 |
+
# DataFrame인 경우 처리
|
| 1001 |
+
if isinstance(data, pd.DataFrame):
|
| 1002 |
+
if type_name == "Models":
|
| 1003 |
+
# 3000위 이내의 모델만 필터링
|
| 1004 |
+
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
| 1005 |
+
# '#' 제거하고 숫자로 변환
|
| 1006 |
+
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= 3000]
|
| 1007 |
+
|
| 1008 |
+
# ID 컬럼 선택
|
| 1009 |
+
id_column = 'Space ID' if type_name == "Spaces" else 'Model ID'
|
| 1010 |
+
registrations = data[id_column].apply(lambda x: x.split('/')[0]).value_counts()
|
| 1011 |
+
else:
|
| 1012 |
+
# 리스트나 다른 형태의 데이터인 경우 처리
|
| 1013 |
+
registrations = {}
|
| 1014 |
+
for item in data:
|
| 1015 |
+
if isinstance(item, dict):
|
| 1016 |
+
# Models의 경우 3000위 이내만 처리
|
| 1017 |
+
if type_name == "Models":
|
| 1018 |
+
rank = item.get('global_rank')
|
| 1019 |
+
if isinstance(rank, str) or rank > 3000:
|
| 1020 |
+
continue
|
| 1021 |
+
creator = item.get('id', '').split('/')[0]
|
| 1022 |
+
registrations[creator] = registrations.get(creator, 0) + 1
|
| 1023 |
+
registrations = pd.Series(registrations)
|
| 1024 |
+
|
| 1025 |
+
# 정렬된 데이터 준비
|
| 1026 |
+
registrations = registrations.sort_values(ascending=False)
|
| 1027 |
+
|
| 1028 |
+
fig = go.Figure(data=[go.Bar(
|
| 1029 |
+
x=registrations.index,
|
| 1030 |
+
y=registrations.values,
|
| 1031 |
+
text=registrations.values,
|
| 1032 |
+
textposition='auto',
|
| 1033 |
+
marker_color='#FF6B6B'
|
| 1034 |
+
)])
|
| 1035 |
+
|
| 1036 |
+
fig.update_layout(
|
| 1037 |
+
title=f"Korean {type_name} Registrations by Creator (Top 3000)",
|
| 1038 |
+
xaxis_title="Creator ID",
|
| 1039 |
+
yaxis_title="Number of Registrations",
|
| 1040 |
+
showlegend=False,
|
| 1041 |
+
height=400,
|
| 1042 |
+
width=700
|
| 1043 |
+
)
|
| 1044 |
+
|
| 1045 |
+
return fig
|
| 1046 |
+
except Exception as e:
|
| 1047 |
+
print(f"Error in create_registration_bar_chart: {str(e)}")
|
| 1048 |
+
return go.Figure()
|
| 1049 |
|
| 1050 |
def create_pie_chart(data, total_count, type_name="Spaces"):
|
| 1051 |
+
try:
|
| 1052 |
+
# DataFrame인 경우 처리
|
| 1053 |
+
if isinstance(data, pd.DataFrame):
|
| 1054 |
+
if type_name == "Models":
|
| 1055 |
+
# 3000위 이내의 모델만 필터링
|
| 1056 |
+
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
| 1057 |
+
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= 3000]
|
| 1058 |
+
korean_count = len(data)
|
| 1059 |
+
else:
|
| 1060 |
+
# 리스트나 다른 형태의 데이터인 경우 처리
|
| 1061 |
+
if type_name == "Models":
|
| 1062 |
+
# 3000위 이내의 모델만 카운트
|
| 1063 |
+
korean_count = sum(1 for item in data if isinstance(item.get('global_rank'), (int, float)) and item.get('global_rank') <= 3000)
|
| 1064 |
+
else:
|
| 1065 |
+
korean_count = len(data)
|
| 1066 |
+
|
| 1067 |
+
other_count = total_count - korean_count
|
| 1068 |
+
|
| 1069 |
+
fig = go.Figure(data=[go.Pie(
|
| 1070 |
+
labels=[f'Korean {type_name} in Top 3000', f'Other {type_name} in Top 3000'],
|
| 1071 |
+
values=[korean_count, other_count],
|
| 1072 |
+
hole=.3,
|
| 1073 |
+
marker_colors=['#FF6B6B', '#4ECDC4'],
|
| 1074 |
+
textinfo='percent+value',
|
| 1075 |
+
hovertemplate="<b>%{label}</b><br>" +
|
| 1076 |
+
"Count: %{value}<br>" +
|
| 1077 |
+
"Percentage: %{percent}<br>"
|
| 1078 |
+
)])
|
| 1079 |
+
|
| 1080 |
+
fig.update_layout(
|
| 1081 |
+
title=f"Korean vs Other {type_name} Distribution (Top 3000)",
|
| 1082 |
+
showlegend=True,
|
| 1083 |
+
height=400,
|
| 1084 |
+
width=500
|
| 1085 |
+
)
|
| 1086 |
+
|
| 1087 |
+
return fig
|
| 1088 |
+
except Exception as e:
|
| 1089 |
+
print(f"Error in create_pie_chart: {str(e)}")
|
| 1090 |
+
return go.Figure()
|
| 1091 |
|
| 1092 |
def refresh_all_data():
|
| 1093 |
spaces_results = get_spaces_data("trending")
|