openfree commited on
Commit
b88f94c
ยท
verified ยท
1 Parent(s): 46f93ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -45
app.py CHANGED
@@ -543,54 +543,31 @@ target_spaces = {
543
 
544
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
545
  """์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (trending ๋˜๋Š” modes)"""
546
- url = f"https://huggingface.co/api/spaces"
547
- params = {
548
- 'full': 'true',
549
- 'limit': 300
550
- }
551
 
552
  try:
553
  progress(0, desc=f"Fetching {sort_type} spaces data...")
 
 
 
 
 
554
  response = requests.get(url, params=params)
555
- if response.status_code != 200:
556
- print(f"API ์š”์ฒญ ์‹คํŒจ: {response.status_code}")
557
- print(f"Response: {response.text}")
558
- return create_error_plot(), "<div>์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
559
-
560
  all_spaces = response.json()
561
 
562
- # API ์‘๋‹ต ๊ตฌ์กฐ ํ™•์ธ์„ ์œ„ํ•œ ๋กœ๊น…
563
- print("Sample space data:", all_spaces[0] if all_spaces else "No data")
564
-
565
  # ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
566
  space_ranks = {}
567
- space_details = {}
568
-
569
  for idx, space in enumerate(all_spaces, 1):
570
  space_id = space.get('id', '')
571
- space_ranks[space_id] = idx
572
- space_details[space_id] = {
573
- 'title': space.get('title', 'No Title'),
574
- 'cardData': space.get('cardData', {}),
575
- 'likes': space.get('likes', 0),
576
- 'description': space.get('description', 'No Description')
577
- }
578
 
579
- # target_spaces ํ•„ํ„ฐ๋ง ๋ฐ ์ˆœ์œ„ ์ •๋ณด ํฌํ•จ
580
- spaces = []
581
- for space_id in target_spaces.keys():
582
- if space_id in space_ranks:
583
- space_info = {
584
- 'id': space_id,
585
- 'rank': space_ranks[space_id],
586
- 'title': space_details[space_id]['title'],
587
- 'description': space_details[space_id]['description'],
588
- 'likes': space_details[space_id]['likes']
589
- }
590
- spaces.append(space_info)
591
-
592
- # ์ˆœ์œ„๋ณ„๋กœ ์ •๋ ฌ
593
- spaces.sort(key=lambda x: x['rank'])
594
 
595
  progress(0.3, desc="Creating visualization...")
596
 
@@ -600,8 +577,8 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
600
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
601
  ids = [space['id'] for space in spaces]
602
  ranks = [space['rank'] for space in spaces]
603
- likes = [space['likes'] for space in spaces]
604
- titles = [space['title'] for space in spaces]
605
 
606
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
607
  y_values = [301 - r for r in ranks]
@@ -650,9 +627,14 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
650
  for space in spaces:
651
  space_id = space['id']
652
  rank = space['rank']
653
- title = space['title']
654
- description = space['description']
655
- likes = space['likes']
 
 
 
 
 
656
 
657
  # description์ด ๋„ˆ๋ฌด ๊ธธ๋ฉด ์ž๋ฅด๊ธฐ
658
  short_description = description[:150] + '...' if description and len(description) > 150 else description
@@ -691,9 +673,9 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
691
  df = pd.DataFrame([{
692
  'Rank': space['rank'],
693
  'Space ID': space['id'],
694
- 'Title': space['title'],
695
- 'Description': space['description'][:100] + '...' if space['description'] else 'No Description',
696
- 'Likes': space['likes'],
697
  'URL': target_spaces[space['id']]
698
  } for space in spaces])
699
 
 
543
 
544
  def get_spaces_data(sort_type="trending", progress=gr.Progress()):
545
  """์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (trending ๋˜๋Š” modes)"""
546
+ url = "https://huggingface.co/api/spaces"
 
 
 
 
547
 
548
  try:
549
  progress(0, desc=f"Fetching {sort_type} spaces data...")
550
+ params = {
551
+ 'full': 'true',
552
+ 'limit': 300
553
+ }
554
+
555
  response = requests.get(url, params=params)
556
+ response.raise_for_status()
 
 
 
 
557
  all_spaces = response.json()
558
 
 
 
 
559
  # ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
560
  space_ranks = {}
 
 
561
  for idx, space in enumerate(all_spaces, 1):
562
  space_id = space.get('id', '')
563
+ if space_id in target_spaces:
564
+ # ์ „์ฒด space ์ •๋ณด ์ €์žฅ
565
+ space['rank'] = idx
566
+ space_ranks[space_id] = space
 
 
 
567
 
568
+ # target_spaces ์ค‘ ์ˆœ์œ„๊ถŒ ๋‚ด space ํ•„ํ„ฐ๋ง
569
+ spaces = [space_ranks[space_id] for space_id in space_ranks.keys()]
570
+ spaces.sort(key=lambda x: x['rank']) # ์ˆœ์œ„๋ณ„๋กœ ์ •๋ ฌ
 
 
 
 
 
 
 
 
 
 
 
 
571
 
572
  progress(0.3, desc="Creating visualization...")
573
 
 
577
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
578
  ids = [space['id'] for space in spaces]
579
  ranks = [space['rank'] for space in spaces]
580
+ likes = [space.get('likes', 0) for space in spaces]
581
+ titles = [space.get('title', 'No Title') for space in spaces]
582
 
583
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
584
  y_values = [301 - r for r in ranks]
 
627
  for space in spaces:
628
  space_id = space['id']
629
  rank = space['rank']
630
+ title = space.get('title', 'No Title')
631
+ likes = space.get('likes', 0)
632
+ description = space.get('description', '')
633
+
634
+ # cardData์—์„œ ์ถ”๊ฐ€ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
635
+ card_data = space.get('cardData', {})
636
+ if not description and card_data:
637
+ description = card_data.get('description', 'No Description')
638
 
639
  # description์ด ๋„ˆ๋ฌด ๊ธธ๋ฉด ์ž๋ฅด๊ธฐ
640
  short_description = description[:150] + '...' if description and len(description) > 150 else description
 
673
  df = pd.DataFrame([{
674
  'Rank': space['rank'],
675
  'Space ID': space['id'],
676
+ 'Title': space.get('title', 'No Title'),
677
+ 'Description': (space.get('description', '') or space.get('cardData', {}).get('description', 'No Description'))[:100] + '...',
678
+ 'Likes': space.get('likes', 0),
679
  'URL': target_spaces[space['id']]
680
  } for space in spaces])
681