jisaacso219 commited on
Commit
1ff8081
Β·
verified Β·
1 Parent(s): 83a3f7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
3
  import spotipy
4
  from spotipy.oauth2 import SpotifyOAuth
5
  import random
6
- import time
7
 
8
  # Load environment variables securely from Hugging Face secrets
9
  CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
@@ -20,23 +19,37 @@ sp_oauth = SpotifyOAuth(
20
 
21
  auth_url = sp_oauth.get_authorize_url()
22
 
23
- sp = None # Will be set after authorization
24
  user_playlists = {}
25
  selected_playlist_id = None
26
 
27
  with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
28
- gr.Markdown("## 🎡 RNG Spotify Playlist Shuffler", elem_id="title")
29
  gr.Markdown("A clean and simple way to shuffle your Spotify playlists with one click.")
30
 
31
  with gr.Column():
32
- login_link = gr.Markdown(f"### πŸ” Step 1: [Click here to login to Spotify]({auth_url})")
33
- code_box = gr.Textbox(label="Step 2: Paste authorization code", placeholder="...?code=ABC123", visible=True)
34
- authorize_button = gr.Button("βœ… Step 3: Complete Authorization", visible=True)
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
  def check_login(code):
41
  global sp, user_playlists
42
  if not code:
@@ -54,7 +67,7 @@ with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
54
  gr.update(visible=True, value="βœ… Logged in! Select your playlist below."),
55
  gr.update(visible=True, choices=list(user_playlists.keys())),
56
  gr.update(visible=True),
57
- gr.update(visible=True)
58
  )
59
 
60
  def shuffle_and_play(playlist_name):
@@ -95,4 +108,3 @@ with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
95
 
96
  if __name__ == "__main__":
97
  demo.launch()
98
-
 
3
  import spotipy
4
  from spotipy.oauth2 import SpotifyOAuth
5
  import random
 
6
 
7
  # Load environment variables securely from Hugging Face secrets
8
  CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
 
19
 
20
  auth_url = sp_oauth.get_authorize_url()
21
 
22
+ sp = None
23
  user_playlists = {}
24
  selected_playlist_id = None
25
 
26
  with gr.Blocks(title="RNG Spotify Playlist Shuffler") as demo:
27
+ gr.Markdown("## 🎡 RNG Spotify Playlist Shuffler")
28
  gr.Markdown("A clean and simple way to shuffle your Spotify playlists with one click.")
29
 
30
  with gr.Column():
31
+ login_link = gr.Markdown(f"[πŸ” Step 1: Login to Spotify]({auth_url})")
32
+ code_box = gr.Textbox(label="Step 2: Paste Authorization Code", visible=True)
33
+ authorize_button = gr.Button("βœ… Step 3: Authorize", visible=True)
34
  login_status = gr.Markdown(visible=False)
35
+ playlist_dropdown = gr.Dropdown(choices=[], label="Step 4: Select Playlist", visible=False)
36
  shuffle_button = gr.Button("πŸ”€ Step 5: Shuffle and Play", visible=False)
37
  result_box = gr.Markdown(visible=False)
38
 
39
+ # Autofill JavaScript
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
+ document.querySelector("textarea").value = code;
47
+ document.querySelector("button").click();
48
+ }
49
+ }
50
+ </script>
51
+ """)
52
+
53
  def check_login(code):
54
  global sp, user_playlists
55
  if not code:
 
67
  gr.update(visible=True, value="βœ… Logged in! Select your playlist below."),
68
  gr.update(visible=True, choices=list(user_playlists.keys())),
69
  gr.update(visible=True),
70
+ gr.update(visible=False)
71
  )
72
 
73
  def shuffle_and_play(playlist_name):
 
108
 
109
  if __name__ == "__main__":
110
  demo.launch()