openfree commited on
Commit
6ab4377
ยท
verified ยท
1 Parent(s): ffd267f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -8
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
- return [*spaces_results, *models_results]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
 
1020
  refresh_btn.click(
1021
  refresh_all_data,
1022
  outputs=[
1023
  trending_plot, trending_info, trending_df,
1024
- models_plot, models_info, models_df
 
 
1025
  ]
1026
  )
1027
 
1028
  # ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ๋กœ๋“œ
1029
- spaces_results = get_spaces_data("trending")
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",