Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,3 @@
|
|
| 1 |
-
# import os
|
| 2 |
-
# import spotipy
|
| 3 |
-
# from spotipy.oauth2 import SpotifyOAuth
|
| 4 |
-
# import gradio as gr
|
| 5 |
-
# from urllib.parse import urlparse, parse_qs
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# redirect_uri = "https://huggingface.co/sjw"
|
| 9 |
-
# scope= ['user-library-read',
|
| 10 |
-
# 'user-read-playback-state',
|
| 11 |
-
# 'user-modify-playback-state',
|
| 12 |
-
# 'playlist-modify-public',
|
| 13 |
-
# 'user-top-read']
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# def spotify_auth(client_id, client_secret, code=None):
|
| 17 |
-
# auth_manager = SpotifyOAuth(client_id=client_id,
|
| 18 |
-
# client_secret=client_secret,
|
| 19 |
-
# redirect_uri=redirect_uri,
|
| 20 |
-
# scope=scope)
|
| 21 |
-
# if code:
|
| 22 |
-
# parsed_url = urlparse(code)
|
| 23 |
-
# code = parse_qs(parsed_url.query)['code'][0]
|
| 24 |
-
# auth_manager.get_access_token(code=code, as_dict=False)
|
| 25 |
-
# sp = spotipy.Spotify(auth_manager=auth_manager)
|
| 26 |
-
# devices = sp.devices()
|
| 27 |
-
# device_id = devices['devices'][0]['id']
|
| 28 |
-
|
| 29 |
-
# results = sp.search(q="No Pole", type='track')
|
| 30 |
-
# track_uri = results['tracks']['items'][0]['uri']
|
| 31 |
-
# sp.start_playback(device_id=device_id, uris=[track_uri])
|
| 32 |
-
|
| 33 |
-
# return f"Account switched successfully.\n\n{devices}"
|
| 34 |
-
# else:
|
| 35 |
-
# auth_url = auth_manager.get_authorize_url()
|
| 36 |
-
# return f"Please authorize the app by clicking [here]({auth_url}) and then paste the code below."
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# with gr.Blocks() as demo:
|
| 40 |
-
|
| 41 |
-
# with gr.Row():
|
| 42 |
-
# client_id = gr.Textbox(label="Client ID")
|
| 43 |
-
# client_secret = gr.Textbox(label="Client Secret")
|
| 44 |
-
# link_button = gr.Button("Get Link")
|
| 45 |
-
# link_result = gr.Markdown()
|
| 46 |
-
|
| 47 |
-
# link = gr.Textbox(label="Paste Link")
|
| 48 |
-
# auth_button = gr.Button("Authorize")
|
| 49 |
-
# auth_result = gr.Textbox()
|
| 50 |
-
|
| 51 |
-
# link_button.click(spotify_auth, inputs=[client_id, client_secret], outputs=link_result)
|
| 52 |
-
# auth_button.click(spotify_auth, inputs=[client_id, client_secret, link], outputs=auth_result)
|
| 53 |
-
# demo.launch()
|
| 54 |
-
|
| 55 |
-
|
| 56 |
import gradio as gr
|
| 57 |
from urllib.parse import urlparse, parse_qs
|
| 58 |
import requests
|
|
@@ -83,12 +28,6 @@ with gr.Blocks() as demo:
|
|
| 83 |
fragment = parsed_url.fragment
|
| 84 |
access_token = parse_qs(fragment)['access_token'][0]
|
| 85 |
|
| 86 |
-
# # Start playing the song
|
| 87 |
-
# headers = {"Authorization": f"Bearer {access_token}"}
|
| 88 |
-
# data = {"uris": ["spotify:track:7hDc8b7IXETo14hHIHdnhd"]}
|
| 89 |
-
# response = requests.put("https://api.spotify.com/v1/me/player/play", headers=headers, json=data)
|
| 90 |
-
# if response.status_code != 204:
|
| 91 |
-
# return "Failed to start playback: " + response.text
|
| 92 |
sp = spotipy.Spotify(auth=access_token)
|
| 93 |
device_id = sp.devices()['devices'][0]['id']
|
| 94 |
results = sp.search(q="Passionfruit", type='track')
|
|
@@ -103,4 +42,4 @@ with gr.Blocks() as demo:
|
|
| 103 |
link_button.click(spotify_auth, inputs=[client_id], outputs=link_result)
|
| 104 |
auth_button.click(spotify_auth, inputs=[client_id, link], outputs=auth_result)
|
| 105 |
|
| 106 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from urllib.parse import urlparse, parse_qs
|
| 3 |
import requests
|
|
|
|
| 28 |
fragment = parsed_url.fragment
|
| 29 |
access_token = parse_qs(fragment)['access_token'][0]
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
sp = spotipy.Spotify(auth=access_token)
|
| 32 |
device_id = sp.devices()['devices'][0]['id']
|
| 33 |
results = sp.search(q="Passionfruit", type='track')
|
|
|
|
| 42 |
link_button.click(spotify_auth, inputs=[client_id], outputs=link_result)
|
| 43 |
auth_button.click(spotify_auth, inputs=[client_id, link], outputs=auth_result)
|
| 44 |
|
| 45 |
+
demo.launch()
|