atepper commited on
Commit
f2a6772
·
1 Parent(s): 18f6182

forget spotify!!!

Browse files
Files changed (1) hide show
  1. app.py +53 -51
app.py CHANGED
@@ -1,67 +1,69 @@
1
  import streamlit as st
2
  import spotipy
3
  from streamlit_oauth import OAuth2Component
4
- # from diffusers import StableDiffusionPipeline
5
- # from transformers import AutoTokenizer, AutoModelForCausalLM
6
  # import torch
7
 
8
- AUTHORIZE_URL = 'https://accounts.spotify.com/authorize'
9
- TOKEN_URL = 'https://accounts.spotify.com/api/token'
10
- REFRESH_TOKEN_URL = TOKEN_URL
11
- REVOKE_TOKEN_URL = TOKEN_URL
12
- CLIENT_ID = st.secrets["SPOTIFY_CLIENT_ID"]
13
- CLIENT_SECRET = st.secrets["SPOTIFY_CLIENT_SECRET"]
14
- REDIRECT_URI = 'https://huggingface.co/spaces/atepper/tracklist-analysis/component/streamlit_oauth.authorize_button/index.html'
15
- # REDIRECT_URI= 'http://localhost:8501/component/streamlit_oauth.authorize_button/index.html'
16
- SCOPE = st.secrets["SPOTIFY_SCOPE"]
17
 
18
- oauth2 = OAuth2Component(CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL, REFRESH_TOKEN_URL, REVOKE_TOKEN_URL)
19
 
20
- if 'token' not in st.session_state:
21
- result = oauth2.authorize_button("Login with Spotify", REDIRECT_URI, SCOPE)
22
- if result and 'token' in result:
23
- # If authorization successful, save token in session state
24
- st.session_state.token = result.get('token')
25
- st.rerun()
26
- else:
27
- # If token exists in session state, show the token
28
- token = st.session_state['token']
29
- st.json(token)
30
- if st.button("Refresh Token"):
31
- # If refresh token button is clicked, refresh the token
32
- token = oauth2.refresh_token(token)
33
- st.session_state.token = token
34
- st.rerun()
35
 
36
- sp = spotipy.Spotify(token['access_token'])
37
- results = sp.current_user_recently_played(limit=25)
38
 
39
- entries = []
40
- for idx, item in enumerate(results['items']):
41
- track = item['track']
42
- st.write(f"{idx+1}. {track['name']} by {', '.join([artist['name'] for artist in track['artists']])}")
43
- track = item['track']
44
- artist = ', '.join([artist['name'] for artist in track['artists']])
45
- entry = f"{track['name']} by {artist}"
46
- entries.append(entry)
47
 
48
- prompt = f"Generate 6 adjectives that describe the color, physical texture, taste, smell, vibe, and style of the sum of the following songs: {', '.join(entries)}. Return only the six adjectives in this form: [\"color\", \"physical texture\", \"taste\", \"smell\", \"vibe\", \"style\"]"
49
- st.write('Prompt: ' + prompt)
50
 
51
- # tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
52
- # model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it")
53
 
54
- # input_ids = tokenizer(prompt, return_tensors="pt")
 
55
 
56
- # outputs = model.generate(**input_ids)
57
- # st.write(tokenizer.decode(outputs[0]))
58
 
59
- # model_id = "runwayml/stable-diffusion-v1-5"
60
- # pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
61
- # pipe = pipe.to("cuda")
62
 
63
- # image = pipe(prompt).images[0]
64
-
65
- # image.save("generated.png")
66
 
67
- # st.image("generated.png", caption=f"\"{prompt}\"", use_column_width=True)
 
 
 
 
 
1
  import streamlit as st
2
  import spotipy
3
  from streamlit_oauth import OAuth2Component
4
+ from diffusers import StableDiffusionPipeline
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM
6
  # import torch
7
 
8
+ # AUTHORIZE_URL = 'https://accounts.spotify.com/authorize'
9
+ # TOKEN_URL = 'https://accounts.spotify.com/api/token'
10
+ # REFRESH_TOKEN_URL = TOKEN_URL
11
+ # REVOKE_TOKEN_URL = TOKEN_URL
12
+ # CLIENT_ID = st.secrets["SPOTIFY_CLIENT_ID"]
13
+ # CLIENT_SECRET = st.secrets["SPOTIFY_CLIENT_SECRET"]
14
+ # REDIRECT_URI = 'https://huggingface.co/spaces/atepper/tracklist-analysis/component/streamlit_oauth.authorize_button/index.html'
15
+ # # REDIRECT_URI= 'http://localhost:8501/component/streamlit_oauth.authorize_button/index.html'
16
+ # SCOPE = st.secrets["SPOTIFY_SCOPE"]
17
 
18
+ # oauth2 = OAuth2Component(CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL, REFRESH_TOKEN_URL, REVOKE_TOKEN_URL)
19
 
20
+ # if 'token' not in st.session_state:
21
+ # result = oauth2.authorize_button("Login with Spotify", REDIRECT_URI, SCOPE)
22
+ # if result and 'token' in result:
23
+ # # If authorization successful, save token in session state
24
+ # st.session_state.token = result.get('token')
25
+ # st.rerun()
26
+ # else:
27
+ # # If token exists in session state, show the token
28
+ # token = st.session_state['token']
29
+ # st.json(token)
30
+ # if st.button("Refresh Token"):
31
+ # # If refresh token button is clicked, refresh the token
32
+ # token = oauth2.refresh_token(token)
33
+ # st.session_state.token = token
34
+ # st.rerun()
35
 
36
+ # sp = spotipy.Spotify(token['access_token'])
37
+ # results = sp.current_user_recently_played(limit=25)
38
 
39
+ # entries = []
40
+ # for idx, item in enumerate(results['items']):
41
+ # track = item['track']
42
+ # st.write(f"{idx+1}. {track['name']} by {', '.join([artist['name'] for artist in track['artists']])}")
43
+ # track = item['track']
44
+ # artist = ', '.join([artist['name'] for artist in track['artists']])
45
+ # entry = f"{track['name']} by {artist}"
46
+ # entries.append(entry)
47
 
48
+ # prompt = f"Generate 6 adjectives that describe the color, physical texture, taste, smell, vibe, and style of the sum of the following songs: {', '.join(entries)}. Return only the six adjectives in this form: [\"color\", \"physical texture\", \"taste\", \"smell\", \"vibe\", \"style\"]"
49
+ # st.write('Prompt: ' + prompt)
50
 
51
+ prompt = "Generate 6 adjectives that describe the color, physical texture, taste, smell, vibe, and specific genre of the sum of the following songs: Rich Folks Hoax by Rodríguez, Gommorah (A Nursery Rhyme) by Rodríguez, Like Janis by Rodríguez, I Wonder by Rodríguez, Inner City Blues by Rodríguez, Forget It by Rodríguez, Hate Street Dialogue by Rodríguez, This Is Not a Song, It's an Outburst: Or, the Establishment Blues by Rodríguez, Crucify Your Mind by Rodríguez, Only Good For Conversation by Rodríguez, Sugar Man by Rodríguez, Juliette by Jackson C. Frank, Saturday Sun by Nick Drake, Fruit Tree by Nick Drake, Man In A Shed by Nick Drake, The Thoughts Of Mary Jane by Nick Drake, ' Cello Song by Nick Drake, Day Is Done by Nick Drake, Way To Blue by Nick Drake, Three Hours by Nick Drake, River Man by Nick Drake, Time Has Told Me by Nick Drake, Sunday by Nick Drake, Northern Sky by Nick Drake, Poor Boy by Nick Drake. Return only the six adjectives in this form: [\"color\", \"physical texture\", \"taste\", \"smell\", \"vibe\", \"specific genre\"]. There should only be one array printed with six adjectives that describe all of the above tracks put together. Return ONLY the array, nothing else."
 
52
 
53
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
54
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it")
55
 
56
+ input_ids = tokenizer(prompt, return_tensors="pt")
 
57
 
58
+ outputs = model.generate(**input_ids)
59
+ st.write(tokenizer.decode(outputs[0]))
 
60
 
61
+ model_id = "runwayml/stable-diffusion-v1-5"
62
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
63
+ pipe = pipe.to("cuda")
64
 
65
+ image = pipe(prompt).images[0]
66
+
67
+ image.save("generated.png")
68
+
69
+ st.image("generated.png", caption=f"\"{prompt}\"", use_column_width=True)