Download app.py from rajkr/new0: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/rajkr/new0/resolve/main/app.py
- Command line
-
hf download hf://spaces/rajkr/new0/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rajkr/new0/resolve/main/app.py
1.32 kB
| # This Gradio app allows users to search for a song by artist name and stream the song. | |
| import gradio as gr | |
| import numpy as np | |
| import time | |
| import requests | |
| from io import BytesIO | |
| # Function to search for a song by artist name | |
| def search_song(artist_name): | |
| # Simulate a search request to an API | |
| # In a real application, you would replace this with an actual API call | |
| response = { | |
| "artist": artist_name, | |
| "song": "Sample Song", | |
| "audio_url": "https://example.com/sample-song.mp3" | |
| } | |
| return response | |
| # Function to stream the song | |
| def stream_song(song_details): | |
| # Extract the audio URL from the song details | |
| audio_url = song_details["audio_url"] | |
| # Simulate streaming the song | |
| for _ in range(10): # Fixed the syntax error by adding a colon and a range value | |
| time.sleep(0.5) | |
| yield audio_url | |
| # Create the Gradio interface | |
| with gr.Blocks() as demo: | |
| artist_name = gr.Textbox(label="Artist Name") | |
| song_details = gr.Json(label="Song Details") | |
| audio_output = gr.Audio(streaming=True, autoplay=True) | |
| # Set up the event listeners | |
| artist_name.submit(search_song, inputs=artist_name, outputs=song_details) | |
| song_details.change(stream_song, inputs=song_details, outputs=audio_output) | |
| # Launch the Gradio app | |
| demo.launch(show_error=True) |