openfree commited on
Commit
bb83351
·
verified ·
1 Parent(s): 3e9d1cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -65
app.py CHANGED
@@ -996,73 +996,98 @@ def refresh_data():
996
 
997
 
998
  def create_registration_bar_chart(data, type_name="Spaces"):
999
- # DataFrame인 경우 처리
1000
- if isinstance(data, pd.DataFrame):
1001
- registrations = data['Space ID' if type_name == "Spaces" else 'Model ID'].apply(
1002
- lambda x: x.split('/')[0]
1003
- ).value_counts()
1004
- else:
1005
- # 리스트나 다른 형태의 데이터인 경우 처리
1006
- registrations = {}
1007
- for item in data:
1008
- if isinstance(item, dict):
1009
- creator = item.get('id', '').split('/')[0]
1010
- else:
1011
- creator = str(item).split('/')[0]
1012
- registrations[creator] = registrations.get(creator, 0) + 1
1013
- registrations = pd.Series(registrations)
1014
-
1015
- # 정렬된 데이터 준비
1016
- registrations = registrations.sort_values(ascending=False)
1017
-
1018
- fig = go.Figure(data=[go.Bar(
1019
- x=registrations.index,
1020
- y=registrations.values,
1021
- text=registrations.values,
1022
- textposition='auto',
1023
- marker_color='#FF6B6B'
1024
- )])
1025
-
1026
- fig.update_layout(
1027
- title=f"Korean {type_name} Registrations by Creator",
1028
- xaxis_title="Creator ID",
1029
- yaxis_title="Number of Registrations",
1030
- showlegend=False,
1031
- height=400,
1032
- width=700
1033
- )
1034
-
1035
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
1036
 
1037
  def create_pie_chart(data, total_count, type_name="Spaces"):
1038
- # DataFrame인 경우 처리
1039
- if isinstance(data, pd.DataFrame):
1040
- korean_count = len(data)
1041
- else:
1042
- # 리스트나 다른 형태의 데이터인 경우 처리
1043
- korean_count = len(data)
1044
-
1045
- other_count = total_count - korean_count
1046
-
1047
- fig = go.Figure(data=[go.Pie(
1048
- labels=[f'Korean {type_name}', f'Other {type_name}'],
1049
- values=[korean_count, other_count],
1050
- hole=.3,
1051
- marker_colors=['#FF6B6B', '#4ECDC4'],
1052
- textinfo='percent+value',
1053
- hovertemplate="<b>%{label}</b><br>" +
1054
- "Count: %{value}<br>" +
1055
- "Percentage: %{percent}<br>"
1056
- )])
1057
-
1058
- fig.update_layout(
1059
- title=f"Korean vs Other {type_name} Distribution",
1060
- showlegend=True,
1061
- height=400,
1062
- width=500
1063
- )
1064
-
1065
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
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")