openfree commited on
Commit
5f0579d
โ€ข
1 Parent(s): 902ba72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -74
app.py CHANGED
@@ -292,6 +292,7 @@ target_models = {
292
  "sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
293
  }
294
 
 
295
  def get_models_data(progress=gr.Progress()):
296
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
297
  def normalize_model_id(model_id):
@@ -305,7 +306,7 @@ def get_models_data(progress=gr.Progress()):
305
  params = {
306
  'full': 'true',
307
  'limit': 3000, # 3000๊ฐœ๋กœ ์ฆ๊ฐ€
308
- 'sort': 'likes',
309
  'direction': -1
310
  }
311
 
@@ -336,6 +337,8 @@ def get_models_data(progress=gr.Progress()):
336
  filtered_models = []
337
  for target_id in target_models.keys():
338
  normalized_target_id = normalize_model_id(target_id)
 
 
339
  if normalized_target_id in model_data:
340
  model_info = {
341
  'id': target_id,
@@ -344,10 +347,39 @@ def get_models_data(progress=gr.Progress()):
344
  'likes': model_data[normalized_target_id]['likes'],
345
  'title': model_data[normalized_target_id]['title']
346
  }
347
- filtered_models.append(model_info)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
- # ์ˆœ์œ„๋กœ ์ •๋ ฌ
350
- filtered_models.sort(key=lambda x: x['rank'])
 
 
351
 
352
  if not filtered_models:
353
  return create_error_plot(), "<div>์„ ํƒ๋œ ๋ชจ๋ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
@@ -363,8 +395,8 @@ def get_models_data(progress=gr.Progress()):
363
  likes = [model['likes'] for model in filtered_models]
364
  downloads = [model['downloads'] for model in filtered_models]
365
 
366
- # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
367
- y_values = [3001 - r for r in ranks] # 3000์œผ๋กœ ๋ณ€๊ฒฝ
368
 
369
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
370
  fig.add_trace(go.Bar(
@@ -388,7 +420,7 @@ def get_models_data(progress=gr.Progress()):
388
  xaxis_title='Model ID',
389
  yaxis_title='Global Rank',
390
  yaxis=dict(
391
- ticktext=[str(i) for i in range(1, 3001, 150)], # ๊ฐ„๊ฒฉ ์กฐ์ •
392
  tickvals=[3001 - i for i in range(1, 3001, 150)],
393
  range=[0, 3000]
394
  ),
@@ -411,8 +443,8 @@ def get_models_data(progress=gr.Progress()):
411
  for model in filtered_models:
412
  model_id = model['id']
413
  rank = model['rank']
414
- likes = model['likes']
415
- downloads = model['downloads']
416
  title = model.get('title', 'No Title')
417
 
418
  html_content += f"""
@@ -443,58 +475,20 @@ def get_models_data(progress=gr.Progress()):
443
  </div>
444
  """
445
 
446
- # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ ์นด๋“œ ์ƒ์„ฑ
447
- for model_id in target_models:
448
- if model_id not in [m['id'] for m in filtered_models]:
449
- html_content += f"""
450
- <div style='
451
- background: #f8f9fa;
452
- padding: 20px;
453
- border-radius: 10px;
454
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
455
- '>
456
- <h3 style='color: #34495e;'>{model_id}</h3>
457
- <p style='color: #7f8c8d;'>Not in top 3000 by downloads</p>
458
- <a href='{target_models[model_id]}'
459
- target='_blank'
460
- style='
461
- display: inline-block;
462
- padding: 8px 16px;
463
- background: #95a5a6;
464
- color: white;
465
- text-decoration: none;
466
- border-radius: 5px;
467
- '>
468
- Visit Model ๐Ÿ”—
469
- </a>
470
- </div>
471
- """
472
-
473
  html_content += "</div></div>"
474
 
475
  # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
476
  df_data = []
477
- # ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ
478
  for model in filtered_models:
479
  df_data.append({
480
  'Global Rank': model['rank'],
481
  'Model ID': model['id'],
482
  'Title': model.get('title', 'No Title'),
483
- 'Likes': f"{model['likes']:,}",
484
- 'Downloads': f"{model['downloads']:,}",
485
  'URL': target_models[model['id']]
486
  })
487
- # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ
488
- for model_id in target_models:
489
- if model_id not in [m['id'] for m in filtered_models]:
490
- df_data.append({
491
- 'Global Rank': 'Not in top 3000',
492
- 'Model ID': model_id,
493
- 'Title': 'N/A',
494
- 'Likes': 'N/A',
495
- 'Downloads': 'N/A',
496
- 'URL': target_models[model_id]
497
- })
498
 
499
  df = pd.DataFrame(df_data)
500
 
@@ -540,6 +534,7 @@ target_spaces = {
540
  "upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard",
541
  "LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo",
542
 
 
543
  "kolaslab/RC4-EnDecoder": "https://huggingface.co/spaces/kolaslab/RC4-EnDecoder",
544
  "kolaslab/simulator": "https://huggingface.co/spaces/kolaslab/simulator",
545
  "kolaslab/calculator": "https://huggingface.co/spaces/kolaslab/calculator",
@@ -553,14 +548,16 @@ target_spaces = {
553
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
554
  """์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (trending ๋˜๋Š” modes)"""
555
  url = "https://huggingface.co/api/spaces"
 
 
 
 
 
 
 
556
 
557
  try:
558
  progress(0, desc=f"Fetching {sort_type} spaces data...")
559
- params = {
560
- 'full': 'true',
561
- 'limit': 300
562
- }
563
-
564
  response = requests.get(url, params=params)
565
  response.raise_for_status()
566
  all_spaces = response.json()
@@ -570,13 +567,11 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
570
  for idx, space in enumerate(all_spaces, 1):
571
  space_id = space.get('id', '')
572
  if space_id in target_spaces:
573
- # ์ „์ฒด space ์ •๋ณด ์ €์žฅ
574
  space['rank'] = idx
575
  space_ranks[space_id] = space
576
 
577
- # target_spaces ์ค‘ ์ˆœ์œ„๊ถŒ ๋‚ด space ํ•„ํ„ฐ๋ง
578
  spaces = [space_ranks[space_id] for space_id in space_ranks.keys()]
579
- spaces.sort(key=lambda x: x['rank']) # ์ˆœ์œ„๋ณ„๋กœ ์ •๋ ฌ
580
 
581
  progress(0.3, desc="Creating visualization...")
582
 
@@ -587,7 +582,7 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
587
  ids = [space['id'] for space in spaces]
588
  ranks = [space['rank'] for space in spaces]
589
  likes = [space.get('likes', 0) for space in spaces]
590
- titles = [space.get('title', 'No Title') for space in spaces]
591
 
592
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
593
  y_values = [301 - r for r in ranks]
@@ -636,18 +631,10 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
636
  for space in spaces:
637
  space_id = space['id']
638
  rank = space['rank']
639
- title = space.get('title', 'No Title')
640
  likes = space.get('likes', 0)
641
- description = space.get('description', '')
642
-
643
- # cardData์—์„œ ์ถ”๊ฐ€ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
644
- card_data = space.get('cardData', {})
645
- if not description and card_data:
646
- description = card_data.get('description', 'No Description')
647
-
648
- # description์ด ๋„ˆ๋ฌด ๊ธธ๋ฉด ์ž๋ฅด๊ธฐ
649
- short_description = description[:150] + '...' if description and len(description) > 150 else description
650
-
651
  html_content += f"""
652
  <div style='
653
  background: white;
@@ -657,9 +644,18 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
657
  transition: transform 0.2s;
658
  '>
659
  <h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
660
- <h4 style='color: #2c3e50; margin: 10px 0; font-size: 1.1em;'>{title}</h4>
 
 
 
 
 
 
 
 
 
 
661
  <p style='color: #7f8c8d; margin-bottom: 10px;'>๐Ÿ‘ Likes: {likes}</p>
662
- <p style='color: #7f8c8d; font-size: 0.9em; margin-bottom: 15px; line-height: 1.4;'>{short_description}</p>
663
  <a href='{target_spaces[space_id]}'
664
  target='_blank'
665
  style='
@@ -675,6 +671,8 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
675
  </a>
676
  </div>
677
  """
 
 
678
 
679
  html_content += "</div></div>"
680
 
@@ -682,8 +680,7 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
682
  df = pd.DataFrame([{
683
  'Rank': space['rank'],
684
  'Space ID': space['id'],
685
- 'Title': space.get('title', 'No Title'),
686
- 'Description': (space.get('description', '') or space.get('cardData', {}).get('description', 'No Description'))[:100] + '...',
687
  'Likes': space.get('likes', 0),
688
  'URL': target_spaces[space['id']]
689
  } for space in spaces])
 
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
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
298
  def normalize_model_id(model_id):
 
306
  params = {
307
  'full': 'true',
308
  'limit': 3000, # 3000๊ฐœ๋กœ ์ฆ๊ฐ€
309
+ 'sort': 'downloads',
310
  'direction': -1
311
  }
312
 
 
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,
 
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()
 
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(
 
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
  ),
 
443
  for model in filtered_models:
444
  model_id = model['id']
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"""
 
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
 
 
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",
 
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...")
 
 
 
 
 
561
  response = requests.get(url, params=params)
562
  response.raise_for_status()
563
  all_spaces = response.json()
 
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...")
577
 
 
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]
 
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
 
 
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])