Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
-
import tempfile
|
| 5 |
|
| 6 |
# —————— PARCHE Pydantic para FastAPI ——————
|
| 7 |
import pydantic
|
|
@@ -26,6 +25,7 @@ CLIENT_ID = os.getenv("SPOTIFY_CLIENT_IDS", "").split(',')[0]
|
|
| 26 |
CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRETS", "").split(',')[0]
|
| 27 |
|
| 28 |
# Función para obtener token
|
|
|
|
| 29 |
def get_token():
|
| 30 |
resp = requests.post(
|
| 31 |
"https://accounts.spotify.com/api/token",
|
|
@@ -51,6 +51,7 @@ def get_artist_genres(aid, headers):
|
|
| 51 |
return genres
|
| 52 |
|
| 53 |
# Fetch y devuelve DataFrame de toda la playlist
|
|
|
|
| 54 |
def fetch_playlist_table(url):
|
| 55 |
if not CLIENT_ID or not CLIENT_SECRET:
|
| 56 |
return pd.DataFrame([{'Error': 'Faltan credenciales'}])
|
|
@@ -92,27 +93,19 @@ def fetch_playlist_table(url):
|
|
| 92 |
df = pd.DataFrame(records)
|
| 93 |
return df
|
| 94 |
|
| 95 |
-
# Función principal: retorna DataFrame
|
| 96 |
|
| 97 |
def main(url):
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
df.to_csv(tmp.name, index=False)
|
| 102 |
-
# Mostrar tabla y luego revelar botón de descarga
|
| 103 |
-
return df, gr.File.update(value=tmp.name, visible=True)
|
| 104 |
-
|
| 105 |
-
# Definición de interfaz con botón de descarga oculto inicialmente
|
| 106 |
iface = gr.Interface(
|
| 107 |
fn=main,
|
| 108 |
-
inputs=gr.Textbox(label="URL de playlist"),
|
| 109 |
-
outputs=[
|
| 110 |
-
gr.Dataframe(headers=['Artist','Title','ISRC','URL','URI','Genres'], label="Tabla"),
|
| 111 |
-
gr.File(label="Descargar CSV", visible=False)
|
| 112 |
-
],
|
| 113 |
title="🎵 Tabla de Playlist Spotify",
|
| 114 |
-
description="Trae Artist, Title, ISRC, URL, URI y Géneros de cada track
|
| 115 |
)
|
| 116 |
|
| 117 |
if __name__ == '__main__':
|
| 118 |
-
iface.launch(server_name='0.0.0.0', server_port=7860)
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
# —————— PARCHE Pydantic para FastAPI ——————
|
| 6 |
import pydantic
|
|
|
|
| 25 |
CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRETS", "").split(',')[0]
|
| 26 |
|
| 27 |
# Función para obtener token
|
| 28 |
+
|
| 29 |
def get_token():
|
| 30 |
resp = requests.post(
|
| 31 |
"https://accounts.spotify.com/api/token",
|
|
|
|
| 51 |
return genres
|
| 52 |
|
| 53 |
# Fetch y devuelve DataFrame de toda la playlist
|
| 54 |
+
|
| 55 |
def fetch_playlist_table(url):
|
| 56 |
if not CLIENT_ID or not CLIENT_SECRET:
|
| 57 |
return pd.DataFrame([{'Error': 'Faltan credenciales'}])
|
|
|
|
| 93 |
df = pd.DataFrame(records)
|
| 94 |
return df
|
| 95 |
|
| 96 |
+
# Función principal: retorna DataFrame para mostrar en tabla
|
| 97 |
|
| 98 |
def main(url):
|
| 99 |
+
return fetch_playlist_table(url)
|
| 100 |
+
|
| 101 |
+
# Interfaz Gradio: sólo DataFrame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
iface = gr.Interface(
|
| 103 |
fn=main,
|
| 104 |
+
inputs=gr.Textbox(label="URL de playlist", placeholder="https://open.spotify.com/playlist/...") ,
|
| 105 |
+
outputs=gr.Dataframe(headers=['Artist','Title','ISRC','URL','URI','Genres'], label="Tabla de Playlist Spotify"),
|
|
|
|
|
|
|
|
|
|
| 106 |
title="🎵 Tabla de Playlist Spotify",
|
| 107 |
+
description="Trae Artist, Title, ISRC, URL, URI y Géneros de cada track"
|
| 108 |
)
|
| 109 |
|
| 110 |
if __name__ == '__main__':
|
| 111 |
+
iface.launch(server_name='0.0.0.0', server_port=7860)
|