Spaces:
Sleeping
Sleeping
Commit
·
fa83c8b
1
Parent(s):
c3c18c4
Update app.py
Browse files
app.py
CHANGED
@@ -65,16 +65,22 @@ def recommend_song(song_name, artist_name, spotify_data_processed, top_n=4):
|
|
65 |
|
66 |
|
67 |
|
|
|
68 |
def recommend_song_interface(song_name, artist_name):
|
69 |
recommendations_df = recommend_song(song_name, artist_name, spotify_data_processed)
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
recommendations_list = recommendations_df.values.tolist()
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
else:
|
76 |
-
#
|
77 |
-
return
|
|
|
78 |
|
79 |
# Crear la interfaz con Gradio
|
80 |
iface = gr.Interface(
|
@@ -90,7 +96,11 @@ iface = gr.Interface(
|
|
90 |
title="Recomendador de Canciones",
|
91 |
description="Ingrese el título de una canción y el nombre del artista para obtener recomendaciones.",
|
92 |
theme="dark", # Comenta o elimina si el tema oscuro no está disponible
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
)
|
95 |
|
96 |
iface.launch()
|
|
|
65 |
|
66 |
|
67 |
|
68 |
+
|
69 |
def recommend_song_interface(song_name, artist_name):
|
70 |
recommendations_df = recommend_song(song_name, artist_name, spotify_data_processed)
|
71 |
|
72 |
+
# Verificar si el DataFrame está vacío o si las columnas necesarias están presentes
|
73 |
+
if isinstance(recommendations_df, pd.DataFrame) and not recommendations_df.empty and {'song', 'artist'}.issubset(recommendations_df.columns):
|
74 |
+
recommendations_list = recommendations_df[['song', 'artist']].values.tolist()
|
75 |
+
formatted_recommendations = ["{} by {}".format(song, artist) for song, artist in recommendations_list]
|
76 |
+
# Rellenar con cadenas vacías si hay menos de 4 recomendaciones
|
77 |
+
while len(formatted_recommendations) < 4:
|
78 |
+
formatted_recommendations.append("")
|
79 |
+
return formatted_recommendations[:4]
|
80 |
else:
|
81 |
+
# Devolver mensajes de error o cadenas vacías si no se cumplen las condiciones anteriores
|
82 |
+
return ["Error: No se pudo procesar las recomendaciones."] + [""] * 3
|
83 |
+
|
84 |
|
85 |
# Crear la interfaz con Gradio
|
86 |
iface = gr.Interface(
|
|
|
96 |
title="Recomendador de Canciones",
|
97 |
description="Ingrese el título de una canción y el nombre del artista para obtener recomendaciones.",
|
98 |
theme="dark", # Comenta o elimina si el tema oscuro no está disponible
|
99 |
+
css="""
|
100 |
+
body {font-family: Arial, sans-serif;}
|
101 |
+
.input_text {background-color: #f0f0f0; border-radius: 5px;}
|
102 |
+
.output_text {border: 2px solid #f0f0f0; border-radius: 5px; padding: 10px;}
|
103 |
+
"""
|
104 |
)
|
105 |
|
106 |
iface.launch()
|