Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -360,6 +360,7 @@ target_models = {
|
|
360 |
"sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
|
361 |
}
|
362 |
|
|
|
363 |
def get_korea_models():
|
364 |
"""Korea ๊ด๋ จ ๋ชจ๋ธ ๊ฒ์"""
|
365 |
params = {
|
@@ -390,7 +391,6 @@ def get_all_models(limit=3000):
|
|
390 |
all_models = []
|
391 |
page_size = 1000 # API์ ํ ๋ฒ ์์ฒญ๋น ์ต๋ ํฌ๊ธฐ
|
392 |
|
393 |
-
# ์ฌ๋ฌ ํ์ด์ง์ ๊ฑธ์ณ ๋ฐ์ดํฐ ์์ง
|
394 |
for offset in range(0, limit, page_size):
|
395 |
params = {
|
396 |
'limit': min(page_size, limit - offset),
|
@@ -412,7 +412,6 @@ def get_all_models(limit=3000):
|
|
412 |
print(f"Failed to fetch models at offset {offset}: {response.status_code}")
|
413 |
break
|
414 |
|
415 |
-
# Korea ๊ฒ์ ๊ฒฐ๊ณผ๋ ๋์ผํ๊ฒ ํ์ฅ
|
416 |
korea_params = {
|
417 |
"search": "korea",
|
418 |
"full": "True",
|
@@ -430,7 +429,6 @@ def get_all_models(limit=3000):
|
|
430 |
korea_models = korea_response.json()
|
431 |
print(f"Fetched {len(korea_models)} Korea-related models")
|
432 |
|
433 |
-
# ์ค๋ณต ์ ๊ฑฐํ๋ฉด์ Korea ๋ชจ๋ธ ์ถ๊ฐ
|
434 |
existing_ids = {model.get('id', '') for model in all_models}
|
435 |
for model in korea_models:
|
436 |
if model.get('id', '') not in existing_ids:
|
@@ -442,7 +440,6 @@ def get_all_models(limit=3000):
|
|
442 |
print(f"Total unique models: {len(all_models)}")
|
443 |
return all_models[:limit]
|
444 |
|
445 |
-
# ๋น๋๊ธฐ API ํธ์ถ์ ์ํ ํจ์๋ค
|
446 |
async def fetch_model_data(session, model_id):
|
447 |
url = f"https://huggingface.co/api/models/{model_id.strip('/')}"
|
448 |
try:
|
@@ -464,15 +461,12 @@ async def fetch_all_target_models(model_ids):
|
|
464 |
|
465 |
def get_models_data(progress=gr.Progress()):
|
466 |
def calculate_rank(model_id, all_global_models, korea_models):
|
467 |
-
# ๊ธ๋ก๋ฒ ์์ ํ์ธ
|
468 |
global_rank = next((idx for idx, m in enumerate(all_global_models, 1)
|
469 |
if m.get('id', '').strip() == model_id.strip()), None)
|
470 |
|
471 |
-
# Korea ๋ชจ๋ธ์ธ ๊ฒฝ์ฐ
|
472 |
is_korea = any(m.get('id', '').strip() == model_id.strip() for m in korea_models)
|
473 |
|
474 |
if is_korea:
|
475 |
-
# Korea ๋ชจ๋ธ ์ค์์์ ์์ ํ์ธ
|
476 |
korea_rank = next((idx for idx, m in enumerate(korea_models, 1)
|
477 |
if m.get('id', '').strip() == model_id.strip()), None)
|
478 |
|
@@ -495,14 +489,13 @@ def get_models_data(progress=gr.Progress()):
|
|
495 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
496 |
return fig, error_html, empty_df
|
497 |
|
498 |
-
#
|
499 |
all_global_models = get_all_models(limit=3000)
|
500 |
korea_models = get_korea_models()
|
501 |
|
502 |
print(f"Total global models fetched: {len(all_global_models)}")
|
503 |
print(f"Total Korea models fetched: {len(korea_models)}")
|
504 |
|
505 |
-
# ๋ชจ๋ ๋ชจ๋ธ ํตํฉ (์ค๋ณต ์ ๊ฑฐ)
|
506 |
all_models = all_global_models.copy()
|
507 |
existing_ids = {model.get('id', '') for model in all_global_models}
|
508 |
|
@@ -516,15 +509,30 @@ def get_models_data(progress=gr.Progress()):
|
|
516 |
print(f"Added {added_korea_models} unique Korea models")
|
517 |
print(f"Total combined models: {len(all_models)}")
|
518 |
|
519 |
-
# ์๊ฐํ๋ฅผ ์ํ Figure ์์ฑ
|
520 |
fig = go.Figure()
|
521 |
|
522 |
-
#
|
523 |
-
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
|
526 |
filtered_models = []
|
527 |
-
for model_id, model_data in zip(
|
528 |
if model_data is not None:
|
529 |
rank, is_korea = calculate_rank(model_id, all_global_models, korea_models)
|
530 |
filtered_models.append({
|
@@ -535,7 +543,7 @@ def get_models_data(progress=gr.Progress()):
|
|
535 |
'title': model_data.get('title', 'No Title'),
|
536 |
'is_korea': is_korea
|
537 |
})
|
538 |
-
print(f"Model {model_id}: Rank={rank}, Is Korea={is_korea}")
|
539 |
else:
|
540 |
filtered_models.append({
|
541 |
'id': model_id,
|
@@ -546,10 +554,14 @@ def get_models_data(progress=gr.Progress()):
|
|
546 |
'is_korea': False
|
547 |
})
|
548 |
|
549 |
-
#
|
550 |
-
|
|
|
|
|
|
|
|
|
|
|
551 |
|
552 |
-
# ์๊ฐํ ๋ฐ์ดํฐ ์ค๋น
|
553 |
valid_models = [m for m in filtered_models if isinstance(m['global_rank'], (int, float))]
|
554 |
|
555 |
if valid_models:
|
@@ -558,12 +570,12 @@ def get_models_data(progress=gr.Progress()):
|
|
558 |
|
559 |
fig.add_trace(go.Bar(
|
560 |
x=ids,
|
561 |
-
y=[3001 - r for r in ranks],
|
562 |
text=[f"Rank: #{r}<br>Downloads: {format(m['downloads'], ',')}<br>Likes: {format(m['likes'], ',')}"
|
563 |
for r, m in zip(ranks, valid_models)],
|
564 |
textposition='auto',
|
565 |
marker_color=['rgba(255,0,0,0.6)' if m['is_korea'] else 'rgba(0,0,255,0.6)'
|
566 |
-
|
567 |
opacity=0.8
|
568 |
))
|
569 |
|
@@ -582,7 +594,6 @@ def get_models_data(progress=gr.Progress()):
|
|
582 |
xaxis_tickangle=-45
|
583 |
)
|
584 |
|
585 |
-
# HTML ์นด๋ ์์ฑ
|
586 |
html_content = """
|
587 |
<div style='padding: 20px; background: #f5f5f5;'>
|
588 |
<h2 style='color: #2c3e50;'>Models Rankings (Up to #3000)</h2>
|
@@ -592,6 +603,8 @@ def get_models_data(progress=gr.Progress()):
|
|
592 |
for model in filtered_models:
|
593 |
rank_display = f"Global Rank #{model['global_rank']}" if isinstance(model['global_rank'], (int, float)) else "Not in top 3000"
|
594 |
korea_badge = "๐ฐ๐ท Korea Search Result" if model['is_korea'] else ""
|
|
|
|
|
595 |
|
596 |
html_content += f"""
|
597 |
<div style='
|
@@ -607,7 +620,7 @@ def get_models_data(progress=gr.Progress()):
|
|
607 |
<p style='color: #e74c3c; font-weight: bold;'>{korea_badge}</p>
|
608 |
<p style='color: #7f8c8d;'>โฌ๏ธ Downloads: {format(model['downloads'], ',')}</p>
|
609 |
<p style='color: #7f8c8d;'>๐ Likes: {format(model['likes'], ',')}</p>
|
610 |
-
<a href='{
|
611 |
target='_blank'
|
612 |
style='
|
613 |
display: inline-block;
|
@@ -625,7 +638,6 @@ def get_models_data(progress=gr.Progress()):
|
|
625 |
|
626 |
html_content += "</div></div>"
|
627 |
|
628 |
-
# ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
629 |
df = pd.DataFrame([{
|
630 |
'Global Rank': f"#{m['global_rank']}" if isinstance(m['global_rank'], (int, float)) else m['global_rank'],
|
631 |
'Model ID': m['id'],
|
@@ -633,7 +645,8 @@ def get_models_data(progress=gr.Progress()):
|
|
633 |
'Downloads': format(m['downloads'], ','),
|
634 |
'Likes': format(m['likes'], ','),
|
635 |
'Korea Search': '๐ฐ๐ท' if m['is_korea'] else '',
|
636 |
-
|
|
|
637 |
} for m in filtered_models])
|
638 |
|
639 |
progress(1.0, desc="Complete!")
|
@@ -651,8 +664,6 @@ def get_models_data(progress=gr.Progress()):
|
|
651 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
652 |
return error_fig, error_html, empty_df
|
653 |
|
654 |
-
|
655 |
-
# ๊ด์ฌ ์คํ์ด์ค URL ๋ฆฌ์คํธ์ ์ ๋ณด
|
656 |
target_spaces = {
|
657 |
|
658 |
"VIDraft/Qwen3-8B": "https://huggingface.co/spaces/VIDraft/Qwen3-8B",
|
@@ -1013,7 +1024,7 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1013 |
url = "https://huggingface.co/api/spaces"
|
1014 |
params = {
|
1015 |
'full': 'true',
|
1016 |
-
'limit':
|
1017 |
}
|
1018 |
|
1019 |
if sort_type == "modes":
|
@@ -1025,29 +1036,36 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1025 |
response.raise_for_status()
|
1026 |
all_spaces = response.json()
|
1027 |
|
1028 |
-
# ์์
|
|
|
|
|
1029 |
space_ranks = {}
|
1030 |
for idx, space in enumerate(all_spaces, 1):
|
1031 |
space_id = space.get('id', '')
|
1032 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1033 |
space['rank'] = idx
|
1034 |
space_ranks[space_id] = space
|
|
|
1035 |
|
1036 |
-
|
|
|
1037 |
spaces.sort(key=lambda x: x['rank'])
|
1038 |
|
1039 |
progress(0.3, desc="Creating visualization...")
|
1040 |
|
1041 |
-
# ์๊ฐํ ์์ฑ
|
1042 |
fig = go.Figure()
|
1043 |
|
1044 |
-
# ๋ฐ์ดํฐ ์ค๋น
|
1045 |
ids = [space['id'] for space in spaces]
|
1046 |
ranks = [space['rank'] for space in spaces]
|
1047 |
likes = [space.get('likes', 0) for space in spaces]
|
1048 |
titles = [space.get('cardData', {}).get('title') or space.get('title', 'No Title') for space in spaces]
|
1049 |
|
1050 |
-
# ๋ง๋ ๊ทธ๋ํ ์์ฑ
|
1051 |
fig.add_trace(go.Bar(
|
1052 |
x=ids,
|
1053 |
y=ranks,
|
@@ -1069,10 +1087,10 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1069 |
xaxis_title='Space ID',
|
1070 |
yaxis_title='Rank',
|
1071 |
yaxis=dict(
|
1072 |
-
autorange='reversed',
|
1073 |
tickmode='array',
|
1074 |
-
ticktext=[str(i) for i in range(1,
|
1075 |
-
tickvals=[i for i in range(1,
|
1076 |
range=[1, 500]
|
1077 |
),
|
1078 |
height=800,
|
@@ -1083,7 +1101,6 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1083 |
|
1084 |
progress(0.6, desc="Creating space cards...")
|
1085 |
|
1086 |
-
# HTML ์นด๋ ์์ฑ
|
1087 |
html_content = f"""
|
1088 |
<div style='padding: 20px; background: #f5f5f5;'>
|
1089 |
<h2 style='color: #2c3e50;'>{sort_type.title()} Rankings</h2>
|
@@ -1096,6 +1113,9 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1096 |
title = space.get('cardData', {}).get('title') or space.get('title', 'No Title')
|
1097 |
likes = space.get('likes', 0)
|
1098 |
|
|
|
|
|
|
|
1099 |
html_content += f"""
|
1100 |
<div style='
|
1101 |
background: white;
|
@@ -1117,7 +1137,7 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1117 |
padding: 5px 0;
|
1118 |
'>{title}</h4>
|
1119 |
<p style='color: #7f8c8d; margin-bottom: 10px;'>๐ Likes: {likes}</p>
|
1120 |
-
<a href='{
|
1121 |
target='_blank'
|
1122 |
style='
|
1123 |
display: inline-block;
|
@@ -1135,13 +1155,12 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1135 |
|
1136 |
html_content += "</div></div>"
|
1137 |
|
1138 |
-
# ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
1139 |
df = pd.DataFrame([{
|
1140 |
'Rank': space['rank'],
|
1141 |
'Space ID': space['id'],
|
1142 |
'Title': space.get('cardData', {}).get('title') or space.get('title', 'No Title'),
|
1143 |
'Likes': space.get('likes', 0),
|
1144 |
-
'URL': target_spaces[space['id']
|
1145 |
} for space in spaces])
|
1146 |
|
1147 |
progress(1.0, desc="Complete!")
|
@@ -1153,18 +1172,17 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
1153 |
error_plot = create_error_plot()
|
1154 |
return error_plot, error_html, pd.DataFrame()
|
1155 |
|
1156 |
-
|
1157 |
def create_trend_visualization(spaces_data):
|
1158 |
if not spaces_data:
|
1159 |
return create_error_plot()
|
1160 |
|
1161 |
fig = go.Figure()
|
1162 |
|
1163 |
-
# ์์ ๋ฐ์ดํฐ ์ค๋น
|
1164 |
ranks = []
|
1165 |
for idx, space in enumerate(spaces_data, 1):
|
1166 |
space_id = space.get('id', '')
|
1167 |
-
|
|
|
1168 |
ranks.append({
|
1169 |
'id': space_id,
|
1170 |
'rank': idx,
|
@@ -1176,16 +1194,13 @@ def create_trend_visualization(spaces_data):
|
|
1176 |
if not ranks:
|
1177 |
return create_error_plot()
|
1178 |
|
1179 |
-
# ์์๋ณ๋ก ์ ๋ ฌ
|
1180 |
ranks.sort(key=lambda x: x['rank'])
|
1181 |
|
1182 |
-
# ๏ฟฝ๏ฟฝ๏ฟฝ๋กฏ ๋ฐ์ดํฐ ์์ฑ
|
1183 |
ids = [r['id'] for r in ranks]
|
1184 |
rank_values = [r['rank'] for r in ranks]
|
1185 |
likes = [r['likes'] for r in ranks]
|
1186 |
views = [r['views'] for r in ranks]
|
1187 |
|
1188 |
-
# ๋ง๋ ๊ทธ๋ํ ์์ฑ
|
1189 |
fig.add_trace(go.Bar(
|
1190 |
x=ids,
|
1191 |
y=rank_values,
|
@@ -1197,7 +1212,7 @@ def create_trend_visualization(spaces_data):
|
|
1197 |
|
1198 |
fig.update_layout(
|
1199 |
title={
|
1200 |
-
'text': 'Current Trending Ranks (All Target Spaces)',
|
1201 |
'y':0.95,
|
1202 |
'x':0.5,
|
1203 |
'xanchor': 'center',
|
@@ -1214,7 +1229,6 @@ def create_trend_visualization(spaces_data):
|
|
1214 |
|
1215 |
return fig
|
1216 |
|
1217 |
-
# ํ ํฐ์ด ์๋ ๊ฒฝ์ฐ๋ฅผ ์ํ ๋์ฒด ํจ์
|
1218 |
def get_trending_spaces_without_token():
|
1219 |
try:
|
1220 |
url = "https://huggingface.co/api/spaces"
|
@@ -1237,7 +1251,6 @@ def get_trending_spaces_without_token():
|
|
1237 |
print(f"API ํธ์ถ ์ค ์๋ฌ ๋ฐ์ (ํ ํฐ ์์): {str(e)}")
|
1238 |
return None
|
1239 |
|
1240 |
-
# API ํ ํฐ ์ค์ ๋ฐ ํจ์ ์ ํ
|
1241 |
if not HF_TOKEN:
|
1242 |
get_trending_spaces = get_trending_spaces_without_token
|
1243 |
|
@@ -1268,10 +1281,12 @@ def create_space_info_html(spaces_data):
|
|
1268 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
1269 |
"""
|
1270 |
|
1271 |
-
#
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
|
|
|
|
1275 |
rank = next((idx for idx, s in enumerate(spaces_data, 1) if s.get('id') == space_id), 'N/A')
|
1276 |
html_content += f"""
|
1277 |
<div style='
|
@@ -1282,11 +1297,11 @@ def create_space_info_html(spaces_data):
|
|
1282 |
transition: transform 0.2s;
|
1283 |
'>
|
1284 |
<h3 style='color: #34495e;'>#{rank} - {space_id}</h3>
|
1285 |
-
<p style='color: #7f8c8d;'>๐ Likes: {
|
1286 |
-
<p style='color: #7f8c8d;'>๐ Views: {
|
1287 |
-
<p style='color: #2c3e50;'>{
|
1288 |
-
<p style='color: #7f8c8d; font-size: 0.9em;'>{
|
1289 |
-
<a href='{target_spaces
|
1290 |
target='_blank'
|
1291 |
style='
|
1292 |
display: inline-block;
|
@@ -1301,30 +1316,6 @@ def create_space_info_html(spaces_data):
|
|
1301 |
</a>
|
1302 |
</div>
|
1303 |
"""
|
1304 |
-
else:
|
1305 |
-
html_content += f"""
|
1306 |
-
<div style='
|
1307 |
-
background: #f8f9fa;
|
1308 |
-
padding: 20px;
|
1309 |
-
border-radius: 10px;
|
1310 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
1311 |
-
'>
|
1312 |
-
<h3 style='color: #34495e;'>{space_id}</h3>
|
1313 |
-
<p style='color: #7f8c8d;'>Not in trending</p>
|
1314 |
-
<a href='{target_spaces[space_id]}'
|
1315 |
-
target='_blank'
|
1316 |
-
style='
|
1317 |
-
display: inline-block;
|
1318 |
-
padding: 8px 16px;
|
1319 |
-
background: #95a5a6;
|
1320 |
-
color: white;
|
1321 |
-
text-decoration: none;
|
1322 |
-
border-radius: 5px;
|
1323 |
-
'>
|
1324 |
-
Visit Space ๐
|
1325 |
-
</a>
|
1326 |
-
</div>
|
1327 |
-
"""
|
1328 |
|
1329 |
html_content += "</div></div>"
|
1330 |
return html_content
|
@@ -1334,15 +1325,16 @@ def create_data_table(spaces_data):
|
|
1334 |
return pd.DataFrame()
|
1335 |
|
1336 |
rows = []
|
|
|
1337 |
for idx, space in enumerate(spaces_data, 1):
|
1338 |
space_id = space.get('id', '')
|
1339 |
-
if space_id in target_spaces:
|
1340 |
rows.append({
|
1341 |
'Rank': idx,
|
1342 |
'Space ID': space_id,
|
1343 |
'Likes': space.get('likes', 'N/A'),
|
1344 |
'Title': space.get('title', 'N/A'),
|
1345 |
-
'URL': target_spaces
|
1346 |
})
|
1347 |
|
1348 |
return pd.DataFrame(rows)
|
@@ -1357,28 +1349,19 @@ def refresh_data():
|
|
1357 |
else:
|
1358 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ๏ฟฝ๏ฟฝํฉ๋๋ค.</div>", pd.DataFrame()
|
1359 |
|
1360 |
-
|
1361 |
-
|
1362 |
def create_registration_bar_chart(data, type_name="Spaces"):
|
1363 |
try:
|
1364 |
-
# TOP ๊ธฐ์ค ์ค์
|
1365 |
top_limit = 500 if type_name == "Spaces" else 3000
|
1366 |
-
|
1367 |
-
# DataFrame์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
|
1368 |
if isinstance(data, pd.DataFrame):
|
1369 |
if type_name == "Models":
|
1370 |
-
# 3000์ ์ด๋ด์ ๋ชจ๋ธ๋ง ํํฐ๋ง
|
1371 |
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
1372 |
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
|
1373 |
elif type_name == "Spaces":
|
1374 |
-
# 500์ ์ด๋ด์ ์คํ์ด์ค๋ง ํํฐ๋ง
|
1375 |
data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
|
1376 |
|
1377 |
-
# ID ์ปฌ๋ผ ์ ํ
|
1378 |
id_column = 'Space ID' if type_name == "Spaces" else 'Model ID'
|
1379 |
registrations = data[id_column].apply(lambda x: x.split('/')[0]).value_counts()
|
1380 |
else:
|
1381 |
-
# ๋ฆฌ์คํธ๋ ๋ค๋ฅธ ํํ์ ๋ฐ์ดํฐ์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
|
1382 |
registrations = {}
|
1383 |
for item in data:
|
1384 |
if isinstance(item, dict):
|
@@ -1389,7 +1372,6 @@ def create_registration_bar_chart(data, type_name="Spaces"):
|
|
1389 |
registrations[creator] = registrations.get(creator, 0) + 1
|
1390 |
registrations = pd.Series(registrations)
|
1391 |
|
1392 |
-
# ์ ๋ ฌ๋ ๋ฐ์ดํฐ ์ค๋น
|
1393 |
registrations = registrations.sort_values(ascending=False)
|
1394 |
|
1395 |
fig = go.Figure(data=[go.Bar(
|
@@ -1416,21 +1398,15 @@ def create_registration_bar_chart(data, type_name="Spaces"):
|
|
1416 |
|
1417 |
def create_pie_chart(data, total_count, type_name="Spaces"):
|
1418 |
try:
|
1419 |
-
# TOP ๊ธฐ์ค ์ค์
|
1420 |
top_limit = 500 if type_name == "Spaces" else 3000
|
1421 |
-
|
1422 |
-
# DataFrame์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
|
1423 |
if isinstance(data, pd.DataFrame):
|
1424 |
if type_name == "Models":
|
1425 |
-
# 3000์ ์ด๋ด์ ๋ชจ๋ธ๋ง ํํฐ๋ง
|
1426 |
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
1427 |
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
|
1428 |
elif type_name == "Spaces":
|
1429 |
-
# 500์ ์ด๋ด์ ์คํ์ด์ค๋ง ํํฐ๋ง
|
1430 |
data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
|
1431 |
korean_count = len(data)
|
1432 |
else:
|
1433 |
-
# ๋ฆฌ์คํธ๋ ๋ค๋ฅธ ํํ์ ๋ฐ์ดํฐ์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
|
1434 |
if type_name == "Models":
|
1435 |
korean_count = sum(1 for item in data if isinstance(item.get('global_rank'), (int, float)) and item.get('global_rank') <= top_limit)
|
1436 |
else:
|
@@ -1465,11 +1441,13 @@ def refresh_all_data():
|
|
1465 |
spaces_results = get_spaces_data("trending")
|
1466 |
models_results = get_models_data()
|
1467 |
|
1468 |
-
#
|
|
|
|
|
|
|
1469 |
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1470 |
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
1471 |
|
1472 |
-
# Models ์ฐจํธ ์์ฑ
|
1473 |
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1474 |
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
1475 |
|
@@ -1480,7 +1458,6 @@ def refresh_all_data():
|
|
1480 |
models_pie, models_bar
|
1481 |
]
|
1482 |
|
1483 |
-
|
1484 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
1485 |
#spaces_pie, #models_pie {
|
1486 |
min-height: 400px;
|
@@ -1499,20 +1476,16 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1499 |
HuggingFace๊ฐ ์ ๊ณตํ๋ Spaces์ Models ์ค์๊ฐ ์ธ๊ธฐ ์์ ๋ฐ์ํ์ฌ 'ํ๊ตญ์ธ(๊ธฐ์
/์ธ์ด)'์ ๋ฆฌ์คํธ(๊ณต๊ฐ,๊ฒ์,๋ฆฌ๋๋ณด๋ ๋ฑ)๋ง ๋ถ์. (c)'ํ๊ตญ์ธ๊ณต์ง๋ฅ์งํฅํํ' / ์์ฒญ: [email protected]
|
1500 |
""")
|
1501 |
|
1502 |
-
# ์ด๋ฏธ์ง์ ์ค๋ช
์ถ๊ฐ
|
1503 |
gr.Markdown("""
|
1504 |
### [Hot NEWS] ํ๊น
ํ์ด์ค ์ ์ 12์ 'TOP 12'์ ํ๊ตญ 'ginipick'์ 'FLUXllama'์ 'Text3D' 2์ข
์ด ์ ์ ๋จ
|
1505 |
""")
|
1506 |
gr.Image("HF-TOP12.png", show_label=False)
|
1507 |
|
1508 |
-
# ์๋ก ๊ณ ์นจ ๋ฒํผ (๊ธฐ์กด ์ฝ๋)
|
1509 |
refresh_btn = gr.Button("๐ ์๋ก ๊ณ ์นจ", variant="primary")
|
1510 |
|
1511 |
-
|
1512 |
with gr.Tab("Spaces Trending"):
|
1513 |
trending_plot = gr.Plot()
|
1514 |
with gr.Row():
|
1515 |
-
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1516 |
with gr.Column(scale=1):
|
1517 |
spaces_pie_chart = gr.Plot(
|
1518 |
label="Korean Spaces Distribution",
|
@@ -1533,7 +1506,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1533 |
with gr.Tab("Models Trending"):
|
1534 |
models_plot = gr.Plot()
|
1535 |
with gr.Row():
|
1536 |
-
# ์ํ ๊ทธ๋ํ์ ๋ง๋ ๊ทธ๋ํ๋ฅผ ์ํ ์ปจํ
์ด๋ ์ถ๊ฐ
|
1537 |
with gr.Column(scale=1):
|
1538 |
models_pie_chart = gr.Plot(
|
1539 |
label="Korean Models Distribution",
|
@@ -1556,11 +1528,9 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1556 |
spaces_results = get_spaces_data("trending")
|
1557 |
models_results = get_models_data()
|
1558 |
|
1559 |
-
# Spaces ์ฐจํธ ์์ฑ
|
1560 |
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1561 |
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
1562 |
|
1563 |
-
# Models ์ฐจํธ ์์ฑ
|
1564 |
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1565 |
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
1566 |
|
@@ -1572,10 +1542,8 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1572 |
]
|
1573 |
except Exception as e:
|
1574 |
print(f"Error in refresh_all_data: {str(e)}")
|
1575 |
-
# ์๋ฌ ๋ฐ์ ์ ๊ธฐ๋ณธ๊ฐ ๋ฐํ
|
1576 |
return [None] * 10
|
1577 |
|
1578 |
-
# ์๋ก๊ณ ์นจ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
1579 |
refresh_btn.click(
|
1580 |
fn=refresh_all_data,
|
1581 |
outputs=[
|
@@ -1586,11 +1554,8 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1586 |
]
|
1587 |
)
|
1588 |
|
1589 |
-
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
1590 |
try:
|
1591 |
initial_data = refresh_all_data()
|
1592 |
-
|
1593 |
-
# ์ด๊ธฐ๊ฐ ์ค์
|
1594 |
trending_plot.value = initial_data[0]
|
1595 |
trending_info.value = initial_data[1]
|
1596 |
trending_df.value = initial_data[2]
|
@@ -1605,7 +1570,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
|
1605 |
print(f"Error loading initial data: {str(e)}")
|
1606 |
gr.Warning("์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
|
1607 |
|
1608 |
-
# Gradio ์ฑ ์คํ
|
1609 |
demo.launch(
|
1610 |
server_name="0.0.0.0",
|
1611 |
server_port=7860,
|
|
|
360 |
"sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
|
361 |
}
|
362 |
|
363 |
+
|
364 |
def get_korea_models():
|
365 |
"""Korea ๊ด๋ จ ๋ชจ๋ธ ๊ฒ์"""
|
366 |
params = {
|
|
|
391 |
all_models = []
|
392 |
page_size = 1000 # API์ ํ ๋ฒ ์์ฒญ๋น ์ต๋ ํฌ๊ธฐ
|
393 |
|
|
|
394 |
for offset in range(0, limit, page_size):
|
395 |
params = {
|
396 |
'limit': min(page_size, limit - offset),
|
|
|
412 |
print(f"Failed to fetch models at offset {offset}: {response.status_code}")
|
413 |
break
|
414 |
|
|
|
415 |
korea_params = {
|
416 |
"search": "korea",
|
417 |
"full": "True",
|
|
|
429 |
korea_models = korea_response.json()
|
430 |
print(f"Fetched {len(korea_models)} Korea-related models")
|
431 |
|
|
|
432 |
existing_ids = {model.get('id', '') for model in all_models}
|
433 |
for model in korea_models:
|
434 |
if model.get('id', '') not in existing_ids:
|
|
|
440 |
print(f"Total unique models: {len(all_models)}")
|
441 |
return all_models[:limit]
|
442 |
|
|
|
443 |
async def fetch_model_data(session, model_id):
|
444 |
url = f"https://huggingface.co/api/models/{model_id.strip('/')}"
|
445 |
try:
|
|
|
461 |
|
462 |
def get_models_data(progress=gr.Progress()):
|
463 |
def calculate_rank(model_id, all_global_models, korea_models):
|
|
|
464 |
global_rank = next((idx for idx, m in enumerate(all_global_models, 1)
|
465 |
if m.get('id', '').strip() == model_id.strip()), None)
|
466 |
|
|
|
467 |
is_korea = any(m.get('id', '').strip() == model_id.strip() for m in korea_models)
|
468 |
|
469 |
if is_korea:
|
|
|
470 |
korea_rank = next((idx for idx, m in enumerate(korea_models, 1)
|
471 |
if m.get('id', '').strip() == model_id.strip()), None)
|
472 |
|
|
|
489 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
490 |
return fig, error_html, empty_df
|
491 |
|
492 |
+
# ์ ์ฒด ๋ชจ๋ธ(์์ 3000) + Korea ๊ฒ์ ๋ชจ๋ธ ๋ชฉ๋ก
|
493 |
all_global_models = get_all_models(limit=3000)
|
494 |
korea_models = get_korea_models()
|
495 |
|
496 |
print(f"Total global models fetched: {len(all_global_models)}")
|
497 |
print(f"Total Korea models fetched: {len(korea_models)}")
|
498 |
|
|
|
499 |
all_models = all_global_models.copy()
|
500 |
existing_ids = {model.get('id', '') for model in all_global_models}
|
501 |
|
|
|
509 |
print(f"Added {added_korea_models} unique Korea models")
|
510 |
print(f"Total combined models: {len(all_models)}")
|
511 |
|
|
|
512 |
fig = go.Figure()
|
513 |
|
514 |
+
# ---------------------------
|
515 |
+
# 1) ๊ธฐ์กด target_models + 2) openfree/ ๊ณ์ ์ ํด๋นํ๋ ๋ชจ๋ธ ID ๋ชจ๋ ํฌํจ
|
516 |
+
# ---------------------------
|
517 |
+
target_model_ids = set(target_models.keys())
|
518 |
+
|
519 |
+
# ์ ์ฒด ๋ชฉ๋ก ์ค 'openfree/' ๋ก ์์ํ๋ ๋ชจ๋ธ๋ ์ถ์ถํด์ ํฌํจ
|
520 |
+
extra_accounts = ["openfree/", "vidraft/", "ginigen/", "heartsync/", "seawolf2357/", "aiqcamp/", "aiqtech/", "fantaxy/", "fantos/", "immunobiotech/", "yokoha/", "cutechicken/", "kolaslab/","kolaslab/", "gunship999/" ]
|
521 |
+
extra_model_ids = {
|
522 |
+
m['id'] for m in all_global_models
|
523 |
+
if isinstance(m.get('id'), str)
|
524 |
+
and any(m['id'].startswith(prefix) for prefix in extra_accounts)
|
525 |
+
}
|
526 |
+
# ์ต์ข
์ ์ผ๋ก rank ๊ณ์ฐํ ๋์
|
527 |
+
final_model_ids = target_model_ids.union(extra_model_ids)
|
528 |
+
|
529 |
+
|
530 |
+
|
531 |
+
# ํด๋น ๋ชจ๋ธ๋ค์ ์์ธ์ ๋ณด ๋น๋๊ธฐ ํธ์ถ
|
532 |
+
model_results = asyncio.run(fetch_all_target_models(final_model_ids))
|
533 |
|
534 |
filtered_models = []
|
535 |
+
for model_id, model_data in zip(final_model_ids, model_results):
|
536 |
if model_data is not None:
|
537 |
rank, is_korea = calculate_rank(model_id, all_global_models, korea_models)
|
538 |
filtered_models.append({
|
|
|
543 |
'title': model_data.get('title', 'No Title'),
|
544 |
'is_korea': is_korea
|
545 |
})
|
546 |
+
# print(f"Model {model_id}: Rank={rank}, Is Korea={is_korea}")
|
547 |
else:
|
548 |
filtered_models.append({
|
549 |
'id': model_id,
|
|
|
554 |
'is_korea': False
|
555 |
})
|
556 |
|
557 |
+
# rank ๊ธฐ์ค ์ ๋ ฌ
|
558 |
+
def rank_value(x):
|
559 |
+
if isinstance(x['global_rank'], str):
|
560 |
+
return float('inf')
|
561 |
+
return x['global_rank']
|
562 |
+
|
563 |
+
filtered_models.sort(key=rank_value)
|
564 |
|
|
|
565 |
valid_models = [m for m in filtered_models if isinstance(m['global_rank'], (int, float))]
|
566 |
|
567 |
if valid_models:
|
|
|
570 |
|
571 |
fig.add_trace(go.Bar(
|
572 |
x=ids,
|
573 |
+
y=[3001 - r for r in ranks],
|
574 |
text=[f"Rank: #{r}<br>Downloads: {format(m['downloads'], ',')}<br>Likes: {format(m['likes'], ',')}"
|
575 |
for r, m in zip(ranks, valid_models)],
|
576 |
textposition='auto',
|
577 |
marker_color=['rgba(255,0,0,0.6)' if m['is_korea'] else 'rgba(0,0,255,0.6)'
|
578 |
+
for m in valid_models],
|
579 |
opacity=0.8
|
580 |
))
|
581 |
|
|
|
594 |
xaxis_tickangle=-45
|
595 |
)
|
596 |
|
|
|
597 |
html_content = """
|
598 |
<div style='padding: 20px; background: #f5f5f5;'>
|
599 |
<h2 style='color: #2c3e50;'>Models Rankings (Up to #3000)</h2>
|
|
|
603 |
for model in filtered_models:
|
604 |
rank_display = f"Global Rank #{model['global_rank']}" if isinstance(model['global_rank'], (int, float)) else "Not in top 3000"
|
605 |
korea_badge = "๐ฐ๐ท Korea Search Result" if model['is_korea'] else ""
|
606 |
+
# target_models ๋์
๋๋ฆฌ์ ์์ ์ ์์ผ๋ฏ๋ก get() ์ฌ์ฉ
|
607 |
+
model_url = target_models.get(model['id'], f"https://huggingface.co/{model['id']}")
|
608 |
|
609 |
html_content += f"""
|
610 |
<div style='
|
|
|
620 |
<p style='color: #e74c3c; font-weight: bold;'>{korea_badge}</p>
|
621 |
<p style='color: #7f8c8d;'>โฌ๏ธ Downloads: {format(model['downloads'], ',')}</p>
|
622 |
<p style='color: #7f8c8d;'>๐ Likes: {format(model['likes'], ',')}</p>
|
623 |
+
<a href='{model_url}'
|
624 |
target='_blank'
|
625 |
style='
|
626 |
display: inline-block;
|
|
|
638 |
|
639 |
html_content += "</div></div>"
|
640 |
|
|
|
641 |
df = pd.DataFrame([{
|
642 |
'Global Rank': f"#{m['global_rank']}" if isinstance(m['global_rank'], (int, float)) else m['global_rank'],
|
643 |
'Model ID': m['id'],
|
|
|
645 |
'Downloads': format(m['downloads'], ','),
|
646 |
'Likes': format(m['likes'], ','),
|
647 |
'Korea Search': '๐ฐ๐ท' if m['is_korea'] else '',
|
648 |
+
# ํน์ target_models ๋์
๋๋ฆฌ์ ์์ ๊ฒฝ์ฐ ์ง์ HF URL
|
649 |
+
'URL': target_models.get(m['id'], f"https://huggingface.co/{m['id']}")
|
650 |
} for m in filtered_models])
|
651 |
|
652 |
progress(1.0, desc="Complete!")
|
|
|
664 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
665 |
return error_fig, error_html, empty_df
|
666 |
|
|
|
|
|
667 |
target_spaces = {
|
668 |
|
669 |
"VIDraft/Qwen3-8B": "https://huggingface.co/spaces/VIDraft/Qwen3-8B",
|
|
|
1024 |
url = "https://huggingface.co/api/spaces"
|
1025 |
params = {
|
1026 |
'full': 'true',
|
1027 |
+
'limit': 1000
|
1028 |
}
|
1029 |
|
1030 |
if sort_type == "modes":
|
|
|
1036 |
response.raise_for_status()
|
1037 |
all_spaces = response.json()
|
1038 |
|
1039 |
+
# ์ฌ๊ธฐ์ ์์(rank)๋ ๋จ์ํ ์๋ต ๋ฐฐ์ด ์์๋๋ก 1๋ถํฐ ๋งค๊น
|
1040 |
+
# ๊ธฐ๋ณธ์ ์ผ๋ก 'sort_type'์ ๋ฐ๋ฅธ ์ ๋ ฌ์ด ๋๏ฟฝ๏ฟฝ ์์ ๊ฒ์ผ๋ก ๊ฐ์ .
|
1041 |
+
|
1042 |
space_ranks = {}
|
1043 |
for idx, space in enumerate(all_spaces, 1):
|
1044 |
space_id = space.get('id', '')
|
1045 |
+
|
1046 |
+
# ๊ธฐ์กด target_spaces + "openfree/" ๋ก ์์ํ๋ ์คํ์ด์ค๋ rank์ ์ถ๊ฐ
|
1047 |
+
|
1048 |
+
if space_id in target_spaces or any(
|
1049 |
+
space_id.startswith(prefix + "/")
|
1050 |
+
for prefix in ["openfree", "vidraft", "ginigen", "heartsync", "seawolf2357", "aiqcamp", "aiqtech", "fantaxy", "fantos", "immunobiotech", "yokoha", "cutechicken","kolaslab", "gunship999"]
|
1051 |
+
):
|
1052 |
space['rank'] = idx
|
1053 |
space_ranks[space_id] = space
|
1054 |
+
|
1055 |
|
1056 |
+
# space_ranks์ ๋ชจ์ธ ์คํ์ด์ค๋ง ์ ๋ ฌ
|
1057 |
+
spaces = [space_ranks[sid] for sid in space_ranks]
|
1058 |
spaces.sort(key=lambda x: x['rank'])
|
1059 |
|
1060 |
progress(0.3, desc="Creating visualization...")
|
1061 |
|
|
|
1062 |
fig = go.Figure()
|
1063 |
|
|
|
1064 |
ids = [space['id'] for space in spaces]
|
1065 |
ranks = [space['rank'] for space in spaces]
|
1066 |
likes = [space.get('likes', 0) for space in spaces]
|
1067 |
titles = [space.get('cardData', {}).get('title') or space.get('title', 'No Title') for space in spaces]
|
1068 |
|
|
|
1069 |
fig.add_trace(go.Bar(
|
1070 |
x=ids,
|
1071 |
y=ranks,
|
|
|
1087 |
xaxis_title='Space ID',
|
1088 |
yaxis_title='Rank',
|
1089 |
yaxis=dict(
|
1090 |
+
autorange='reversed',
|
1091 |
tickmode='array',
|
1092 |
+
ticktext=[str(i) for i in range(1, 1001, 20)],
|
1093 |
+
tickvals=[i for i in range(1, 1001, 20)],
|
1094 |
range=[1, 500]
|
1095 |
),
|
1096 |
height=800,
|
|
|
1101 |
|
1102 |
progress(0.6, desc="Creating space cards...")
|
1103 |
|
|
|
1104 |
html_content = f"""
|
1105 |
<div style='padding: 20px; background: #f5f5f5;'>
|
1106 |
<h2 style='color: #2c3e50;'>{sort_type.title()} Rankings</h2>
|
|
|
1113 |
title = space.get('cardData', {}).get('title') or space.get('title', 'No Title')
|
1114 |
likes = space.get('likes', 0)
|
1115 |
|
1116 |
+
# ๋ง์ฝ target_spaces์ ์์ผ๋ฉด ๊ธฐ๋ณธ ์ฃผ์๋ก
|
1117 |
+
space_url = target_spaces.get(space_id, f"https://huggingface.co/spaces/{space_id}")
|
1118 |
+
|
1119 |
html_content += f"""
|
1120 |
<div style='
|
1121 |
background: white;
|
|
|
1137 |
padding: 5px 0;
|
1138 |
'>{title}</h4>
|
1139 |
<p style='color: #7f8c8d; margin-bottom: 10px;'>๐ Likes: {likes}</p>
|
1140 |
+
<a href='{space_url}'
|
1141 |
target='_blank'
|
1142 |
style='
|
1143 |
display: inline-block;
|
|
|
1155 |
|
1156 |
html_content += "</div></div>"
|
1157 |
|
|
|
1158 |
df = pd.DataFrame([{
|
1159 |
'Rank': space['rank'],
|
1160 |
'Space ID': space['id'],
|
1161 |
'Title': space.get('cardData', {}).get('title') or space.get('title', 'No Title'),
|
1162 |
'Likes': space.get('likes', 0),
|
1163 |
+
'URL': target_spaces.get(space['id'], f"https://huggingface.co/spaces/{space['id']}")
|
1164 |
} for space in spaces])
|
1165 |
|
1166 |
progress(1.0, desc="Complete!")
|
|
|
1172 |
error_plot = create_error_plot()
|
1173 |
return error_plot, error_html, pd.DataFrame()
|
1174 |
|
|
|
1175 |
def create_trend_visualization(spaces_data):
|
1176 |
if not spaces_data:
|
1177 |
return create_error_plot()
|
1178 |
|
1179 |
fig = go.Figure()
|
1180 |
|
|
|
1181 |
ranks = []
|
1182 |
for idx, space in enumerate(spaces_data, 1):
|
1183 |
space_id = space.get('id', '')
|
1184 |
+
# target_spaces + openfree/ ์ฒดํฌ
|
1185 |
+
if space_id in target_spaces or space_id.startswith("openfree/"):
|
1186 |
ranks.append({
|
1187 |
'id': space_id,
|
1188 |
'rank': idx,
|
|
|
1194 |
if not ranks:
|
1195 |
return create_error_plot()
|
1196 |
|
|
|
1197 |
ranks.sort(key=lambda x: x['rank'])
|
1198 |
|
|
|
1199 |
ids = [r['id'] for r in ranks]
|
1200 |
rank_values = [r['rank'] for r in ranks]
|
1201 |
likes = [r['likes'] for r in ranks]
|
1202 |
views = [r['views'] for r in ranks]
|
1203 |
|
|
|
1204 |
fig.add_trace(go.Bar(
|
1205 |
x=ids,
|
1206 |
y=rank_values,
|
|
|
1212 |
|
1213 |
fig.update_layout(
|
1214 |
title={
|
1215 |
+
'text': 'Current Trending Ranks (All Target + openfree Spaces)',
|
1216 |
'y':0.95,
|
1217 |
'x':0.5,
|
1218 |
'xanchor': 'center',
|
|
|
1229 |
|
1230 |
return fig
|
1231 |
|
|
|
1232 |
def get_trending_spaces_without_token():
|
1233 |
try:
|
1234 |
url = "https://huggingface.co/api/spaces"
|
|
|
1251 |
print(f"API ํธ์ถ ์ค ์๋ฌ ๋ฐ์ (ํ ํฐ ์์): {str(e)}")
|
1252 |
return None
|
1253 |
|
|
|
1254 |
if not HF_TOKEN:
|
1255 |
get_trending_spaces = get_trending_spaces_without_token
|
1256 |
|
|
|
1281 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
1282 |
"""
|
1283 |
|
1284 |
+
# ๋์: target_spaces + openfree/๋ก ์์
|
1285 |
+
all_space_keys = set(target_spaces.keys())
|
1286 |
+
|
1287 |
+
for space in spaces_data:
|
1288 |
+
space_id = space.get('id')
|
1289 |
+
if space_id in all_space_keys or (space_id and space_id.startswith("openfree/")):
|
1290 |
rank = next((idx for idx, s in enumerate(spaces_data, 1) if s.get('id') == space_id), 'N/A')
|
1291 |
html_content += f"""
|
1292 |
<div style='
|
|
|
1297 |
transition: transform 0.2s;
|
1298 |
'>
|
1299 |
<h3 style='color: #34495e;'>#{rank} - {space_id}</h3>
|
1300 |
+
<p style='color: #7f8c8d;'>๐ Likes: {space.get('likes', 'N/A')}</p>
|
1301 |
+
<p style='color: #7f8c8d;'>๐ Views: {space.get('views', 'N/A')}</p>
|
1302 |
+
<p style='color: #2c3e50;'>{space.get('title', 'N/A')}</p>
|
1303 |
+
<p style='color: #7f8c8d; font-size: 0.9em;'>{space.get('description', 'N/A')[:100]}...</p>
|
1304 |
+
<a href='{target_spaces.get(space_id, f"https://huggingface.co/spaces/{space_id}")}'
|
1305 |
target='_blank'
|
1306 |
style='
|
1307 |
display: inline-block;
|
|
|
1316 |
</a>
|
1317 |
</div>
|
1318 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1319 |
|
1320 |
html_content += "</div></div>"
|
1321 |
return html_content
|
|
|
1325 |
return pd.DataFrame()
|
1326 |
|
1327 |
rows = []
|
1328 |
+
# ๋์: target_spaces + openfree/๋ก ์์
|
1329 |
for idx, space in enumerate(spaces_data, 1):
|
1330 |
space_id = space.get('id', '')
|
1331 |
+
if space_id in target_spaces or space_id.startswith("openfree/"):
|
1332 |
rows.append({
|
1333 |
'Rank': idx,
|
1334 |
'Space ID': space_id,
|
1335 |
'Likes': space.get('likes', 'N/A'),
|
1336 |
'Title': space.get('title', 'N/A'),
|
1337 |
+
'URL': target_spaces.get(space_id, f"https://huggingface.co/spaces/{space_id}")
|
1338 |
})
|
1339 |
|
1340 |
return pd.DataFrame(rows)
|
|
|
1349 |
else:
|
1350 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ๏ฟฝ๏ฟฝํฉ๋๋ค.</div>", pd.DataFrame()
|
1351 |
|
|
|
|
|
1352 |
def create_registration_bar_chart(data, type_name="Spaces"):
|
1353 |
try:
|
|
|
1354 |
top_limit = 500 if type_name == "Spaces" else 3000
|
|
|
|
|
1355 |
if isinstance(data, pd.DataFrame):
|
1356 |
if type_name == "Models":
|
|
|
1357 |
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
1358 |
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
|
1359 |
elif type_name == "Spaces":
|
|
|
1360 |
data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
|
1361 |
|
|
|
1362 |
id_column = 'Space ID' if type_name == "Spaces" else 'Model ID'
|
1363 |
registrations = data[id_column].apply(lambda x: x.split('/')[0]).value_counts()
|
1364 |
else:
|
|
|
1365 |
registrations = {}
|
1366 |
for item in data:
|
1367 |
if isinstance(item, dict):
|
|
|
1372 |
registrations[creator] = registrations.get(creator, 0) + 1
|
1373 |
registrations = pd.Series(registrations)
|
1374 |
|
|
|
1375 |
registrations = registrations.sort_values(ascending=False)
|
1376 |
|
1377 |
fig = go.Figure(data=[go.Bar(
|
|
|
1398 |
|
1399 |
def create_pie_chart(data, total_count, type_name="Spaces"):
|
1400 |
try:
|
|
|
1401 |
top_limit = 500 if type_name == "Spaces" else 3000
|
|
|
|
|
1402 |
if isinstance(data, pd.DataFrame):
|
1403 |
if type_name == "Models":
|
|
|
1404 |
data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
|
1405 |
data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
|
1406 |
elif type_name == "Spaces":
|
|
|
1407 |
data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
|
1408 |
korean_count = len(data)
|
1409 |
else:
|
|
|
1410 |
if type_name == "Models":
|
1411 |
korean_count = sum(1 for item in data if isinstance(item.get('global_rank'), (int, float)) and item.get('global_rank') <= top_limit)
|
1412 |
else:
|
|
|
1441 |
spaces_results = get_spaces_data("trending")
|
1442 |
models_results = get_models_data()
|
1443 |
|
1444 |
+
# spaces_results / models_results ๊ฐ ๊ฒฐ๊ณผ:
|
1445 |
+
# (plot, html, dataframe)
|
1446 |
+
|
1447 |
+
# ํ์ด/๋ฐ ์ฐจํธ ์์ฑ
|
1448 |
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1449 |
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
1450 |
|
|
|
1451 |
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1452 |
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
1453 |
|
|
|
1458 |
models_pie, models_bar
|
1459 |
]
|
1460 |
|
|
|
1461 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css="""
|
1462 |
#spaces_pie, #models_pie {
|
1463 |
min-height: 400px;
|
|
|
1476 |
HuggingFace๊ฐ ์ ๊ณตํ๋ Spaces์ Models ์ค์๊ฐ ์ธ๊ธฐ ์์ ๋ฐ์ํ์ฌ 'ํ๊ตญ์ธ(๊ธฐ์
/์ธ์ด)'์ ๋ฆฌ์คํธ(๊ณต๊ฐ,๊ฒ์,๋ฆฌ๋๋ณด๋ ๋ฑ)๋ง ๋ถ์. (c)'ํ๊ตญ์ธ๊ณต์ง๋ฅ์งํฅํํ' / ์์ฒญ: [email protected]
|
1477 |
""")
|
1478 |
|
|
|
1479 |
gr.Markdown("""
|
1480 |
### [Hot NEWS] ํ๊น
ํ์ด์ค ์ ์ 12์ 'TOP 12'์ ํ๊ตญ 'ginipick'์ 'FLUXllama'์ 'Text3D' 2์ข
์ด ์ ์ ๋จ
|
1481 |
""")
|
1482 |
gr.Image("HF-TOP12.png", show_label=False)
|
1483 |
|
|
|
1484 |
refresh_btn = gr.Button("๐ ์๋ก ๊ณ ์นจ", variant="primary")
|
1485 |
|
|
|
1486 |
with gr.Tab("Spaces Trending"):
|
1487 |
trending_plot = gr.Plot()
|
1488 |
with gr.Row():
|
|
|
1489 |
with gr.Column(scale=1):
|
1490 |
spaces_pie_chart = gr.Plot(
|
1491 |
label="Korean Spaces Distribution",
|
|
|
1506 |
with gr.Tab("Models Trending"):
|
1507 |
models_plot = gr.Plot()
|
1508 |
with gr.Row():
|
|
|
1509 |
with gr.Column(scale=1):
|
1510 |
models_pie_chart = gr.Plot(
|
1511 |
label="Korean Models Distribution",
|
|
|
1528 |
spaces_results = get_spaces_data("trending")
|
1529 |
models_results = get_models_data()
|
1530 |
|
|
|
1531 |
spaces_pie = create_pie_chart(spaces_results[2], 500, "Spaces")
|
1532 |
spaces_bar = create_registration_bar_chart(spaces_results[2], "Spaces")
|
1533 |
|
|
|
1534 |
models_pie = create_pie_chart(models_results[2], 3000, "Models")
|
1535 |
models_bar = create_registration_bar_chart(models_results[2], "Models")
|
1536 |
|
|
|
1542 |
]
|
1543 |
except Exception as e:
|
1544 |
print(f"Error in refresh_all_data: {str(e)}")
|
|
|
1545 |
return [None] * 10
|
1546 |
|
|
|
1547 |
refresh_btn.click(
|
1548 |
fn=refresh_all_data,
|
1549 |
outputs=[
|
|
|
1554 |
]
|
1555 |
)
|
1556 |
|
|
|
1557 |
try:
|
1558 |
initial_data = refresh_all_data()
|
|
|
|
|
1559 |
trending_plot.value = initial_data[0]
|
1560 |
trending_info.value = initial_data[1]
|
1561 |
trending_df.value = initial_data[2]
|
|
|
1570 |
print(f"Error loading initial data: {str(e)}")
|
1571 |
gr.Warning("์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
|
1572 |
|
|
|
1573 |
demo.launch(
|
1574 |
server_name="0.0.0.0",
|
1575 |
server_port=7860,
|