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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
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
- 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(
@@ -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()