| # import os | |
| # import spotipy | |
| # from spotipy.oauth2 import SpotifyOAuth | |
| # import gradio as gr | |
| # from urllib.parse import urlparse, parse_qs | |
| # redirect_uri = "https://huggingface.co/sjw" | |
| # scope= ['user-library-read', | |
| # 'user-read-playback-state', | |
| # 'user-modify-playback-state', | |
| # 'playlist-modify-public', | |
| # 'user-top-read'] | |
| # def spotify_auth(client_id, client_secret, code=None): | |
| # auth_manager = SpotifyOAuth(client_id=client_id, | |
| # client_secret=client_secret, | |
| # redirect_uri=redirect_uri, | |
| # scope=scope) | |
| # if code: | |
| # parsed_url = urlparse(code) | |
| # code = parse_qs(parsed_url.query)['code'][0] | |
| # auth_manager.get_access_token(code=code, as_dict=False) | |
| # sp = spotipy.Spotify(auth_manager=auth_manager) | |
| # devices = sp.devices() | |
| # device_id = devices['devices'][0]['id'] | |
| # results = sp.search(q="No Pole", type='track') | |
| # track_uri = results['tracks']['items'][0]['uri'] | |
| # sp.start_playback(device_id=device_id, uris=[track_uri]) | |
| # return f"Account switched successfully.\n\n{devices}" | |
| # else: | |
| # auth_url = auth_manager.get_authorize_url() | |
| # return f"Please authorize the app by clicking [here]({auth_url}) and then paste the code below." | |
| # with gr.Blocks() as demo: | |
| # with gr.Row(): | |
| # client_id = gr.Textbox(label="Client ID") | |
| # client_secret = gr.Textbox(label="Client Secret") | |
| # link_button = gr.Button("Get Link") | |
| # link_result = gr.Markdown() | |
| # link = gr.Textbox(label="Paste Link") | |
| # auth_button = gr.Button("Authorize") | |
| # auth_result = gr.Textbox() | |
| # link_button.click(spotify_auth, inputs=[client_id, client_secret], outputs=link_result) | |
| # auth_button.click(spotify_auth, inputs=[client_id, client_secret, link], outputs=auth_result) | |
| # demo.launch() | |
| import gradio as gr | |
| secret_word = "gradio" | |
| with gr.Blocks() as demo: | |
| used_letters_var = gr.State([]) | |
| with gr.Row() as row: | |
| with gr.Column(): | |
| input_letter = gr.Textbox(label="Enter letter") | |
| btn = gr.Button("Guess Letter") | |
| with gr.Column(): | |
| hangman = gr.Textbox( | |
| label="Hangman", | |
| value="_"*len(secret_word) | |
| ) | |
| used_letters_box = gr.Textbox(label="Used Letters") | |
| def guess_letter(letter, used_letters): | |
| used_letters.append(letter) | |
| answer = "".join([ | |
| (letter if letter in used_letters else "_") | |
| for letter in secret_word | |
| ]) | |
| return { | |
| used_letters_var: used_letters, | |
| used_letters_box: ", ".join(used_letters), | |
| hangman: answer | |
| } | |
| btn.click( | |
| guess_letter, | |
| [input_letter, used_letters_var], | |
| [used_letters_var, used_letters_box, hangman] | |
| ) | |
| demo.launch() |