Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -995,8 +995,53 @@ def refresh_data():
|
|
995 |
|
996 |
|
997 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
998 |
def create_pie_chart(data, total_count, type_name="Spaces"):
|
999 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1000 |
other_count = total_count - korean_count
|
1001 |
|
1002 |
fig = go.Figure(data=[go.Pie(
|
@@ -1019,36 +1064,25 @@ def create_pie_chart(data, total_count, type_name="Spaces"):
|
|
1019 |
|
1020 |
return fig
|
1021 |
|
1022 |
-
def
|
1023 |
-
|
1024 |
-
|
1025 |
-
for item in data:
|
1026 |
-
creator = item.get('id', '').split('/')[0] # ID์ ์ฒซ ๋ถ๋ถ์ ๋ฑ๋ก์๋ก ๊ฐ์ฃผ
|
1027 |
-
registrations[creator] = registrations.get(creator, 0) + 1
|
1028 |
|
1029 |
-
#
|
1030 |
-
|
1031 |
-
|
1032 |
-
counts = [x[1] for x in sorted_data]
|
1033 |
-
|
1034 |
-
fig = go.Figure(data=[go.Bar(
|
1035 |
-
x=creators,
|
1036 |
-
y=counts,
|
1037 |
-
text=counts,
|
1038 |
-
textposition='auto',
|
1039 |
-
marker_color='#FF6B6B'
|
1040 |
-
)])
|
1041 |
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
yaxis_title="Number of Registrations",
|
1046 |
-
showlegend=False,
|
1047 |
-
height=400,
|
1048 |
-
width=700
|
1049 |
-
)
|
1050 |
|
1051 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
1052 |
|
1053 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
1054 |
gr.Markdown("""
|
@@ -1063,45 +1097,71 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
1063 |
trending_plot = gr.Plot()
|
1064 |
with gr.Row():
|
1065 |
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1066 |
-
with gr.Column():
|
1067 |
-
spaces_pie_chart = gr.Plot(
|
1068 |
-
|
1069 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1070 |
trending_info = gr.HTML()
|
1071 |
-
trending_df = gr.DataFrame(
|
|
|
|
|
|
|
|
|
1072 |
|
1073 |
with gr.Tab("Models Trending"):
|
1074 |
models_plot = gr.Plot()
|
1075 |
with gr.Row():
|
1076 |
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1077 |
-
with gr.Column():
|
1078 |
-
models_pie_chart = gr.Plot(
|
1079 |
-
|
1080 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1081 |
models_info = gr.HTML()
|
1082 |
-
models_df = gr.DataFrame(
|
1083 |
-
|
|
|
|
|
|
|
|
|
1084 |
def refresh_all_data():
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1103 |
refresh_btn.click(
|
1104 |
-
refresh_all_data,
|
1105 |
outputs=[
|
1106 |
trending_plot, trending_info, trending_df,
|
1107 |
spaces_pie_chart, spaces_bar_chart,
|
@@ -1111,23 +1171,44 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
1111 |
)
|
1112 |
|
1113 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1127 |
|
1128 |
# Gradio ์ฑ ์คํ
|
1129 |
demo.launch(
|
1130 |
server_name="0.0.0.0",
|
1131 |
server_port=7860,
|
1132 |
-
share=False
|
|
|
1133 |
)
|
|
|
995 |
|
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(
|
|
|
1064 |
|
1065 |
return fig
|
1066 |
|
1067 |
+
def refresh_all_data():
|
1068 |
+
spaces_results = get_spaces_data("trending")
|
1069 |
+
models_results = get_models_data()
|
|
|
|
|
|
|
1070 |
|
1071 |
+
# Spaces ์ฐจํธ ์์ฑ
|
1072 |
+
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1073 |
+
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1074 |
|
1075 |
+
# Models ์ฐจํธ ์์ฑ
|
1076 |
+
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1077 |
+
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
|
|
|
|
|
|
|
|
|
|
1078 |
|
1079 |
+
return [
|
1080 |
+
spaces_results[0], spaces_results[1], spaces_results[2],
|
1081 |
+
spaces_pie, spaces_bar,
|
1082 |
+
models_results[0], models_results[1], models_results[2],
|
1083 |
+
models_pie, models_bar
|
1084 |
+
]
|
1085 |
+
|
1086 |
|
1087 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
1088 |
gr.Markdown("""
|
|
|
1097 |
trending_plot = gr.Plot()
|
1098 |
with gr.Row():
|
1099 |
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1100 |
+
with gr.Column(scale=1):
|
1101 |
+
spaces_pie_chart = gr.Plot(
|
1102 |
+
label="Korean Spaces Distribution",
|
1103 |
+
elem_id="spaces_pie"
|
1104 |
+
)
|
1105 |
+
with gr.Column(scale=2):
|
1106 |
+
spaces_bar_chart = gr.Plot(
|
1107 |
+
label="Registrations by Creator",
|
1108 |
+
elem_id="spaces_bar"
|
1109 |
+
)
|
1110 |
trending_info = gr.HTML()
|
1111 |
+
trending_df = gr.DataFrame(
|
1112 |
+
headers=["Rank", "Space ID", "Title", "Likes", "URL"],
|
1113 |
+
datatype=["number", "str", "str", "number", "str"],
|
1114 |
+
row_count=(10, "dynamic")
|
1115 |
+
)
|
1116 |
|
1117 |
with gr.Tab("Models Trending"):
|
1118 |
models_plot = gr.Plot()
|
1119 |
with gr.Row():
|
1120 |
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1121 |
+
with gr.Column(scale=1):
|
1122 |
+
models_pie_chart = gr.Plot(
|
1123 |
+
label="Korean Models Distribution",
|
1124 |
+
elem_id="models_pie"
|
1125 |
+
)
|
1126 |
+
with gr.Column(scale=2):
|
1127 |
+
models_bar_chart = gr.Plot(
|
1128 |
+
label="Registrations by Creator",
|
1129 |
+
elem_id="models_bar"
|
1130 |
+
)
|
1131 |
models_info = gr.HTML()
|
1132 |
+
models_df = gr.DataFrame(
|
1133 |
+
headers=["Global Rank", "Model ID", "Title", "Downloads", "Likes", "Korea Search", "URL"],
|
1134 |
+
datatype=["str", "str", "str", "str", "str", "str", "str"],
|
1135 |
+
row_count=(10, "dynamic")
|
1136 |
+
)
|
1137 |
+
|
1138 |
def refresh_all_data():
|
1139 |
+
try:
|
1140 |
+
spaces_results = get_spaces_data("trending")
|
1141 |
+
models_results = get_models_data()
|
1142 |
+
|
1143 |
+
# Spaces ์ฐจํธ ์์ฑ
|
1144 |
+
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1145 |
+
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
1146 |
+
|
1147 |
+
# Models ์ฐจํธ ์์ฑ
|
1148 |
+
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1149 |
+
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
1150 |
+
|
1151 |
+
return [
|
1152 |
+
spaces_results[0], spaces_results[1], spaces_results[2],
|
1153 |
+
spaces_pie, spaces_bar,
|
1154 |
+
models_results[0], models_results[1], models_results[2],
|
1155 |
+
models_pie, models_bar
|
1156 |
+
]
|
1157 |
+
except Exception as e:
|
1158 |
+
print(f"Error in refresh_all_data: {str(e)}")
|
1159 |
+
# ์๋ฌ ๋ฐ์ ์ ๊ธฐ๋ณธ๊ฐ ๋ฐํ
|
1160 |
+
return [None] * 10
|
1161 |
+
|
1162 |
+
# ์๋ก๊ณ ์นจ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
1163 |
refresh_btn.click(
|
1164 |
+
fn=refresh_all_data,
|
1165 |
outputs=[
|
1166 |
trending_plot, trending_info, trending_df,
|
1167 |
spaces_pie_chart, spaces_bar_chart,
|
|
|
1171 |
)
|
1172 |
|
1173 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
1174 |
+
try:
|
1175 |
+
initial_data = refresh_all_data()
|
1176 |
+
|
1177 |
+
# ์ด๊ธฐ๊ฐ ์ค์
|
1178 |
+
trending_plot.value = initial_data[0]
|
1179 |
+
trending_info.value = initial_data[1]
|
1180 |
+
trending_df.value = initial_data[2]
|
1181 |
+
spaces_pie_chart.value = initial_data[3]
|
1182 |
+
spaces_bar_chart.value = initial_data[4]
|
1183 |
+
models_plot.value = initial_data[5]
|
1184 |
+
models_info.value = initial_data[6]
|
1185 |
+
models_df.value = initial_data[7]
|
1186 |
+
models_pie_chart.value = initial_data[8]
|
1187 |
+
models_bar_chart.value = initial_data[9]
|
1188 |
+
except Exception as e:
|
1189 |
+
print(f"Error loading initial data: {str(e)}")
|
1190 |
+
gr.Warning("์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
|
1191 |
+
|
1192 |
+
# CSS ์คํ์ผ ์ถ๊ฐ
|
1193 |
+
demo.load("""
|
1194 |
+
<style>
|
1195 |
+
#spaces_pie, #models_pie {
|
1196 |
+
min-height: 400px;
|
1197 |
+
border-radius: 10px;
|
1198 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
1199 |
+
}
|
1200 |
+
#spaces_bar, #models_bar {
|
1201 |
+
min-height: 400px;
|
1202 |
+
border-radius: 10px;
|
1203 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
1204 |
+
}
|
1205 |
+
</style>
|
1206 |
+
""")
|
1207 |
|
1208 |
# Gradio ์ฑ ์คํ
|
1209 |
demo.launch(
|
1210 |
server_name="0.0.0.0",
|
1211 |
server_port=7860,
|
1212 |
+
share=False,
|
1213 |
+
show_error=True
|
1214 |
)
|