Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,6 +50,7 @@ def app():
|
|
| 50 |
'redirect_uri': REDIRECT_URI,
|
| 51 |
'scope': 'user-read-private', # Modify as per your required scopes
|
| 52 |
}
|
|
|
|
| 53 |
st.write('Please log in to Spotify')
|
| 54 |
st.markdown(f"[Log In]({AUTH_URL}?{urlencode(auth_params)})", unsafe_allow_html=True)
|
| 55 |
else:#
|
|
@@ -71,18 +72,31 @@ def app():
|
|
| 71 |
if 'access_token' in st.session_state:
|
| 72 |
st.write("Enter a Spotify Track URL or URI to get its audio features.")
|
| 73 |
track_input = st.text_input("Spotify Track URL/URI", "")
|
|
|
|
| 74 |
if st.button("Get Audio Features"):
|
| 75 |
track_id = extract_track_id_from_url(track_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
if track_id:
|
| 77 |
audio_features = get_track_audio_features(track_id, st.session_state['access_token'])
|
| 78 |
features = [None] * 9
|
| 79 |
-
features[0] = audio_features["tempo"]
|
| 80 |
features[1] = audio_features["energy"]
|
| 81 |
features[2] = audio_features["danceability"]
|
| 82 |
-
features[3] = audio_features["loudness"]
|
| 83 |
features[4] = audio_features["liveness"]
|
| 84 |
features[5] = audio_features["valence"]
|
| 85 |
-
features[6] = audio_features["duration_ms"] / 1000
|
| 86 |
features[7] = audio_features["acousticness"]
|
| 87 |
features[8] = audio_features["speechiness"]
|
| 88 |
feature_display = {
|
|
@@ -96,21 +110,24 @@ def app():
|
|
| 96 |
"acousticness":features[7],
|
| 97 |
"speechiness":features[8]
|
| 98 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
st.write(feature_display)
|
| 100 |
-
predictions = predict_popularity(features)
|
| 101 |
st.write(f"Random Forest Prediction: {predictions[0]}")
|
| 102 |
st.write(f"Regression Prediction: {predictions[1]}")
|
| 103 |
|
| 104 |
else:
|
| 105 |
st.error("Please enter a valid Spotify Track URL or URI.")
|
| 106 |
-
|
| 107 |
-
track_info = get_track_information(track_id, st.session_state['access_token'])
|
| 108 |
-
if track_info:
|
| 109 |
-
st.write(f"Popularität: {track_info.get('popularity', 'Nicht verfügbar')}")
|
| 110 |
-
else:
|
| 111 |
-
st.write("Track-Informationen konnten nicht abgerufen werden.")
|
| 112 |
-
else:
|
| 113 |
-
st.write("Bitte geben Sie eine gültige Track-ID ein.")
|
| 114 |
|
| 115 |
if 'code' not in st.session_state:
|
| 116 |
query_params = st.experimental_get_query_params()
|
|
|
|
| 50 |
'redirect_uri': REDIRECT_URI,
|
| 51 |
'scope': 'user-read-private', # Modify as per your required scopes
|
| 52 |
}
|
| 53 |
+
st.code(st.session_state)
|
| 54 |
st.write('Please log in to Spotify')
|
| 55 |
st.markdown(f"[Log In]({AUTH_URL}?{urlencode(auth_params)})", unsafe_allow_html=True)
|
| 56 |
else:#
|
|
|
|
| 72 |
if 'access_token' in st.session_state:
|
| 73 |
st.write("Enter a Spotify Track URL or URI to get its audio features.")
|
| 74 |
track_input = st.text_input("Spotify Track URL/URI", "")
|
| 75 |
+
traindata = []
|
| 76 |
if st.button("Get Audio Features"):
|
| 77 |
track_id = extract_track_id_from_url(track_input)
|
| 78 |
+
if track_id:
|
| 79 |
+
track_info = get_track_information(track_id, st.session_state['access_token'])
|
| 80 |
+
if track_info:
|
| 81 |
+
st.write(f"Popularität: {track_info.get('popularity', 'Nicht verfügbar')}")
|
| 82 |
+
traindata.append("new")
|
| 83 |
+
traindata.append(track_info["name"])
|
| 84 |
+
traindata.append(track_info["artists"][0]["name"])
|
| 85 |
+
traindata.append("No_Genre_Found")
|
| 86 |
+
else:
|
| 87 |
+
st.write("Track-Informationen konnten nicht abgerufen werden.")
|
| 88 |
+
else:
|
| 89 |
+
st.write("Bitte geben Sie eine gültige Track-ID ein.")
|
| 90 |
if track_id:
|
| 91 |
audio_features = get_track_audio_features(track_id, st.session_state['access_token'])
|
| 92 |
features = [None] * 9
|
| 93 |
+
features[0] = audio_features["tempo"] # Beats per minute
|
| 94 |
features[1] = audio_features["energy"]
|
| 95 |
features[2] = audio_features["danceability"]
|
| 96 |
+
features[3] = audio_features["loudness"] # Loudness in dB
|
| 97 |
features[4] = audio_features["liveness"]
|
| 98 |
features[5] = audio_features["valence"]
|
| 99 |
+
features[6] = audio_features["duration_ms"] / 1000 # Umrechnung von Millisekunden in Sekunden
|
| 100 |
features[7] = audio_features["acousticness"]
|
| 101 |
features[8] = audio_features["speechiness"]
|
| 102 |
feature_display = {
|
|
|
|
| 110 |
"acousticness":features[7],
|
| 111 |
"speechiness":features[8]
|
| 112 |
}
|
| 113 |
+
traindata.append(audio_features["tempo"])
|
| 114 |
+
traindata.append(audio_features["energy"])
|
| 115 |
+
traindata.append(audio_features["danceability"])
|
| 116 |
+
traindata.append(audio_features["loudness"])
|
| 117 |
+
traindata.append(audio_features["liveness"])
|
| 118 |
+
traindata.append(audio_features["valence"])
|
| 119 |
+
traindata.append(audio_features["duration_ms"]/ 1000)
|
| 120 |
+
traindata.append(audio_features["acousticness"])
|
| 121 |
+
traindata.append(audio_features["speechiness"])
|
| 122 |
+
traindata.append(track_info["popularity"])
|
| 123 |
st.write(feature_display)
|
| 124 |
+
predictions = predict_popularity(features, traindata)
|
| 125 |
st.write(f"Random Forest Prediction: {predictions[0]}")
|
| 126 |
st.write(f"Regression Prediction: {predictions[1]}")
|
| 127 |
|
| 128 |
else:
|
| 129 |
st.error("Please enter a valid Spotify Track URL or URI.")
|
| 130 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
if 'code' not in st.session_state:
|
| 133 |
query_params = st.experimental_get_query_params()
|