Spaces:
Running
Running
Update app.py
Browse files
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 =
|
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 |
-
|
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 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
'likes': space.get('likes', 0),
|
576 |
-
'description': space.get('description', 'No Description')
|
577 |
-
}
|
578 |
|
579 |
-
# target_spaces
|
580 |
-
spaces = []
|
581 |
-
|
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
|
604 |
-
titles = [space
|
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
|
654 |
-
|
655 |
-
|
|
|
|
|
|
|
|
|
|
|
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
|
695 |
-
'Description': space
|
696 |
-
'Likes': space
|
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 |
|