Update app.py
Browse files
app.py
CHANGED
|
@@ -694,6 +694,78 @@ def get_spaces_data(sort_type="trending", progress=gr.Progress()):
|
|
| 694 |
template='plotly_white',
|
| 695 |
xaxis_tickangle=-45
|
| 696 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
|
| 698 |
|
| 699 |
def create_trend_visualization(spaces_data):
|
|
|
|
| 694 |
template='plotly_white',
|
| 695 |
xaxis_tickangle=-45
|
| 696 |
)
|
| 697 |
+
|
| 698 |
+
progress(0.6, desc="Creating space cards...")
|
| 699 |
+
|
| 700 |
+
# HTML 旃措摐 靸濎劚
|
| 701 |
+
html_content = f"""
|
| 702 |
+
<div style='padding: 20px; background: #f5f5f5;'>
|
| 703 |
+
<h2 style='color: #2c3e50;'>{sort_type.title()} Rankings</h2>
|
| 704 |
+
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
| 705 |
+
"""
|
| 706 |
+
|
| 707 |
+
for space in spaces:
|
| 708 |
+
space_id = space['id']
|
| 709 |
+
rank = space['rank']
|
| 710 |
+
title = space.get('cardData', {}).get('title') or space.get('title', 'No Title')
|
| 711 |
+
likes = space.get('likes', 0)
|
| 712 |
+
|
| 713 |
+
html_content += f"""
|
| 714 |
+
<div style='
|
| 715 |
+
background: white;
|
| 716 |
+
padding: 20px;
|
| 717 |
+
border-radius: 10px;
|
| 718 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 719 |
+
transition: transform 0.2s;
|
| 720 |
+
'>
|
| 721 |
+
<h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
|
| 722 |
+
<h4 style='
|
| 723 |
+
color: #2980b9;
|
| 724 |
+
margin: 10px 0;
|
| 725 |
+
font-size: 1.2em;
|
| 726 |
+
font-weight: bold;
|
| 727 |
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
| 728 |
+
background: linear-gradient(to right, #3498db, #2980b9);
|
| 729 |
+
-webkit-background-clip: text;
|
| 730 |
+
-webkit-text-fill-color: transparent;
|
| 731 |
+
padding: 5px 0;
|
| 732 |
+
'>{title}</h4>
|
| 733 |
+
<p style='color: #7f8c8d; margin-bottom: 10px;'>馃憤 Likes: {likes}</p>
|
| 734 |
+
<a href='{target_spaces[space_id]}'
|
| 735 |
+
target='_blank'
|
| 736 |
+
style='
|
| 737 |
+
display: inline-block;
|
| 738 |
+
padding: 8px 16px;
|
| 739 |
+
background: #3498db;
|
| 740 |
+
color: white;
|
| 741 |
+
text-decoration: none;
|
| 742 |
+
border-radius: 5px;
|
| 743 |
+
transition: background 0.3s;
|
| 744 |
+
'>
|
| 745 |
+
Visit Space 馃敆
|
| 746 |
+
</a>
|
| 747 |
+
</div>
|
| 748 |
+
"""
|
| 749 |
+
|
| 750 |
+
html_content += "</div></div>"
|
| 751 |
+
|
| 752 |
+
# 雿办澊韯绊攧霠堨瀯 靸濎劚
|
| 753 |
+
df = pd.DataFrame([{
|
| 754 |
+
'Rank': space['rank'],
|
| 755 |
+
'Space ID': space['id'],
|
| 756 |
+
'Title': space.get('cardData', {}).get('title') or space.get('title', 'No Title'),
|
| 757 |
+
'Likes': space.get('likes', 0),
|
| 758 |
+
'URL': target_spaces[space['id']]
|
| 759 |
+
} for space in spaces])
|
| 760 |
+
|
| 761 |
+
progress(1.0, desc="Complete!")
|
| 762 |
+
return fig, html_content, df
|
| 763 |
+
|
| 764 |
+
except Exception as e:
|
| 765 |
+
print(f"Error in get_spaces_data: {str(e)}")
|
| 766 |
+
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
| 767 |
+
error_plot = create_error_plot()
|
| 768 |
+
return error_plot, error_html, pd.DataFrame()
|
| 769 |
|
| 770 |
|
| 771 |
def create_trend_visualization(spaces_data):
|