-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent_renderer.py
205 lines (180 loc) · 8.07 KB
/
content_renderer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import streamlit as st
from recommenders.lyrics_similarity_recommenders import lyrics_similarity_based_recommend
from recommenders.musical_similarity_recommenders import musical_feature_similarity_based_recommend
from recommenders.collabrative_recommenders import collabrative_recommend
from recommenders.artists_similarity_recommenders import artists_similarity_based_recommend
from recommenders.als_recommenders import als_similarity_based_recommend
# Set up the Streamlit app
def setup_app():
st.set_page_config(
page_title="SereneSounds",
layout='wide'
)
st.markdown("<H1 class='big-title'>SereneSounds</H1>", unsafe_allow_html=True)
st.markdown("<h3 class='small-subtitle'>A Sophisticated Music Curation Engine</h3>", unsafe_allow_html=True)
# Display dropdown for song selection
def display_song_dropdown_list(music_list):
selected_song = st.selectbox(
"Type or select a song from the dropdown",
music_list
)
return selected_song
# Display Recommendations
def show_recommendations(selected_song):
if st.button('Show Recommendation'):
display_lyrics_similarity_based_recommendations(selected_song)
display_musical_feature_similarity_based_recommendations(selected_song)
display_collabrative_feature_based_recommendations(selected_song)
display_artists_similarity_based_recommendations(selected_song)
display_als_similarity_based_recommendations(selected_song)
# add more same fuctions
# Display recommendations based on lyrics_similarity
def display_lyrics_similarity_based_recommendations(selected_song):
recommendations = lyrics_similarity_based_recommend(selected_song)
st.markdown(
"""
<div style="border: 2px solid #e74c3c; padding: 5px; border-radius: 10px; margin: 5px 0;">
<h3 style="color: #e74c3c;">Lyrical Similarity Based Recommendated Songs</h3>
</div>
""",
unsafe_allow_html=True,
)
# Display recommendations in cards
for i in range(0, len(recommendations), 5):
row = st.columns(5)
for j in range(min(5, len(recommendations) - i)):
with row[j]:
st.write(f"{recommendations[i + j]['name']}")
st.image(recommendations[i + j]['poster'], use_column_width=True)
st.write(f"[Listen on]({recommendations[i + j]['link']})")
# Display recommendations based on musical_feature_similarity
def display_musical_feature_similarity_based_recommendations(selected_song):
recommendations = musical_feature_similarity_based_recommend(selected_song)
st.markdown(
"""
<div style="border: 2px solid #e74c3c; padding: 5px; border-radius: 10px; margin: 5px 0;">
<h3 style="color: #e74c3c;">Musical Feature Similarity Based Recommendated Songs</h3>
</div>
""",
unsafe_allow_html=True,
)
# Display recommendations in cards
for i in range(0, len(recommendations), 5):
row = st.columns(5)
for j in range(min(5, len(recommendations) - i)):
with row[j]:
st.write(f"{recommendations[i + j]['name']}")
st.image(recommendations[i + j]['poster'], use_column_width=True)
st.write(f"[Listen on]({recommendations[i + j]['link']})")
# Display recommendations based on collabrative_feature_similarity
def display_collabrative_feature_based_recommendations(selected_song):
recommendations = collabrative_recommend(selected_song)
st.markdown(
"""
<div style="border: 2px solid #e74c3c; padding: 5px; border-radius: 10px; margin: 5px 0;">
<h3 style="color: #e74c3c;">Collabrative Feature Similarity Based Recommendated Songs</h3>
</div>
""",
unsafe_allow_html=True,
)
# Display recommendations in cards
for i in range(0, len(recommendations), 5):
row = st.columns(5)
for j in range(min(5, len(recommendations) - i)):
with row[j]:
st.write(f"{recommendations[i + j]['name']}")
st.image(recommendations[i + j]['poster'], use_column_width=True)
st.write(f"[Listen on]({recommendations[i + j]['link']})")
# Display recommendations based on artists_similarity
def display_artists_similarity_based_recommendations(selected_song):
recommendations = artists_similarity_based_recommend(selected_song)
st.markdown(
"""
<div style="border: 2px solid #e74c3c; padding: 5px; border-radius: 10px; margin: 5px 0;">
<h3 style="color: #e74c3c;">Artists Similarity Based Recommendated Songs</h3>
</div>
""",
unsafe_allow_html=True,
)
# Display recommendations in cards
for i in range(0, len(recommendations), 5):
row = st.columns(5)
for j in range(min(5, len(recommendations) - i)):
with row[j]:
st.write(f"{recommendations[i + j]['name']}")
st.image(recommendations[i + j]['poster'], use_column_width=True)
st.write(f"[Listen on]({recommendations[i + j]['link']})")
# add more same fuctions
# Display recommendations based on als_similarity
def display_als_similarity_based_recommendations(selected_song):
recommendations = als_similarity_based_recommend(selected_song)
st.markdown(
"""
<div style="border: 2px solid #e74c3c; padding: 5px; border-radius: 10px; margin: 5px 0;">
<h3 style="color: #e74c3c;">Other Recommendated Songs</h3>
</div>
""",
unsafe_allow_html=True,
)
# Display recommendations in cards
for i in range(0, len(recommendations), 5):
row = st.columns(5)
for j in range(min(5, len(recommendations) - i)):
with row[j]:
st.write(f"{recommendations[i + j]['name']}")
st.image(recommendations[i + j]['poster'], use_column_width=True)
st.write(f"[Listen on]({recommendations[i + j]['link']})")
# Apply CSS
def apply_css():
st.markdown(
"""
<style>
.big-title {
font-size: 3.5em;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
font-style: italic;
text-align: center;
}
.small-subtitle {
font-size: 1em;
margin-top: -15px;
font-family: 'Arial', sans-serif;
font-style: italic;
text-align: center;
margin-bottom: 30px;
}
body {
background-color: #f0f2f6;
font-family: 'Arial', sans-serif;
}
.stSelectbox {
width: 100%;
max-width: 1200px;
margin-bottom: 20px;
}
.stButton button, .stTextInput input {{
background-color: #2c6db8 !important;
border-color: #2c6db8 !important;
color: #fff !important;
}}
.stButton:hover button, .stTextInput:hover input {{
background-color: #2c6db8 !important;
border-color: #2c6db8 !important;
color: #fff !important;
}}
.stButton:active button {{
background-color: #ff4d4d !important;
border-color: #ff4d4d !important;
}}
.stText {{
font-size: 18px;
}}
.stImage {{
max-width: 100%;
height: auto;
}}
</style>
""",
unsafe_allow_html=True
)