atepper commited on
Commit
ed3ace1
·
1 Parent(s): bf9a4d2

google gemma integration

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import streamlit as st
2
  import spotipy
3
  from streamlit_oauth import OAuth2Component
4
- from diffusers import StableDiffusionPipeline
 
5
  import torch
6
 
7
  AUTHORIZE_URL = 'https://accounts.spotify.com/authorize'
@@ -10,8 +11,8 @@ REFRESH_TOKEN_URL = TOKEN_URL
10
  REVOKE_TOKEN_URL = TOKEN_URL
11
  CLIENT_ID = st.secrets["SPOTIFY_CLIENT_ID"]
12
  CLIENT_SECRET = st.secrets["SPOTIFY_CLIENT_SECRET"]
13
- REDIRECT_URI = 'https://huggingface.co/spaces/atepper/tracklist-analysis'
14
- # REDIRECT_URI= 'http://localhost:8501'
15
  SCOPE = st.secrets["SPOTIFY_SCOPE"]
16
 
17
 
@@ -46,15 +47,23 @@ else:
46
  entry = f"{track['name']} by {artist}"
47
  entries.append(entry)
48
 
49
- prompt = f"generate 6 adjectives that describe the color, texture, theme, mood, vibe, and style of the following songs: {', '.join(entries)}"
50
- st.write(prompt)
51
 
52
- model_id = "runwayml/stable-diffusion-v1-5"
53
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
54
- pipe = pipe.to("cuda")
55
 
56
- image = pipe(prompt).images[0]
 
 
 
 
 
 
 
 
 
57
 
58
- image.save("generated.png")
59
 
60
- 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'
 
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'
15
+ REDIRECT_URI= 'http://localhost:8501'
16
  SCOPE = st.secrets["SPOTIFY_SCOPE"]
17
 
18
 
 
47
  entry = f"{track['name']} by {artist}"
48
  entries.append(entry)
49
 
50
+ 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\"]"
51
+ st.write('Prompt: ' + prompt)
52
 
53
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
54
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-7b")
 
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)