openfree commited on
Commit
41bc46b
·
verified ·
1 Parent(s): 12c0512

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -553,14 +553,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 +572,12 @@ 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 +588,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,14 +637,9 @@ 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
@@ -682,8 +678,8 @@ 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])
 
553
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
554
  """스페이스 데이터 가져오기 (trending 또는 modes)"""
555
  url = "https://huggingface.co/api/spaces"
556
+ params = {
557
+ 'full': 'true',
558
+ 'limit': 300
559
+ }
560
+
561
+ if sort_type == "modes":
562
+ params['sort'] = 'likes'
563
 
564
  try:
565
  progress(0, desc=f"Fetching {sort_type} spaces data...")
 
 
 
 
 
566
  response = requests.get(url, params=params)
567
  response.raise_for_status()
568
  all_spaces = response.json()
 
572
  for idx, space in enumerate(all_spaces, 1):
573
  space_id = space.get('id', '')
574
  if space_id in target_spaces:
 
575
  space['rank'] = idx
576
  space_ranks[space_id] = space
577
 
578
  # target_spaces 중 순위권 내 space 필터링
579
  spaces = [space_ranks[space_id] for space_id in space_ranks.keys()]
580
+ spaces.sort(key=lambda x: x['rank'])
581
 
582
  progress(0.3, desc="Creating visualization...")
583
 
 
588
  ids = [space['id'] for space in spaces]
589
  ranks = [space['rank'] for space in spaces]
590
  likes = [space.get('likes', 0) for space in spaces]
591
+ titles = [space.get('cardData', {}).get('title') or space.get('title', 'No Title') for space in spaces]
592
 
593
  # Y축 값을 반전
594
  y_values = [301 - r for r in ranks]
 
637
  for space in spaces:
638
  space_id = space['id']
639
  rank = space['rank']
640
+ title = space.get('cardData', {}).get('title') or space.get('title', 'No Title')
641
+ description = space.get('cardData', {}).get('description') or space.get('description', 'No Description')
642
  likes = space.get('likes', 0)
 
 
 
 
 
 
643
 
644
  # description이 너무 길면 자르기
645
  short_description = description[:150] + '...' if description and len(description) > 150 else description
 
678
  df = pd.DataFrame([{
679
  'Rank': space['rank'],
680
  'Space ID': space['id'],
681
+ 'Title': space.get('cardData', {}).get('title') or space.get('title', 'No Title'),
682
+ 'Description': (space.get('cardData', {}).get('description') or space.get('description', 'No Description'))[:100] + '...',
683
  'Likes': space.get('likes', 0),
684
  'URL': target_spaces[space['id']]
685
  } for space in spaces])