Diego-0121 commited on
Commit
c3c18c4
·
1 Parent(s): c41e135

Update Recomendation.py

Browse files
Files changed (1) hide show
  1. Recomendation.py +12 -6
Recomendation.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
- if isinstance(recommendations_df, pd.DataFrame):
72
- # Convierte el DataFrame en una lista de listas y luego a un formato de texto plano para la salida
73
- recommendations_list = recommendations_df.values.tolist()
74
- return ["{} by {}".format(song, artist) for song, artist in recommendations_list]
 
 
 
 
75
  else:
76
- # Si no es un DataFrame, devolver el mensaje de error
77
- return recommendations_df
 
78
 
79
  # Crear la interfaz con Gradio
80
  iface = gr.Interface(
 
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(