sjw commited on
Commit
ff393f0
·
1 Parent(s): 7587b95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -45
app.py CHANGED
@@ -1,53 +1,88 @@
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()
 
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
+ import gradio as gr
56
 
57
+ secret_word = "gradio"
 
 
 
 
58
 
59
+ with gr.Blocks() as demo:
60
+ used_letters_var = gr.State([])
61
+ with gr.Row() as row:
62
+ with gr.Column():
63
+ input_letter = gr.Textbox(label="Enter letter")
64
+ btn = gr.Button("Guess Letter")
65
+ with gr.Column():
66
+ hangman = gr.Textbox(
67
+ label="Hangman",
68
+ value="_"*len(secret_word)
69
+ )
70
+ used_letters_box = gr.Textbox(label="Used Letters")
71
 
72
+ def guess_letter(letter, used_letters):
73
+ used_letters.append(letter)
74
+ answer = "".join([
75
+ (letter if letter in used_letters else "_")
76
+ for letter in secret_word
77
+ ])
78
+ return {
79
+ used_letters_var: used_letters,
80
+ used_letters_box: ", ".join(used_letters),
81
+ hangman: answer
82
+ }
83
+ btn.click(
84
+ guess_letter,
85
+ [input_letter, used_letters_var],
86
+ [used_letters_var, used_letters_box, hangman]
87
+ )
88
  demo.launch()