alanahmet commited on
Commit
3873f09
·
1 Parent(s): 883e5ca

api keys handled

Browse files
Files changed (4) hide show
  1. .cache +1 -1
  2. .gitignore +1 -0
  3. app.py +1 -0
  4. spotify_music_recommender.py +24 -6
.cache CHANGED
@@ -1 +1 @@
1
- {"access_token": "BQBSEwQ66rfKq7t8vvi74QlSVgoyn5fJQe9d4TXx57IIKf30Oqou-jNELI7d2BM6swl4sONrDlcjloHiu8w0RAPovKpEejgUb3w3PSQ8dw_TuoZetVM", "token_type": "Bearer", "expires_in": 3600, "expires_at": 1685714408}
 
1
+ {"access_token": "BQCcgc_4zWsgVUt9b9_r6ka5YkOS0KReZE6pPHKS0ELyM5K3KOfyyUyED87zZORxZbpPAGRxFEpQ8e24eQo6Mleh2xP8tZzVKkqnCDszX68thYCwqbc", "token_type": "Bearer", "expires_in": 3600, "expires_at": 1685645349}
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ secrets.py
app.py CHANGED
@@ -3,6 +3,7 @@ from streamlit_option_menu import option_menu
3
  import streamlit.components.v1 as components
4
  import spotify_music_recommender as smr
5
 
 
6
  if "song_init" not in st.session_state:
7
  st.session_state.song_init = False
8
 
 
3
  import streamlit.components.v1 as components
4
  import spotify_music_recommender as smr
5
 
6
+
7
  if "song_init" not in st.session_state:
8
  st.session_state.song_init = False
9
 
spotify_music_recommender.py CHANGED
@@ -13,6 +13,7 @@ import pandas as pd
13
  import openai
14
  import spotipy
15
  import pickle
 
16
 
17
  from sklearn.cluster import KMeans
18
  from sklearn.preprocessing import StandardScaler
@@ -52,8 +53,14 @@ def get_pipeline_data_number_cols():
52
 
53
 
54
  def find_song(name, year):
55
- sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
56
- client_id="e941ee9577244e08a1741a6b8183b346", client_secret="d5990a6f11e442fe8e897da07b3f6277"))
 
 
 
 
 
 
57
  song_data = defaultdict()
58
  results = sp.search(q='track: {} year: {}'.format(name, year), limit=1)
59
  if results['tracks']['items'] == []:
@@ -77,8 +84,13 @@ def find_song(name, year):
77
 
78
  def find_song_uri(name, year):
79
  # Create a Spotify client object.
80
- client = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
81
- client_id="e941ee9577244e08a1741a6b8183b346", client_secret="d5990a6f11e442fe8e897da07b3f6277"))
 
 
 
 
 
82
  # Get the name of the song you want to get the ID for.
83
  song_name = name
84
  # Call the `search` method with the song name.
@@ -98,7 +110,12 @@ def format_song(song_data, number_cols):
98
 
99
 
100
  def get_response(text):
101
- openai.api_key = "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"
 
 
 
 
 
102
 
103
  response = openai.Completion.create(
104
  model="text-davinci-003",
@@ -228,7 +245,8 @@ def control():
228
  data_path = "data/data.csv"
229
  file_path = "data/pipeline.pkl"
230
  cluster_labels = "data/cluster_labels.csv"
231
- song_cluster_pipeline, data, number_cols = get_model_values(data_path, file_path, cluster_labels)
 
232
 
233
  user_critic_text = "it was dull and very loud"
234
  song_name = "Poem of a Killer"
 
13
  import openai
14
  import spotipy
15
  import pickle
16
+ import os
17
 
18
  from sklearn.cluster import KMeans
19
  from sklearn.preprocessing import StandardScaler
 
53
 
54
 
55
  def find_song(name, year):
56
+ if os.path.isfile("/secrets"):
57
+ import secrets
58
+ sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
59
+ client_id=secrets.client_id, client_secret=secrets.client_secret))
60
+ else:
61
+ sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
62
+ client_id=os.environ.get("client_id"), client_secret=os.environ.get("client_secret")))
63
+
64
  song_data = defaultdict()
65
  results = sp.search(q='track: {} year: {}'.format(name, year), limit=1)
66
  if results['tracks']['items'] == []:
 
84
 
85
  def find_song_uri(name, year):
86
  # Create a Spotify client object.
87
+ if os.path.isfile("/secrets"):
88
+ import secrets
89
+ client = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
90
+ client_id=secrets.client_id, client_secret=secrets.client_secret))
91
+ else:
92
+ client = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
93
+ client_id=os.environ.get("client_id"), client_secret=os.environ.get("client_secret")))
94
  # Get the name of the song you want to get the ID for.
95
  song_name = name
96
  # Call the `search` method with the song name.
 
110
 
111
 
112
  def get_response(text):
113
+
114
+ if os.path.isfile("/secrets"):
115
+ import secrets
116
+ openai.api_key = secrets.openai_api_key
117
+ else:
118
+ openai.api_key = os.environ.get("openai_api_key")
119
 
120
  response = openai.Completion.create(
121
  model="text-davinci-003",
 
245
  data_path = "data/data.csv"
246
  file_path = "data/pipeline.pkl"
247
  cluster_labels = "data/cluster_labels.csv"
248
+ song_cluster_pipeline, data, number_cols = get_model_values(
249
+ data_path, file_path, cluster_labels)
250
 
251
  user_critic_text = "it was dull and very loud"
252
  song_name = "Poem of a Killer"