redump final model, edit html and css for gradio
Browse files- Model Building.ipynb +4 -4
- app.py +27 -10
- final_model.pkl +1 -1
- requirements.txt +2 -1
Model Building.ipynb
CHANGED
|
@@ -5212,7 +5212,7 @@
|
|
| 5212 |
},
|
| 5213 |
{
|
| 5214 |
"cell_type": "code",
|
| 5215 |
-
"execution_count":
|
| 5216 |
"id": "a2e122ed",
|
| 5217 |
"metadata": {},
|
| 5218 |
"outputs": [
|
|
@@ -6316,7 +6316,7 @@
|
|
| 6316 |
},
|
| 6317 |
{
|
| 6318 |
"cell_type": "code",
|
| 6319 |
-
"execution_count":
|
| 6320 |
"id": "addeaf5e",
|
| 6321 |
"metadata": {},
|
| 6322 |
"outputs": [
|
|
@@ -6699,7 +6699,7 @@
|
|
| 6699 |
},
|
| 6700 |
{
|
| 6701 |
"cell_type": "code",
|
| 6702 |
-
"execution_count":
|
| 6703 |
"id": "b88f2d45",
|
| 6704 |
"metadata": {},
|
| 6705 |
"outputs": [
|
|
@@ -6709,7 +6709,7 @@
|
|
| 6709 |
"['final_model.pkl']"
|
| 6710 |
]
|
| 6711 |
},
|
| 6712 |
-
"execution_count":
|
| 6713 |
"metadata": {},
|
| 6714 |
"output_type": "execute_result"
|
| 6715 |
}
|
|
|
|
| 5212 |
},
|
| 5213 |
{
|
| 5214 |
"cell_type": "code",
|
| 5215 |
+
"execution_count": 19,
|
| 5216 |
"id": "a2e122ed",
|
| 5217 |
"metadata": {},
|
| 5218 |
"outputs": [
|
|
|
|
| 6316 |
},
|
| 6317 |
{
|
| 6318 |
"cell_type": "code",
|
| 6319 |
+
"execution_count": 20,
|
| 6320 |
"id": "addeaf5e",
|
| 6321 |
"metadata": {},
|
| 6322 |
"outputs": [
|
|
|
|
| 6699 |
},
|
| 6700 |
{
|
| 6701 |
"cell_type": "code",
|
| 6702 |
+
"execution_count": 21,
|
| 6703 |
"id": "b88f2d45",
|
| 6704 |
"metadata": {},
|
| 6705 |
"outputs": [
|
|
|
|
| 6709 |
"['final_model.pkl']"
|
| 6710 |
]
|
| 6711 |
},
|
| 6712 |
+
"execution_count": 21,
|
| 6713 |
"metadata": {},
|
| 6714 |
"output_type": "execute_result"
|
| 6715 |
}
|
app.py
CHANGED
|
@@ -4,14 +4,15 @@ import joblib
|
|
| 4 |
import os
|
| 5 |
import spotipy
|
| 6 |
import pylast
|
|
|
|
| 7 |
from spotipy.oauth2 import SpotifyClientCredentials
|
| 8 |
from Levenshtein import distance
|
| 9 |
|
| 10 |
final_model = joblib.load('final_model.pkl')
|
| 11 |
-
print(final_model)
|
| 12 |
# Set up authentication with the Spotify API
|
| 13 |
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=os.environ['SPOT_API'], client_secret=os.environ['SPOT_SECRET']))
|
| 14 |
network = pylast.LastFMNetwork(api_key=os.environ['LAST_API'], api_secret=os.environ['LAST_SECRET'])
|
|
|
|
| 15 |
genre_list = ['acoustic', 'afrobeat', 'alt-rock', 'alternative', 'ambient',
|
| 16 |
'anime', 'black-metal', 'bluegrass', 'blues', 'brazil',
|
| 17 |
'breakbeat', 'british', 'cantopop', 'chicago-house', 'children',
|
|
@@ -39,19 +40,31 @@ genre_list = ['acoustic', 'afrobeat', 'alt-rock', 'alternative', 'ambient',
|
|
| 39 |
|
| 40 |
def get_track_genre(track_id,artist_name,track_name):
|
| 41 |
genres = []
|
| 42 |
-
|
| 43 |
-
artist = sp.artist(
|
| 44 |
-
|
| 45 |
-
album_id = track['album']['id']
|
| 46 |
-
|
| 47 |
album = sp.album(album_id)
|
| 48 |
genres.extend(album['genres'])
|
| 49 |
genres.extend(artist['genres'])
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
tags_list = [tag.item.get_name() for tag in top_tags]
|
| 53 |
genres.extend(tags_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
print(genres)
|
|
|
|
| 55 |
return genres
|
| 56 |
|
| 57 |
def find_most_similar_genre(my_genres, artist_genres):
|
|
@@ -115,7 +128,11 @@ theme = gr.themes.Monochrome(
|
|
| 115 |
# text_size="text_lg",
|
| 116 |
font=[gr.themes.GoogleFont('Neucha'), 'ui-sans-serif', 'system-ui', 'sans-serif'],
|
| 117 |
)
|
| 118 |
-
with gr.Blocks(theme=theme)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
with gr.Row():
|
| 120 |
image = gr.HTML("<div style='display: flex; align-items: center;'><img src='file=images/cat-jam.gif' alt='My gif' width='200' height='200'>" +
|
| 121 |
"<div><h1 style='font-size: 60px; line-height: 24px; margin-left: 50px;'>Music Popularity Prediction</h1>" +
|
|
@@ -156,7 +173,6 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 156 |
search_box.change(fn=update_dropdown, inputs=[search_box,track_ids_var], outputs=[song_dropdown,track_ids_var])
|
| 157 |
|
| 158 |
def update_features(song,track_ids):
|
| 159 |
-
print(song)
|
| 160 |
features = get_song_features(song, track_ids)
|
| 161 |
return features
|
| 162 |
|
|
@@ -190,6 +206,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 190 |
|
| 191 |
df = pd.DataFrame(data)
|
| 192 |
print(df)
|
|
|
|
| 193 |
# Use your trained model to predict popularity based on the input features
|
| 194 |
if(final_model.predict(df)[0] == 1):
|
| 195 |
return ("<div style='display: flex; align-items: center;'><img src='file=images/pepe-jam.gif' alt='My gif 3' width='200' height='200'>" +
|
|
|
|
| 4 |
import os
|
| 5 |
import spotipy
|
| 6 |
import pylast
|
| 7 |
+
import discogs_client
|
| 8 |
from spotipy.oauth2 import SpotifyClientCredentials
|
| 9 |
from Levenshtein import distance
|
| 10 |
|
| 11 |
final_model = joblib.load('final_model.pkl')
|
|
|
|
| 12 |
# Set up authentication with the Spotify API
|
| 13 |
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=os.environ['SPOT_API'], client_secret=os.environ['SPOT_SECRET']))
|
| 14 |
network = pylast.LastFMNetwork(api_key=os.environ['LAST_API'], api_secret=os.environ['LAST_SECRET'])
|
| 15 |
+
d = discogs_client.Client('app/0.1', user_token=os.environ['DIS_TOKEN'])
|
| 16 |
genre_list = ['acoustic', 'afrobeat', 'alt-rock', 'alternative', 'ambient',
|
| 17 |
'anime', 'black-metal', 'bluegrass', 'blues', 'brazil',
|
| 18 |
'breakbeat', 'british', 'cantopop', 'chicago-house', 'children',
|
|
|
|
| 40 |
|
| 41 |
def get_track_genre(track_id,artist_name,track_name):
|
| 42 |
genres = []
|
| 43 |
+
track_spot = sp.track(track_id)
|
| 44 |
+
artist = sp.artist(track_spot['artists'][0]['external_urls']['spotify'])
|
| 45 |
+
album_id = track_spot['album']['id']
|
|
|
|
|
|
|
| 46 |
album = sp.album(album_id)
|
| 47 |
genres.extend(album['genres'])
|
| 48 |
genres.extend(artist['genres'])
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
track_last = network.get_track(artist_name, track_name)
|
| 52 |
+
top_tags = track_last.get_top_tags(limit =5)
|
| 53 |
tags_list = [tag.item.get_name() for tag in top_tags]
|
| 54 |
genres.extend(tags_list)
|
| 55 |
+
|
| 56 |
+
# results = d.search(track_name, artist=artist_name, type='release')
|
| 57 |
+
# if results:
|
| 58 |
+
# release = results[0]
|
| 59 |
+
# if release.genres:
|
| 60 |
+
# genres.extend(release.genres)
|
| 61 |
+
# if release.styles:
|
| 62 |
+
# genres.extend(release.styles)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
print(genres)
|
| 67 |
+
|
| 68 |
return genres
|
| 69 |
|
| 70 |
def find_most_similar_genre(my_genres, artist_genres):
|
|
|
|
| 128 |
# text_size="text_lg",
|
| 129 |
font=[gr.themes.GoogleFont('Neucha'), 'ui-sans-serif', 'system-ui', 'sans-serif'],
|
| 130 |
)
|
| 131 |
+
with gr.Blocks(theme=theme,css = "@media (max-width: 600px) {" +
|
| 132 |
+
".gradio-container { flex-direction: column;}" +
|
| 133 |
+
".gradio-container h1 {font-size: 30px !important ;margin-left: 20px !important; line-height: 30px !important}" +
|
| 134 |
+
".gradio-container h2 {font-size: 15px !important;margin-left: 20px !important;margin-top: 20px !important;}"+
|
| 135 |
+
".gradio-container img{width : 100px; height : 100px}}") as demo:
|
| 136 |
with gr.Row():
|
| 137 |
image = gr.HTML("<div style='display: flex; align-items: center;'><img src='file=images/cat-jam.gif' alt='My gif' width='200' height='200'>" +
|
| 138 |
"<div><h1 style='font-size: 60px; line-height: 24px; margin-left: 50px;'>Music Popularity Prediction</h1>" +
|
|
|
|
| 173 |
search_box.change(fn=update_dropdown, inputs=[search_box,track_ids_var], outputs=[song_dropdown,track_ids_var])
|
| 174 |
|
| 175 |
def update_features(song,track_ids):
|
|
|
|
| 176 |
features = get_song_features(song, track_ids)
|
| 177 |
return features
|
| 178 |
|
|
|
|
| 206 |
|
| 207 |
df = pd.DataFrame(data)
|
| 208 |
print(df)
|
| 209 |
+
print(final_model.predict(df))
|
| 210 |
# Use your trained model to predict popularity based on the input features
|
| 211 |
if(final_model.predict(df)[0] == 1):
|
| 212 |
return ("<div style='display: flex; align-items: center;'><img src='file=images/pepe-jam.gif' alt='My gif 3' width='200' height='200'>" +
|
final_model.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 8825585
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8f8f0c12979cb682a77639be924d8e358bf1a936121bcbdf86da5c5f19570e7d
|
| 3 |
size 8825585
|
requirements.txt
CHANGED
|
@@ -7,4 +7,5 @@ category_encoders
|
|
| 7 |
catboost
|
| 8 |
scikit-learn
|
| 9 |
pylast
|
| 10 |
-
pandas < 2.0.0
|
|
|
|
|
|
| 7 |
catboost
|
| 8 |
scikit-learn
|
| 9 |
pylast
|
| 10 |
+
pandas < 2.0.0
|
| 11 |
+
python3-discogs-client
|