Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from recommend import recommend_songs, recommend_by_mood
|
| 3 |
from mood_profiles import mood_profiles
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
recommendations += "Recommendations based on your song:\n" + format_results(song_recs) + "\n\n"
|
| 13 |
-
|
| 14 |
-
analyzed_mood_vector = analyze_song_mood(song_list)
|
| 15 |
-
print(f"Analyzed Mood Vector for {title}: {analyzed_mood_vector}") # Debugging print
|
| 16 |
-
|
| 17 |
-
if analyzed_mood_vector is not None:
|
| 18 |
-
mood_recs = recommend_by_mood(analyzed_mood_vector)
|
| 19 |
-
recommendations += f"Recommendations based on the analyzed mood of '{title}':\n" + format_results(mood_recs)
|
| 20 |
-
else:
|
| 21 |
-
recommendations += f"Could not analyze the mood of '{title}'.\n"
|
| 22 |
-
|
| 23 |
-
except ValueError:
|
| 24 |
-
recommendations += "Error: Invalid year format.\n\n"
|
| 25 |
-
except Exception as e:
|
| 26 |
-
recommendations += f"Error: {e}\n\n"
|
| 27 |
-
else:
|
| 28 |
-
recommendations = "Please enter a song to get recommendations."
|
| 29 |
-
|
| 30 |
-
return recommendations
|
| 31 |
|
| 32 |
def recommend_from_mood(mood):
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
-
results = recommend_by_mood(mood_vector)
|
| 36 |
return format_results(results)
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error: {e}"
|
|
@@ -48,11 +28,11 @@ def format_results(results):
|
|
| 48 |
return formatted
|
| 49 |
|
| 50 |
song_interface = gr.Interface(
|
| 51 |
-
fn=
|
| 52 |
-
inputs=[gr.Textbox(label="Song Name"), gr.Textbox(label="Year
|
| 53 |
outputs="text",
|
| 54 |
-
title="🎵 Music Recommender (By Song
|
| 55 |
-
description="Get song recommendations based on your favorite track
|
| 56 |
)
|
| 57 |
|
| 58 |
mood_interface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from recommend import recommend_songs, recommend_by_mood
|
| 3 |
from mood_profiles import mood_profiles
|
| 4 |
|
| 5 |
+
def recommend_from_song(title, year):
|
| 6 |
+
try:
|
| 7 |
+
year = int(year)
|
| 8 |
+
results = recommend_songs([{'name': title, 'year': year}])
|
| 9 |
+
return format_results(results)
|
| 10 |
+
except Exception as e:
|
| 11 |
+
return f"Error: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def recommend_from_mood(mood):
|
| 14 |
try:
|
| 15 |
+
results = recommend_by_mood(mood.lower())
|
|
|
|
| 16 |
return format_results(results)
|
| 17 |
except Exception as e:
|
| 18 |
return f"Error: {e}"
|
|
|
|
| 28 |
return formatted
|
| 29 |
|
| 30 |
song_interface = gr.Interface(
|
| 31 |
+
fn=recommend_from_song,
|
| 32 |
+
inputs=[gr.Textbox(label="Song Name"), gr.Textbox(label="Year")],
|
| 33 |
outputs="text",
|
| 34 |
+
title="🎵 Music Recommender (By Song)",
|
| 35 |
+
description="Get song recommendations based on your favorite track."
|
| 36 |
)
|
| 37 |
|
| 38 |
mood_interface = gr.Interface(
|