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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -26
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.raise_for_status()
 
 
 
 
559
  all_spaces = response.json()
560
 
 
 
 
561
  # ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
562
- space_ranks = {space['id']: idx + 1 for idx, space in enumerate(all_spaces)}
 
 
 
 
 
 
 
 
 
 
 
563
 
564
  # target_spaces ํ•„ํ„ฐ๋ง ๋ฐ ์ˆœ์œ„ ์ •๋ณด ํฌํ•จ
565
  spaces = []
566
- for space in all_spaces:
567
- if space.get('id', '') in target_spaces:
568
- space['rank'] = space_ranks.get(space['id'], 'N/A')
569
- spaces.append(space)
 
 
 
 
 
 
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.get('likes', 0) for space in spaces]
583
- titles = [space.get('title', 'No Title') for space in spaces]
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.get('id', '')
631
- rank = space.get('rank', 'N/A')
632
- likes = space.get('likes', 0)
633
- title = space.get('title', 'No Title')
634
- description = space.get('description', 'No Description')
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.get('rank', 'N/A'),
672
- 'Space ID': space.get('id', ''),
673
- 'Title': space.get('title', 'N/A'),
674
- 'Description': space.get('description', 'N/A')[:100] + '...',
675
- 'Likes': space.get('likes', 'N/A'),
676
- 'URL': target_spaces[space.get('id', '')]
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()