Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,28 @@ import requests
|
|
5 |
JAMENDO_API_URL = "https://api.jamendo.com/v3.0/tracks/"
|
6 |
JAMENDO_CLIENT_ID = "7c065513" # Replace with your Jamendo API key
|
7 |
|
8 |
-
# Function to search for songs
|
9 |
-
def search_songs(query):
|
10 |
params = {
|
11 |
"client_id": JAMENDO_CLIENT_ID,
|
12 |
"format": "json",
|
13 |
"limit": 10, # Limit to 10 results
|
14 |
-
"search": query,
|
15 |
"audioformat": "mp3" # Ensure we get MP3 streams
|
16 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
response = requests.get(JAMENDO_API_URL, params=params)
|
18 |
data = response.json()
|
19 |
|
@@ -42,7 +55,7 @@ body {
|
|
42 |
padding: 20px;
|
43 |
border-radius: 10px;
|
44 |
}
|
45 |
-
input, button {
|
46 |
background-color: #282828;
|
47 |
color: #FFFFFF;
|
48 |
border: none;
|
@@ -64,7 +77,12 @@ with gr.Blocks(css=custom_css, title="Spotify-Like Music Player") as demo:
|
|
64 |
|
65 |
with gr.Row():
|
66 |
with gr.Column(scale=1):
|
67 |
-
search_input = gr.Textbox(label="Search Songs", placeholder="Enter
|
|
|
|
|
|
|
|
|
|
|
68 |
search_btn = gr.Button("Search")
|
69 |
|
70 |
with gr.Column(scale=2):
|
@@ -77,7 +95,7 @@ with gr.Blocks(css=custom_css, title="Spotify-Like Music Player") as demo:
|
|
77 |
# Event handlers
|
78 |
search_btn.click(
|
79 |
fn=search_songs,
|
80 |
-
inputs=search_input,
|
81 |
outputs=song_list
|
82 |
)
|
83 |
song_list.change(
|
|
|
5 |
JAMENDO_API_URL = "https://api.jamendo.com/v3.0/tracks/"
|
6 |
JAMENDO_CLIENT_ID = "7c065513" # Replace with your Jamendo API key
|
7 |
|
8 |
+
# Function to search for songs based on selected option
|
9 |
+
def search_songs(query, search_type):
|
10 |
params = {
|
11 |
"client_id": JAMENDO_CLIENT_ID,
|
12 |
"format": "json",
|
13 |
"limit": 10, # Limit to 10 results
|
|
|
14 |
"audioformat": "mp3" # Ensure we get MP3 streams
|
15 |
}
|
16 |
+
|
17 |
+
# Adjust parameters based on search type
|
18 |
+
if search_type == "Song Title":
|
19 |
+
params["search"] = query
|
20 |
+
elif search_type == "Artist":
|
21 |
+
params["namesearch"] = query # Search by artist name
|
22 |
+
elif search_type == "Genre":
|
23 |
+
params["tags"] = query # Search by genre/tag
|
24 |
+
elif search_type == "Mood/Tag":
|
25 |
+
params["tags"] = query # Same as genre but worded differently for user
|
26 |
+
elif search_type == "Popularity":
|
27 |
+
params["search"] = query
|
28 |
+
params["order"] = "popularity_total_desc" # Sort by popularity
|
29 |
+
|
30 |
response = requests.get(JAMENDO_API_URL, params=params)
|
31 |
data = response.json()
|
32 |
|
|
|
55 |
padding: 20px;
|
56 |
border-radius: 10px;
|
57 |
}
|
58 |
+
input, button, select {
|
59 |
background-color: #282828;
|
60 |
color: #FFFFFF;
|
61 |
border: none;
|
|
|
77 |
|
78 |
with gr.Row():
|
79 |
with gr.Column(scale=1):
|
80 |
+
search_input = gr.Textbox(label="Search Songs", placeholder="Enter your search term...")
|
81 |
+
search_type = gr.Dropdown(
|
82 |
+
label="Search By",
|
83 |
+
choices=["Song Title", "Artist", "Genre", "Mood/Tag", "Popularity"],
|
84 |
+
value="Song Title" # Default option
|
85 |
+
)
|
86 |
search_btn = gr.Button("Search")
|
87 |
|
88 |
with gr.Column(scale=2):
|
|
|
95 |
# Event handlers
|
96 |
search_btn.click(
|
97 |
fn=search_songs,
|
98 |
+
inputs=[search_input, search_type],
|
99 |
outputs=song_list
|
100 |
)
|
101 |
song_list.change(
|