Update app.py
Browse files
app.py
CHANGED
|
@@ -993,6 +993,63 @@ def refresh_data():
|
|
| 993 |
else:
|
| 994 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ์ํฉ๋๋ค.</div>", pd.DataFrame()
|
| 995 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 997 |
gr.Markdown("""
|
| 998 |
# ๐ค ํ๊น
ํ์ด์ค 'ํ๊ตญ(์ธ์ด) ๋ฆฌ๋๋ณด๋'
|
|
@@ -1004,35 +1061,70 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 1004 |
|
| 1005 |
with gr.Tab("Spaces Trending"):
|
| 1006 |
trending_plot = gr.Plot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
trending_info = gr.HTML()
|
| 1008 |
trending_df = gr.DataFrame()
|
| 1009 |
|
| 1010 |
with gr.Tab("Models Trending"):
|
| 1011 |
models_plot = gr.Plot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1012 |
models_info = gr.HTML()
|
| 1013 |
models_df = gr.DataFrame()
|
| 1014 |
|
| 1015 |
def refresh_all_data():
|
| 1016 |
spaces_results = get_spaces_data("trending")
|
| 1017 |
models_results = get_models_data()
|
| 1018 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1019 |
|
| 1020 |
refresh_btn.click(
|
| 1021 |
refresh_all_data,
|
| 1022 |
outputs=[
|
| 1023 |
trending_plot, trending_info, trending_df,
|
| 1024 |
-
|
|
|
|
|
|
|
| 1025 |
]
|
| 1026 |
)
|
| 1027 |
|
| 1028 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
| 1029 |
-
|
| 1030 |
-
models_results = get_models_data()
|
| 1031 |
-
|
| 1032 |
-
trending_plot.value, trending_info.value, trending_df.value = spaces_results
|
| 1033 |
-
models_plot.value, models_info.value, models_df.value = models_results
|
| 1034 |
-
|
| 1035 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
# Gradio ์ฑ ์คํ
|
| 1037 |
demo.launch(
|
| 1038 |
server_name="0.0.0.0",
|
|
|
|
| 993 |
else:
|
| 994 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ์ํฉ๋๋ค.</div>", pd.DataFrame()
|
| 995 |
|
| 996 |
+
|
| 997 |
+
|
| 998 |
+
def create_pie_chart(data, total_count, type_name="Spaces"):
|
| 999 |
+
korean_count = len(data)
|
| 1000 |
+
other_count = total_count - korean_count
|
| 1001 |
+
|
| 1002 |
+
fig = go.Figure(data=[go.Pie(
|
| 1003 |
+
labels=[f'Korean {type_name}', f'Other {type_name}'],
|
| 1004 |
+
values=[korean_count, other_count],
|
| 1005 |
+
hole=.3,
|
| 1006 |
+
marker_colors=['#FF6B6B', '#4ECDC4'],
|
| 1007 |
+
textinfo='percent+value',
|
| 1008 |
+
hovertemplate="<b>%{label}</b><br>" +
|
| 1009 |
+
"Count: %{value}<br>" +
|
| 1010 |
+
"Percentage: %{percent}<br>"
|
| 1011 |
+
)])
|
| 1012 |
+
|
| 1013 |
+
fig.update_layout(
|
| 1014 |
+
title=f"Korean vs Other {type_name} Distribution",
|
| 1015 |
+
showlegend=True,
|
| 1016 |
+
height=400,
|
| 1017 |
+
width=500
|
| 1018 |
+
)
|
| 1019 |
+
|
| 1020 |
+
return fig
|
| 1021 |
+
|
| 1022 |
+
def create_registration_bar_chart(data, type_name="Spaces"):
|
| 1023 |
+
# ๋ฑ๋ก์๋ณ ๊ฑด์ ์ง๊ณ
|
| 1024 |
+
registrations = {}
|
| 1025 |
+
for item in data:
|
| 1026 |
+
creator = item.get('id', '').split('/')[0] # ID์ ์ฒซ ๋ถ๋ถ์ ๋ฑ๋ก์๋ก ๊ฐ์ฃผ
|
| 1027 |
+
registrations[creator] = registrations.get(creator, 0) + 1
|
| 1028 |
+
|
| 1029 |
+
# ์ ๋ ฌ๋ ๋ฐ์ดํฐ ์ค๋น
|
| 1030 |
+
sorted_data = sorted(registrations.items(), key=lambda x: x[1], reverse=True)
|
| 1031 |
+
creators = [x[0] for x in sorted_data]
|
| 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 |
+
fig.update_layout(
|
| 1043 |
+
title=f"Korean {type_name} Registrations by Creator",
|
| 1044 |
+
xaxis_title="Creator ID",
|
| 1045 |
+
yaxis_title="Number of Registrations",
|
| 1046 |
+
showlegend=False,
|
| 1047 |
+
height=400,
|
| 1048 |
+
width=700
|
| 1049 |
+
)
|
| 1050 |
+
|
| 1051 |
+
return fig
|
| 1052 |
+
|
| 1053 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 1054 |
gr.Markdown("""
|
| 1055 |
# ๐ค ํ๊น
ํ์ด์ค 'ํ๊ตญ(์ธ์ด) ๋ฆฌ๋๋ณด๋'
|
|
|
|
| 1061 |
|
| 1062 |
with gr.Tab("Spaces Trending"):
|
| 1063 |
trending_plot = gr.Plot()
|
| 1064 |
+
with gr.Row():
|
| 1065 |
+
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
| 1066 |
+
with gr.Column():
|
| 1067 |
+
spaces_pie_chart = gr.Plot(label="Korean Spaces Distribution")
|
| 1068 |
+
with gr.Column():
|
| 1069 |
+
spaces_bar_chart = gr.Plot(label="Registrations by Creator")
|
| 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(label="Korean Models Distribution")
|
| 1079 |
+
with gr.Column():
|
| 1080 |
+
models_bar_chart = gr.Plot(label="Registrations by Creator")
|
| 1081 |
models_info = gr.HTML()
|
| 1082 |
models_df = gr.DataFrame()
|
| 1083 |
|
| 1084 |
def refresh_all_data():
|
| 1085 |
spaces_results = get_spaces_data("trending")
|
| 1086 |
models_results = get_models_data()
|
| 1087 |
+
|
| 1088 |
+
# Spaces ์ฐจํธ ์์ฑ
|
| 1089 |
+
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces") # DataFrame์์ ๋ฐ์ดํฐ ์ถ์ถ
|
| 1090 |
+
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
| 1091 |
+
|
| 1092 |
+
# Models ์ฐจํธ ์์ฑ
|
| 1093 |
+
models_pie = create_pie_chart(models_results[2], 3000, "Models") # DataFrame์์ ๋ฐ์ดํฐ ์ถ์ถ
|
| 1094 |
+
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
| 1095 |
+
|
| 1096 |
+
return [
|
| 1097 |
+
spaces_results[0], spaces_results[1], spaces_results[2],
|
| 1098 |
+
spaces_pie, spaces_bar,
|
| 1099 |
+
models_results[0], models_results[1], models_results[2],
|
| 1100 |
+
models_pie, models_bar
|
| 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,
|
| 1108 |
+
models_plot, models_info, models_df,
|
| 1109 |
+
models_pie_chart, models_bar_chart
|
| 1110 |
]
|
| 1111 |
)
|
| 1112 |
|
| 1113 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
| 1114 |
+
initial_data = refresh_all_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1115 |
|
| 1116 |
+
# ์ด๊ธฐ๊ฐ ์ค์
|
| 1117 |
+
trending_plot.value = initial_data[0]
|
| 1118 |
+
trending_info.value = initial_data[1]
|
| 1119 |
+
trending_df.value = initial_data[2]
|
| 1120 |
+
spaces_pie_chart.value = initial_data[3]
|
| 1121 |
+
spaces_bar_chart.value = initial_data[4]
|
| 1122 |
+
models_plot.value = initial_data[5]
|
| 1123 |
+
models_info.value = initial_data[6]
|
| 1124 |
+
models_df.value = initial_data[7]
|
| 1125 |
+
models_pie_chart.value = initial_data[8]
|
| 1126 |
+
models_bar_chart.value = initial_data[9]
|
| 1127 |
+
|
| 1128 |
# Gradio ์ฑ ์คํ
|
| 1129 |
demo.launch(
|
| 1130 |
server_name="0.0.0.0",
|