jisaacso219 commited on
Commit
4082b56
Β·
verified Β·
1 Parent(s): b414958

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -7,7 +7,7 @@ import random
7
  # Load environment variables securely from Hugging Face secrets
8
  CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
9
  CLIENT_SECRET = os.environ["SPOTIFY_CLIENT_SECRET"]
10
- REDIRECT_URI = os.environ.get("SPOTIFY_REDIRECT_URI", "https://jisaacso219-rng-shuffle.hf.space/callback")
11
  SCOPE = "user-read-playback-state user-modify-playback-state playlist-read-private"
12
 
13
  sp_oauth = SpotifyOAuth(
@@ -29,31 +29,30 @@ with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
29
  gr.Markdown("A clean and simple way to shuffle your Spotify playlists with one click.")
30
 
31
  with gr.Column():
32
- auth_url_button = gr.Button("πŸ” Step 1: Login to Spotify")
33
- auth_code_box = gr.Textbox(label="Step 2: Paste authorization code", placeholder="...?code=ABC123")
34
- authorize_button = gr.Button("βœ… Step 3: Complete Authorization")
35
- login_status = gr.Markdown(visible=False)
36
- playlist_dropdown = gr.Dropdown(choices=[], label="Step 4: 🎧 Select a Playlist", visible=False)
37
- shuffle_button = gr.Button("πŸ”€ Step 5: Shuffle and Play", visible=False)
38
- result_box = gr.Markdown(visible=False)
39
-
40
- gr.HTML("""
41
  <script>
42
- window.onload = () => {
43
  const params = new URLSearchParams(window.location.search);
44
  const code = params.get("code");
45
- if (code) {
46
  const textbox = document.querySelector("textarea");
47
- if (textbox) {
48
  textbox.value = code;
49
- }
50
- }
51
- }
52
  </script>
53
  """)
54
 
55
- def open_auth_url():
56
- return gr.update(value=get_auth_url())
 
 
 
 
57
 
58
  def check_login(code):
59
  global sp, user_playlists
@@ -99,7 +98,6 @@ with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
99
  sp.start_playback(device_id=device_id, uris=uris)
100
  return gr.update(value=f"▢️ Now playing: **{playlist_name}** in shuffled order!", visible=True)
101
 
102
- auth_url_button.click(fn=lambda: None, _js=f"() => window.open('{get_auth_url()}', '_blank')")
103
  authorize_button.click(
104
  check_login,
105
  inputs=[auth_code_box],
 
7
  # Load environment variables securely from Hugging Face secrets
8
  CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
9
  CLIENT_SECRET = os.environ["SPOTIFY_CLIENT_SECRET"]
10
+ REDIRECT_URI = os.environ.get("SPOTIFY_REDIRECT_URI", "https://jisaacso219-rng-shuffle.hf.space/") # βœ… Updated to match registered redirect URI
11
  SCOPE = "user-read-playback-state user-modify-playback-state playlist-read-private"
12
 
13
  sp_oauth = SpotifyOAuth(
 
29
  gr.Markdown("A clean and simple way to shuffle your Spotify playlists with one click.")
30
 
31
  with gr.Column():
32
+ gr.HTML(f"""
33
+ <a href='{get_auth_url()}' target='_blank'>
34
+ <button style='font-size: 16px; padding: 10px 20px; width: 100%; background-color: #4f46e5; color: white; border: none; border-radius: 6px;'>πŸ” Step 1: Login to Spotify</button>
35
+ </a>
 
 
 
 
 
36
  <script>
37
+ window.onload = () => {{
38
  const params = new URLSearchParams(window.location.search);
39
  const code = params.get("code");
40
+ if (code) {{
41
  const textbox = document.querySelector("textarea");
42
+ if (textbox) {{
43
  textbox.value = code;
44
+ }}
45
+ }}
46
+ }}
47
  </script>
48
  """)
49
 
50
+ auth_code_box = gr.Textbox(label="Step 2: Paste authorization code", placeholder="...?code=ABC123")
51
+ authorize_button = gr.Button("βœ… Step 3: Complete Authorization")
52
+ login_status = gr.Markdown(visible=False)
53
+ playlist_dropdown = gr.Dropdown(choices=[], label="Step 4: 🎧 Select a Playlist", visible=False)
54
+ shuffle_button = gr.Button("πŸ”€ Step 5: Shuffle and Play", visible=False)
55
+ result_box = gr.Markdown(visible=False)
56
 
57
  def check_login(code):
58
  global sp, user_playlists
 
98
  sp.start_playback(device_id=device_id, uris=uris)
99
  return gr.update(value=f"▢️ Now playing: **{playlist_name}** in shuffled order!", visible=True)
100
 
 
101
  authorize_button.click(
102
  check_login,
103
  inputs=[auth_code_box],