Update app.py
Browse files
app.py
CHANGED
@@ -549,24 +549,45 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
549 |
'limit': 300
|
550 |
}
|
551 |
|
552 |
-
if sort_type == "modes":
|
553 |
-
params['sort'] = 'likes'
|
554 |
-
|
555 |
try:
|
556 |
progress(0, desc=f"Fetching {sort_type} spaces data...")
|
557 |
response = requests.get(url, params=params)
|
558 |
-
response.
|
|
|
|
|
|
|
|
|
559 |
all_spaces = response.json()
|
560 |
|
|
|
|
|
|
|
561 |
# ์์ ์ ๋ณด ์ ์ฅ
|
562 |
-
space_ranks = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
|
564 |
# target_spaces ํํฐ๋ง ๋ฐ ์์ ์ ๋ณด ํฌํจ
|
565 |
spaces = []
|
566 |
-
for
|
567 |
-
if
|
568 |
-
|
569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
|
571 |
# ์์๋ณ๋ก ์ ๋ ฌ
|
572 |
spaces.sort(key=lambda x: x['rank'])
|
@@ -579,8 +600,8 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
579 |
# ๋ฐ์ดํฐ ์ค๋น
|
580 |
ids = [space['id'] for space in spaces]
|
581 |
ranks = [space['rank'] for space in spaces]
|
582 |
-
likes = [space
|
583 |
-
titles = [space
|
584 |
|
585 |
# Y์ถ ๊ฐ์ ๋ฐ์
|
586 |
y_values = [301 - r for r in ranks]
|
@@ -627,11 +648,11 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
627 |
"""
|
628 |
|
629 |
for space in spaces:
|
630 |
-
space_id = space
|
631 |
-
rank = space
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
|
636 |
# description์ด ๋๋ฌด ๊ธธ๋ฉด ์๋ฅด๊ธฐ
|
637 |
short_description = description[:150] + '...' if description and len(description) > 150 else description
|
@@ -645,9 +666,9 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
645 |
transition: transform 0.2s;
|
646 |
'>
|
647 |
<h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
|
648 |
-
<h4 style='color: #2c3e50; margin: 10px 0;'>{title}</h4>
|
649 |
<p style='color: #7f8c8d; margin-bottom: 10px;'>๐ Likes: {likes}</p>
|
650 |
-
<p style='color: #7f8c8d; font-size: 0.9em; margin-bottom: 15px;'>{short_description}</p>
|
651 |
<a href='{target_spaces[space_id]}'
|
652 |
target='_blank'
|
653 |
style='
|
@@ -668,25 +689,24 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
668 |
|
669 |
# ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
670 |
df = pd.DataFrame([{
|
671 |
-
'Rank': space
|
672 |
-
'Space ID': space
|
673 |
-
'Title': space
|
674 |
-
'Description': space
|
675 |
-
'Likes': space
|
676 |
-
'URL': target_spaces[space
|
677 |
} for space in spaces])
|
678 |
|
679 |
progress(1.0, desc="Complete!")
|
680 |
return fig, html_content, df
|
681 |
|
682 |
except Exception as e:
|
|
|
683 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
684 |
error_plot = create_error_plot()
|
685 |
return error_plot, error_html, pd.DataFrame()
|
686 |
|
687 |
|
688 |
-
|
689 |
-
|
690 |
def create_trend_visualization(spaces_data):
|
691 |
if not spaces_data:
|
692 |
return create_error_plot()
|
|
|
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'])
|
|
|
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]
|
|
|
648 |
"""
|
649 |
|
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
|
|
|
666 |
transition: transform 0.2s;
|
667 |
'>
|
668 |
<h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
|
669 |
+
<h4 style='color: #2c3e50; margin: 10px 0; font-size: 1.1em;'>{title}</h4>
|
670 |
<p style='color: #7f8c8d; margin-bottom: 10px;'>๐ Likes: {likes}</p>
|
671 |
+
<p style='color: #7f8c8d; font-size: 0.9em; margin-bottom: 15px; line-height: 1.4;'>{short_description}</p>
|
672 |
<a href='{target_spaces[space_id]}'
|
673 |
target='_blank'
|
674 |
style='
|
|
|
689 |
|
690 |
# ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
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 |
|
700 |
progress(1.0, desc="Complete!")
|
701 |
return fig, html_content, df
|
702 |
|
703 |
except Exception as e:
|
704 |
+
print(f"Error in get_spaces_data: {str(e)}")
|
705 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
706 |
error_plot = create_error_plot()
|
707 |
return error_plot, error_html, pd.DataFrame()
|
708 |
|
709 |
|
|
|
|
|
710 |
def create_trend_visualization(spaces_data):
|
711 |
if not spaces_data:
|
712 |
return create_error_plot()
|