openfree commited on
Commit
bf59ab9
ยท
verified ยท
1 Parent(s): 6c63b3e

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +149 -124
app-backup.py CHANGED
@@ -18,6 +18,7 @@ target_models = {
18
 
19
  "moreh/Llama-3-Motif-102B-Instruct": "https://huggingface.co/moreh/Llama-3-Motif-102B-Instruct",
20
  "moreh/Llama-3-Motif-102B": "https://huggingface.co/moreh/Llama-3-Motif-102B",
 
21
 
22
  "Saxo/Linkbricks-Horizon-AI-Korean-Gemma-2-sft-dpo-27B": "https://huggingface.co/Saxo/Linkbricks-Horizon-AI-Korean-Gemma-2-sft-dpo-27B",
23
  "AALF/gemma-2-27b-it-SimPO-37K": "https://huggingface.co/AALF/gemma-2-27b-it-SimPO-37K",
@@ -291,7 +292,6 @@ target_models = {
291
  "sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
292
  }
293
 
294
- # all_models ๊ด€๋ จ ์ฝ”๋“œ ์ œ๊ฑฐํ•˜๊ณ  get_models_data ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์ˆ˜์ •
295
 
296
  def get_models_data(progress=gr.Progress()):
297
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
@@ -303,44 +303,83 @@ def get_models_data(progress=gr.Progress()):
303
 
304
  try:
305
  progress(0, desc="Fetching models data...")
 
 
 
 
 
 
306
 
307
- # ์—ฌ๋Ÿฌ ์ •๋ ฌ ๋ฐฉ์‹์œผ๋กœ ์‹œ๋„
308
- all_found_models = []
309
- sort_options = [
310
- {'sort': 'downloads', 'direction': -1},
311
- {'sort': 'lastModified', 'direction': -1},
312
- {'sort': 'likes', 'direction': -1}
313
- ]
314
 
315
- for sort_params in sort_options:
316
- params = {
317
- 'full': 'true',
318
- 'limit': 1000,
319
- **sort_params
320
- }
321
-
322
- headers = {'Accept': 'application/json'}
323
-
324
- response = requests.get(url, params=params, headers=headers)
325
- if response.status_code == 200:
326
- models = response.json()
327
- all_found_models.extend(models)
328
 
329
- # ์ค‘๋ณต ์ œ๊ฑฐ
330
- seen_ids = set()
331
- filtered_models = []
332
- for model in all_found_models:
 
 
 
333
  model_id = normalize_model_id(model.get('id', ''))
334
- if model_id not in seen_ids and model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
335
- seen_ids.add(model_id)
336
- filtered_models.append(model)
 
 
 
337
 
338
- # ๋‹ค์šด๋กœ๋“œ ์ˆ˜๋กœ ์ •๋ ฌ
339
- filtered_models.sort(key=lambda x: x.get('downloads', 0), reverse=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
 
341
- # ์ˆœ์œ„ ํ• ๋‹น
342
- for idx, model in enumerate(filtered_models, 1):
343
- model['rank'] = idx
 
344
 
345
  if not filtered_models:
346
  return create_error_plot(), "<div>์„ ํƒ๋œ ๋ชจ๋ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
@@ -353,17 +392,17 @@ def get_models_data(progress=gr.Progress()):
353
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
354
  ids = [model['id'] for model in filtered_models]
355
  ranks = [model['rank'] for model in filtered_models]
356
- likes = [model.get('likes', 0) for model in filtered_models]
357
- downloads = [model.get('downloads', 0) for model in filtered_models]
358
 
359
- # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
360
- y_values = [1001 - r for r in ranks]
361
 
362
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
363
  fig.add_trace(go.Bar(
364
  x=ids,
365
  y=y_values,
366
- text=[f"Rank: {r}<br>Likes: {l}<br>Downloads: {d}"
367
  for r, l, d in zip(ranks, likes, downloads)],
368
  textposition='auto',
369
  marker_color='rgb(158,202,225)',
@@ -372,18 +411,18 @@ def get_models_data(progress=gr.Progress()):
372
 
373
  fig.update_layout(
374
  title={
375
- 'text': 'Hugging Face Models Trending Rankings (Top 1000)',
376
  'y':0.95,
377
  'x':0.5,
378
  'xanchor': 'center',
379
  'yanchor': 'top'
380
  },
381
  xaxis_title='Model ID',
382
- yaxis_title='Rank',
383
  yaxis=dict(
384
- ticktext=[str(i) for i in range(1, 1001, 50)],
385
- tickvals=[1001 - i for i in range(1, 1001, 50)],
386
- range=[0, 1000]
387
  ),
388
  height=800,
389
  showlegend=False,
@@ -396,7 +435,7 @@ def get_models_data(progress=gr.Progress()):
396
  # HTML ์นด๋“œ ์ƒ์„ฑ
397
  html_content = """
398
  <div style='padding: 20px; background: #f5f5f5;'>
399
- <h2 style='color: #2c3e50;'>Models Trending Rankings</h2>
400
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
401
  """
402
 
@@ -406,6 +445,7 @@ def get_models_data(progress=gr.Progress()):
406
  rank = model['rank']
407
  likes = model.get('likes', 0)
408
  downloads = model.get('downloads', 0)
 
409
 
410
  html_content += f"""
411
  <div style='
@@ -416,8 +456,9 @@ def get_models_data(progress=gr.Progress()):
416
  transition: transform 0.2s;
417
  '>
418
  <h3 style='color: #34495e;'>Rank #{rank} - {model_id}</h3>
419
- <p style='color: #7f8c8d;'>๐Ÿ‘ Likes: {likes}</p>
420
- <p style='color: #7f8c8d;'>โฌ‡๏ธ Downloads: {downloads}</p>
 
421
  <a href='{target_models[model_id]}'
422
  target='_blank'
423
  style='
@@ -434,56 +475,20 @@ def get_models_data(progress=gr.Progress()):
434
  </div>
435
  """
436
 
437
- # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ ์นด๋“œ ์ƒ์„ฑ
438
- for model_id in target_models:
439
- if model_id not in [m['id'] for m in filtered_models]:
440
- html_content += f"""
441
- <div style='
442
- background: #f8f9fa;
443
- padding: 20px;
444
- border-radius: 10px;
445
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
446
- '>
447
- <h3 style='color: #34495e;'>{model_id}</h3>
448
- <p style='color: #7f8c8d;'>Not in top 1000</p>
449
- <a href='{target_models[model_id]}'
450
- target='_blank'
451
- style='
452
- display: inline-block;
453
- padding: 8px 16px;
454
- background: #95a5a6;
455
- color: white;
456
- text-decoration: none;
457
- border-radius: 5px;
458
- '>
459
- Visit Model ๐Ÿ”—
460
- </a>
461
- </div>
462
- """
463
-
464
  html_content += "</div></div>"
465
 
466
  # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
467
  df_data = []
468
- # ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ
469
  for model in filtered_models:
470
  df_data.append({
471
- 'Rank': model['rank'],
472
  'Model ID': model['id'],
473
- 'Likes': model.get('likes', 'N/A'),
474
- 'Downloads': model.get('downloads', 'N/A'),
 
475
  'URL': target_models[model['id']]
476
  })
477
- # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ
478
- for model_id in target_models:
479
- if model_id not in [m['id'] for m in filtered_models]:
480
- df_data.append({
481
- 'Rank': 'Not in top 1000',
482
- 'Model ID': model_id,
483
- 'Likes': 'N/A',
484
- 'Downloads': 'N/A',
485
- 'URL': target_models[model_id]
486
- })
487
 
488
  df = pd.DataFrame(df_data)
489
 
@@ -528,19 +533,28 @@ target_spaces = {
528
  "VIDraft/Mouse-Hackathon": "https://huggingface.co/spaces/VIDraft/Mouse-Hackathon",
529
  "upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard",
530
  "LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo",
 
 
 
 
 
 
 
 
 
531
  "NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
532
  }
533
 
534
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
535
  """์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (trending ๋˜๋Š” modes)"""
536
- url = f"https://huggingface.co/api/spaces"
537
  params = {
538
  'full': 'true',
539
  'limit': 300
540
  }
541
 
542
  if sort_type == "modes":
543
- params['sort'] = 'likes' # modes๋Š” ์ข‹์•„์š” ์ˆœ์œผ๋กœ ์ •๋ ฌ
544
 
545
  try:
546
  progress(0, desc=f"Fetching {sort_type} spaces data...")
@@ -549,16 +563,14 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
549
  all_spaces = response.json()
550
 
551
  # ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
552
- space_ranks = {space['id']: idx + 1 for idx, space in enumerate(all_spaces)}
553
-
554
- # target_spaces ํ•„ํ„ฐ๋ง ๋ฐ ์ˆœ์œ„ ์ •๋ณด ํฌํ•จ
555
- spaces = []
556
- for space in all_spaces:
557
- if space.get('id', '') in target_spaces:
558
- space['rank'] = space_ranks.get(space['id'], 'N/A')
559
- spaces.append(space)
560
 
561
- # ์ˆœ์œ„๋ณ„๋กœ ์ •๋ ฌ
562
  spaces.sort(key=lambda x: x['rank'])
563
 
564
  progress(0.3, desc="Creating visualization...")
@@ -570,15 +582,17 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
570
  ids = [space['id'] for space in spaces]
571
  ranks = [space['rank'] for space in spaces]
572
  likes = [space.get('likes', 0) for space in spaces]
 
573
 
574
- # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „ (300 - rank + 1)
575
- y_values = [301 - r for r in ranks] # ์ˆœ์œ„๋ฅผ ๋ฐ˜์ „๋œ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜
576
 
577
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
578
  fig.add_trace(go.Bar(
579
  x=ids,
580
  y=y_values,
581
- text=[f"Rank: {r}<br>Likes: {l}" for r, l in zip(ranks, likes)],
 
582
  textposition='auto',
583
  marker_color='rgb(158,202,225)',
584
  opacity=0.8
@@ -595,9 +609,9 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
595
  xaxis_title='Space ID',
596
  yaxis_title='Rank',
597
  yaxis=dict(
598
- ticktext=[str(i) for i in range(1, 301, 20)], # 1๋ถ€ํ„ฐ 300๊นŒ์ง€ 20 ๊ฐ„๊ฒฉ
599
- tickvals=[301 - i for i in range(1, 301, 20)], # ๋ฐ˜์ „๋œ ๊ฐ’
600
- range=[0, 300] # y์ถ• ๋ฒ”์œ„ ์„ค์ •
601
  ),
602
  height=800,
603
  showlegend=False,
@@ -615,12 +629,12 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
615
  """
616
 
617
  for space in spaces:
618
- space_id = space.get('id', '')
619
- rank = space.get('rank', 'N/A')
 
620
  likes = space.get('likes', 0)
621
- title = space.get('title', 'No Title')
622
- description = space.get('description', 'No Description')[:100]
623
-
624
  html_content += f"""
625
  <div style='
626
  background: white;
@@ -630,9 +644,18 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
630
  transition: transform 0.2s;
631
  '>
632
  <h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
633
- <p style='color: #7f8c8d;'>๐Ÿ‘ Likes: {likes}</p>
634
- <p style='color: #2c3e50;'>{title}</p>
635
- <p style='color: #7f8c8d; font-size: 0.9em;'>{description}...</p>
 
 
 
 
 
 
 
 
 
636
  <a href='{target_spaces[space_id]}'
637
  target='_blank'
638
  style='
@@ -648,29 +671,30 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
648
  </a>
649
  </div>
650
  """
 
 
651
 
652
  html_content += "</div></div>"
653
 
654
  # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
655
  df = pd.DataFrame([{
656
- 'Rank': space.get('rank', 'N/A'),
657
- 'Space ID': space.get('id', ''),
658
- 'Likes': space.get('likes', 'N/A'),
659
- 'Title': space.get('title', 'N/A'),
660
- 'URL': target_spaces[space.get('id', '')]
661
  } for space in spaces])
662
 
663
  progress(1.0, desc="Complete!")
664
  return fig, html_content, df
665
 
666
  except Exception as e:
 
667
  error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
668
  error_plot = create_error_plot()
669
  return error_plot, error_html, pd.DataFrame()
670
 
671
 
672
-
673
-
674
  def create_trend_visualization(spaces_data):
675
  if not spaces_data:
676
  return create_error_plot()
@@ -877,13 +901,15 @@ def refresh_data():
877
  else:
878
  return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.</div>", pd.DataFrame()
879
 
880
-
881
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
882
  gr.Markdown("""
883
- # ๐Ÿค— ํ—ˆ๊น…ํŽ˜์ด์Šค 'ํ•œ๊ตญ ๋ฆฌ๋”๋ณด๋“œ'
884
- ์‹ค์‹œ๊ฐ„์œผ๋กœ Hugging Face์˜ Spaces์™€ Models ์ธ๊ธฐ ์ˆœ์œ„๋ฅผ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. ์‹ ๊ทœ ๋“ฑ๋ก ์š”์ฒญ: [email protected]
885
  """)
886
 
 
 
 
887
  with gr.Tab("Spaces Trending"):
888
  trending_plot = gr.Plot()
889
  trending_info = gr.HTML()
@@ -894,8 +920,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
894
  models_info = gr.HTML()
895
  models_df = gr.DataFrame()
896
 
897
- refresh_btn = gr.Button("๐Ÿ”„ Refresh Data", variant="primary")
898
-
899
  def refresh_all_data():
900
  spaces_results = get_spaces_data("trending")
901
  models_results = get_models_data()
@@ -916,6 +940,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
916
  trending_plot.value, trending_info.value, trending_df.value = spaces_results
917
  models_plot.value, models_info.value, models_df.value = models_results
918
 
 
919
  # Gradio ์•ฑ ์‹คํ–‰
920
  demo.launch(
921
  server_name="0.0.0.0",
 
18
 
19
  "moreh/Llama-3-Motif-102B-Instruct": "https://huggingface.co/moreh/Llama-3-Motif-102B-Instruct",
20
  "moreh/Llama-3-Motif-102B": "https://huggingface.co/moreh/Llama-3-Motif-102B",
21
+ "Samsung/TinyClick": "https://huggingface.co/Samsung/TinyClick",
22
 
23
  "Saxo/Linkbricks-Horizon-AI-Korean-Gemma-2-sft-dpo-27B": "https://huggingface.co/Saxo/Linkbricks-Horizon-AI-Korean-Gemma-2-sft-dpo-27B",
24
  "AALF/gemma-2-27b-it-SimPO-37K": "https://huggingface.co/AALF/gemma-2-27b-it-SimPO-37K",
 
292
  "sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
293
  }
294
 
 
295
 
296
  def get_models_data(progress=gr.Progress()):
297
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
 
303
 
304
  try:
305
  progress(0, desc="Fetching models data...")
306
+ params = {
307
+ 'full': 'true',
308
+ 'limit': 3000, # 3000๊ฐœ๋กœ ์ฆ๊ฐ€
309
+ 'sort': 'likes',
310
+ 'direction': -1
311
+ }
312
 
313
+ headers = {'Accept': 'application/json'}
 
 
 
 
 
 
314
 
315
+ response = requests.get(url, params=params, headers=headers)
316
+ if response.status_code != 200:
317
+ print(f"API ์š”์ฒญ ์‹คํŒจ: {response.status_code}")
318
+ print(f"Response: {response.text}")
319
+ return create_error_plot(), "<div>๋ชจ๋ธ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
 
 
 
 
 
 
 
 
320
 
321
+ models = response.json()
322
+
323
+ # ์ „์ฒด ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ (๋‹ค์šด๋กœ๋“œ ์ˆ˜ ๊ธฐ์ค€)
324
+ model_ranks = {}
325
+ model_data = {} # ๋ชจ๋“  ๋ชจ๋ธ์˜ ์ƒ์„ธ ๋ฐ์ดํ„ฐ ์ €์žฅ
326
+
327
+ for idx, model in enumerate(models, 1):
328
  model_id = normalize_model_id(model.get('id', ''))
329
+ model_data[model_id] = {
330
+ 'rank': idx,
331
+ 'downloads': model.get('downloads', 0),
332
+ 'likes': model.get('likes', 0),
333
+ 'title': model.get('title', 'No Title')
334
+ }
335
 
336
+ # target_models ์ค‘ ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ ํ•„ํ„ฐ๋ง
337
+ filtered_models = []
338
+ for target_id in target_models.keys():
339
+ normalized_target_id = normalize_model_id(target_id)
340
+
341
+ # ๋จผ์ € ์ „์ฒด ์ˆœ์œ„์—์„œ ์ฐพ๊ธฐ
342
+ if normalized_target_id in model_data:
343
+ model_info = {
344
+ 'id': target_id,
345
+ 'rank': model_data[normalized_target_id]['rank'],
346
+ 'downloads': model_data[normalized_target_id]['downloads'],
347
+ 'likes': model_data[normalized_target_id]['likes'],
348
+ 'title': model_data[normalized_target_id]['title']
349
+ }
350
+ else:
351
+ # ์ˆœ์œ„๊ถŒ ๋ฐ–์˜ ๋ชจ๋ธ์€ ๊ฐœ๋ณ„ API ํ˜ธ์ถœ๋กœ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
352
+ try:
353
+ model_url = f"https://huggingface.co/api/models/{target_id}"
354
+ model_response = requests.get(model_url, headers=headers)
355
+ if model_response.status_code == 200:
356
+ model_info = model_response.json()
357
+ model_info['id'] = target_id
358
+ model_info['rank'] = 'Not in top 3000'
359
+ else:
360
+ model_info = {
361
+ 'id': target_id,
362
+ 'rank': 'Not in top 3000',
363
+ 'downloads': 0,
364
+ 'likes': 0,
365
+ 'title': 'No Title'
366
+ }
367
+ except Exception as e:
368
+ print(f"Error fetching data for model {target_id}: {str(e)}")
369
+ model_info = {
370
+ 'id': target_id,
371
+ 'rank': 'Not in top 3000',
372
+ 'downloads': 0,
373
+ 'likes': 0,
374
+ 'title': 'No Title'
375
+ }
376
+
377
+ filtered_models.append(model_info)
378
 
379
+ # ์ˆœ์œ„๋กœ ์ •๋ ฌ (์ˆœ์œ„๊ฐ€ ์ˆซ์ž์ธ ๊ฒฝ์šฐ๋งŒ)
380
+ filtered_models.sort(key=lambda x: (
381
+ float('inf') if x['rank'] == 'Not in top 3000' else x['rank']
382
+ ))
383
 
384
  if not filtered_models:
385
  return create_error_plot(), "<div>์„ ํƒ๋œ ๋ชจ๋ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
 
392
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
393
  ids = [model['id'] for model in filtered_models]
394
  ranks = [model['rank'] for model in filtered_models]
395
+ likes = [model['likes'] for model in filtered_models]
396
+ downloads = [model['downloads'] for model in filtered_models]
397
 
398
+ # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „ (์ˆซ์ž ์ˆœ์œ„๋งŒ)
399
+ y_values = [3001 - r if isinstance(r, int) else 0 for r in ranks]
400
 
401
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
402
  fig.add_trace(go.Bar(
403
  x=ids,
404
  y=y_values,
405
+ text=[f"Rank: {r}<br>Likes: {l:,}<br>Downloads: {d:,}"
406
  for r, l, d in zip(ranks, likes, downloads)],
407
  textposition='auto',
408
  marker_color='rgb(158,202,225)',
 
411
 
412
  fig.update_layout(
413
  title={
414
+ 'text': 'Hugging Face Models Global Download Rankings (Top 3000)',
415
  'y':0.95,
416
  'x':0.5,
417
  'xanchor': 'center',
418
  'yanchor': 'top'
419
  },
420
  xaxis_title='Model ID',
421
+ yaxis_title='Global Rank',
422
  yaxis=dict(
423
+ ticktext=[str(i) for i in range(1, 3001, 150)],
424
+ tickvals=[3001 - i for i in range(1, 3001, 150)],
425
+ range=[0, 3000]
426
  ),
427
  height=800,
428
  showlegend=False,
 
435
  # HTML ์นด๋“œ ์ƒ์„ฑ
436
  html_content = """
437
  <div style='padding: 20px; background: #f5f5f5;'>
438
+ <h2 style='color: #2c3e50;'>Models ๊ธ€๋กœ๋ฒŒ ์ธ๊ธฐ ์ˆœ์œ„ (Top 3000)</h2>
439
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
440
  """
441
 
 
445
  rank = model['rank']
446
  likes = model.get('likes', 0)
447
  downloads = model.get('downloads', 0)
448
+ title = model.get('title', 'No Title')
449
 
450
  html_content += f"""
451
  <div style='
 
456
  transition: transform 0.2s;
457
  '>
458
  <h3 style='color: #34495e;'>Rank #{rank} - {model_id}</h3>
459
+ <p style='color: #2c3e50;'>{title}</p>
460
+ <p style='color: #7f8c8d;'>๐Ÿ‘ Likes: {likes:,}</p>
461
+ <p style='color: #7f8c8d;'>โฌ‡๏ธ Downloads: {downloads:,}</p>
462
  <a href='{target_models[model_id]}'
463
  target='_blank'
464
  style='
 
475
  </div>
476
  """
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  html_content += "</div></div>"
479
 
480
  # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
481
  df_data = []
482
+ # ๋ชจ๋“  ๋ชจ๋ธ ์ •๋ณด๋ฅผ ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์— ์ถ”๊ฐ€
483
  for model in filtered_models:
484
  df_data.append({
485
+ 'Global Rank': model['rank'],
486
  'Model ID': model['id'],
487
+ 'Title': model.get('title', 'No Title'),
488
+ 'Likes': f"{model.get('likes', 0):,}",
489
+ 'Downloads': f"{model.get('downloads', 0):,}",
490
  'URL': target_models[model['id']]
491
  })
 
 
 
 
 
 
 
 
 
 
492
 
493
  df = pd.DataFrame(df_data)
494
 
 
533
  "VIDraft/Mouse-Hackathon": "https://huggingface.co/spaces/VIDraft/Mouse-Hackathon",
534
  "upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard",
535
  "LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo",
536
+
537
+ "cutechicken/TankWar3D": "https://huggingface.co/spaces/cutechicken/TankWar3D",
538
+ "kolaslab/RC4-EnDecoder": "https://huggingface.co/spaces/kolaslab/RC4-EnDecoder",
539
+ "kolaslab/simulator": "https://huggingface.co/spaces/kolaslab/simulator",
540
+ "kolaslab/calculator": "https://huggingface.co/spaces/kolaslab/calculator",
541
+ "etri-vilab/Ko-LLaVA": "https://huggingface.co/spaces/etri-vilab/Ko-LLaVA",
542
+ "etri-vilab/KOALA": "https://huggingface.co/spaces/etri-vilab/KOALA",
543
+ "naver-clova-ix/donut-base-finetuned-cord-v2": "https://huggingface.co/spaces/naver-clova-ix/donut-base-finetuned-cord-v2",
544
+
545
  "NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
546
  }
547
 
548
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
549
  """์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (trending ๋˜๋Š” modes)"""
550
+ url = "https://huggingface.co/api/spaces"
551
  params = {
552
  'full': 'true',
553
  'limit': 300
554
  }
555
 
556
  if sort_type == "modes":
557
+ params['sort'] = 'likes'
558
 
559
  try:
560
  progress(0, desc=f"Fetching {sort_type} spaces data...")
 
563
  all_spaces = response.json()
564
 
565
  # ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
566
+ space_ranks = {}
567
+ for idx, space in enumerate(all_spaces, 1):
568
+ space_id = space.get('id', '')
569
+ if space_id in target_spaces:
570
+ space['rank'] = idx
571
+ space_ranks[space_id] = space
 
 
572
 
573
+ spaces = [space_ranks[space_id] for space_id in space_ranks.keys()]
574
  spaces.sort(key=lambda x: x['rank'])
575
 
576
  progress(0.3, desc="Creating visualization...")
 
582
  ids = [space['id'] for space in spaces]
583
  ranks = [space['rank'] for space in spaces]
584
  likes = [space.get('likes', 0) for space in spaces]
585
+ titles = [space.get('cardData', {}).get('title') or space.get('title', 'No Title') for space in spaces]
586
 
587
+ # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
588
+ y_values = [301 - r for r in ranks]
589
 
590
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
591
  fig.add_trace(go.Bar(
592
  x=ids,
593
  y=y_values,
594
+ text=[f"Rank: {r}<br>Title: {t}<br>Likes: {l}"
595
+ for r, t, l in zip(ranks, titles, likes)],
596
  textposition='auto',
597
  marker_color='rgb(158,202,225)',
598
  opacity=0.8
 
609
  xaxis_title='Space ID',
610
  yaxis_title='Rank',
611
  yaxis=dict(
612
+ ticktext=[str(i) for i in range(1, 301, 20)],
613
+ tickvals=[301 - i for i in range(1, 301, 20)],
614
+ range=[0, 300]
615
  ),
616
  height=800,
617
  showlegend=False,
 
629
  """
630
 
631
  for space in spaces:
632
+ space_id = space['id']
633
+ rank = space['rank']
634
+ title = space.get('cardData', {}).get('title') or space.get('title', 'No Title')
635
  likes = space.get('likes', 0)
636
+
637
+ # ์ŠคํŽ˜์ด์Šค ํ•จ์ˆ˜์˜ HTML ์นด๋“œ ์ƒ์„ฑ ๋ถ€๋ถ„ ์ˆ˜์ •
 
638
  html_content += f"""
639
  <div style='
640
  background: white;
 
644
  transition: transform 0.2s;
645
  '>
646
  <h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
647
+ <h4 style='
648
+ color: #2980b9;
649
+ margin: 10px 0;
650
+ font-size: 1.2em;
651
+ font-weight: bold;
652
+ text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
653
+ background: linear-gradient(to right, #3498db, #2980b9);
654
+ -webkit-background-clip: text;
655
+ -webkit-text-fill-color: transparent;
656
+ padding: 5px 0;
657
+ '>{title}</h4>
658
+ <p style='color: #7f8c8d; margin-bottom: 10px;'>๐Ÿ‘ Likes: {likes}</p>
659
  <a href='{target_spaces[space_id]}'
660
  target='_blank'
661
  style='
 
671
  </a>
672
  </div>
673
  """
674
+
675
+
676
 
677
  html_content += "</div></div>"
678
 
679
  # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
680
  df = pd.DataFrame([{
681
+ 'Rank': space['rank'],
682
+ 'Space ID': space['id'],
683
+ 'Title': space.get('cardData', {}).get('title') or space.get('title', 'No Title'),
684
+ 'Likes': space.get('likes', 0),
685
+ 'URL': target_spaces[space['id']]
686
  } for space in spaces])
687
 
688
  progress(1.0, desc="Complete!")
689
  return fig, html_content, df
690
 
691
  except Exception as e:
692
+ print(f"Error in get_spaces_data: {str(e)}")
693
  error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
694
  error_plot = create_error_plot()
695
  return error_plot, error_html, pd.DataFrame()
696
 
697
 
 
 
698
  def create_trend_visualization(spaces_data):
699
  if not spaces_data:
700
  return create_error_plot()
 
901
  else:
902
  return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.</div>", pd.DataFrame()
903
 
 
904
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
905
  gr.Markdown("""
906
+ # ๐Ÿค— ํ—ˆ๊น…ํŽ˜์ด์Šค 'ํ•œ๊ตญ(์–ธ์–ด) ๋ฆฌ๋”๋ณด๋“œ'
907
+ ์‹ค์‹œ๊ฐ„์œผ๋กœ Hugging Face์˜ Spaces์™€ Models ์ธ๊ธฐ ์ˆœ์œ„๋ฅผ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. ํ•œ๊ตญ์ธ(๊ธฐ์—…)์ด ๊ณต๊ฐœ ๋ฐ ํ•œ๊ตญ์–ด 'LLM ๋ฆฌ๋”๋ณด๋“œ'์— ๊ณต๊ฐœ๋œ ๋ฆฌ์ŠคํŠธ ๋“ฑ์„ ๋“ฑ๋ก. ์‹ ๊ทœ ๋“ฑ๋ก ์š”์ฒญ: [email protected]
908
  """)
909
 
910
+ # ์ƒˆ๋กœ ๊ณ ์นจ ๋ฒ„ํŠผ์„ ์ƒ๋‹จ์œผ๋กœ ์ด๋™ํ•˜๊ณ  ํ•œ๊ธ€๋กœ ๋ณ€๊ฒฝ
911
+ refresh_btn = gr.Button("๐Ÿ”„ ์ƒˆ๋กœ ๊ณ ์นจ", variant="primary")
912
+
913
  with gr.Tab("Spaces Trending"):
914
  trending_plot = gr.Plot()
915
  trending_info = gr.HTML()
 
920
  models_info = gr.HTML()
921
  models_df = gr.DataFrame()
922
 
 
 
923
  def refresh_all_data():
924
  spaces_results = get_spaces_data("trending")
925
  models_results = get_models_data()
 
940
  trending_plot.value, trending_info.value, trending_df.value = spaces_results
941
  models_plot.value, models_info.value, models_df.value = models_results
942
 
943
+
944
  # Gradio ์•ฑ ์‹คํ–‰
945
  demo.launch(
946
  server_name="0.0.0.0",