Spaces:
Sleeping
Sleeping
Manuel Zafra
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -74,10 +74,13 @@ def recognize_song(audio_path: str) -> dict:
|
|
74 |
|
75 |
# Herramienta para iniciar sesión en Soundeo
|
76 |
@tool
|
|
|
77 |
def login_soundeo() -> str:
|
78 |
"""Inicia sesión en Soundeo usando las credenciales almacenadas en secrets"""
|
79 |
from selenium import webdriver
|
80 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
81 |
from selenium.webdriver.common.by import By
|
82 |
from selenium.webdriver.support.ui import WebDriverWait
|
83 |
from selenium.webdriver.support import expected_conditions as EC
|
@@ -97,9 +100,11 @@ def login_soundeo() -> str:
|
|
97 |
chrome_options.add_argument("--disable-gpu")
|
98 |
|
99 |
try:
|
100 |
-
# Inicializar el driver
|
101 |
-
|
|
|
102 |
|
|
|
103 |
# Navegar a Soundeo
|
104 |
driver.get("https://soundeo.com/login")
|
105 |
time.sleep(3) # Esperar a que cargue la página
|
@@ -151,11 +156,20 @@ def add_song_to_download_list(song_title: str, artist: str) -> str:
|
|
151 |
"""
|
152 |
from selenium import webdriver
|
153 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
154 |
from selenium.webdriver.common.by import By
|
155 |
from selenium.webdriver.support.ui import WebDriverWait
|
156 |
from selenium.webdriver.support import expected_conditions as EC
|
157 |
-
import time
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
chrome_options = Options()
|
160 |
chrome_options.add_argument("--headless")
|
161 |
chrome_options.add_argument("--no-sandbox")
|
@@ -163,7 +177,9 @@ def add_song_to_download_list(song_title: str, artist: str) -> str:
|
|
163 |
chrome_options.add_argument("--disable-gpu")
|
164 |
|
165 |
try:
|
166 |
-
driver
|
|
|
|
|
167 |
|
168 |
# Verificar si hay sesión activa
|
169 |
cookies_file = "soundeo_cookies.pkl"
|
@@ -292,11 +308,20 @@ def view_download_list() -> str:
|
|
292 |
"""Muestra la lista actual de canciones en la lista de descargas de Soundeo"""
|
293 |
from selenium import webdriver
|
294 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
295 |
from selenium.webdriver.common.by import By
|
296 |
from selenium.webdriver.support.ui import WebDriverWait
|
297 |
from selenium.webdriver.support import expected_conditions as EC
|
298 |
-
import time
|
299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
chrome_options = Options()
|
301 |
chrome_options.add_argument("--headless")
|
302 |
chrome_options.add_argument("--no-sandbox")
|
@@ -304,7 +329,9 @@ def view_download_list() -> str:
|
|
304 |
chrome_options.add_argument("--disable-gpu")
|
305 |
|
306 |
try:
|
307 |
-
driver
|
|
|
|
|
308 |
|
309 |
# Verificar si hay sesión activa
|
310 |
cookies_file = "soundeo_cookies.pkl"
|
@@ -451,41 +478,46 @@ def process_audio_query(query: str) -> str:
|
|
451 |
|
452 |
@tool
|
453 |
def test_recognition_with_samples() -> str:
|
454 |
-
"""
|
455 |
-
import
|
456 |
import tempfile
|
457 |
import os
|
458 |
-
|
459 |
-
# Usar un archivo de muestra más confiable - este es un archivo de prueba estándar
|
460 |
-
sample_url = "https://file-examples.com/storage/fe52cb0eeea6095a1a78ff8/2017/11/file_example_MP3_700KB.mp3"
|
461 |
|
462 |
try:
|
463 |
-
#
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
#
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
file_size = os.path.getsize(temp_path)
|
475 |
|
476 |
-
#
|
477 |
-
|
478 |
-
|
479 |
-
# Formatear la respuesta
|
480 |
-
if "error" in result:
|
481 |
-
recognition_result = f"❌ Error en el reconocimiento: {result['error']}"
|
482 |
-
else:
|
483 |
-
recognition_result = f"✅ **Canción reconocida**:\n- 🎶 Canción: {result['🎶 Canción']}\n- 🎤 Artista: {result['🎤 Artista']}\n- 📀 Álbum: {result['📀 Álbum']}"
|
484 |
-
|
485 |
-
# Limpiar el archivo temporal
|
486 |
-
os.remove(temp_path)
|
487 |
-
|
488 |
-
return f"✅ Archivo descargado correctamente, tamaño: {file_size} bytes.\n\n{recognition_result}"
|
489 |
|
490 |
except Exception as e:
|
491 |
return f"❌ Error: {str(e)}"
|
|
|
74 |
|
75 |
# Herramienta para iniciar sesión en Soundeo
|
76 |
@tool
|
77 |
+
def @tool
|
78 |
def login_soundeo() -> str:
|
79 |
"""Inicia sesión en Soundeo usando las credenciales almacenadas en secrets"""
|
80 |
from selenium import webdriver
|
81 |
from selenium.webdriver.chrome.options import Options
|
82 |
+
from selenium.webdriver.chrome.service import Service
|
83 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
84 |
from selenium.webdriver.common.by import By
|
85 |
from selenium.webdriver.support.ui import WebDriverWait
|
86 |
from selenium.webdriver.support import expected_conditions as EC
|
|
|
100 |
chrome_options.add_argument("--disable-gpu")
|
101 |
|
102 |
try:
|
103 |
+
# Inicializar el driver con WebDriverManager
|
104 |
+
service = Service(ChromeDriverManager().install())
|
105 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
106 |
|
107 |
+
# Resto del código igual...
|
108 |
# Navegar a Soundeo
|
109 |
driver.get("https://soundeo.com/login")
|
110 |
time.sleep(3) # Esperar a que cargue la página
|
|
|
156 |
"""
|
157 |
from selenium import webdriver
|
158 |
from selenium.webdriver.chrome.options import Options
|
159 |
+
from selenium.webdriver.chrome.service import Service
|
160 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
161 |
from selenium.webdriver.common.by import By
|
162 |
from selenium.webdriver.support.ui import WebDriverWait
|
163 |
from selenium.webdriver.support import expected_conditions as EC
|
|
|
164 |
|
165 |
+
# Obtener credenciales de los secrets
|
166 |
+
username = os.getenv("SOUNDEO_USERNAME")
|
167 |
+
password = os.getenv("SOUNDEO_PASSWORD")
|
168 |
+
|
169 |
+
if not username or not password:
|
170 |
+
return "❌ No se encontraron las credenciales en los secrets"
|
171 |
+
|
172 |
+
# Configurar opciones de Chrome
|
173 |
chrome_options = Options()
|
174 |
chrome_options.add_argument("--headless")
|
175 |
chrome_options.add_argument("--no-sandbox")
|
|
|
177 |
chrome_options.add_argument("--disable-gpu")
|
178 |
|
179 |
try:
|
180 |
+
# Inicializar el driver con WebDriverManager
|
181 |
+
service = Service(ChromeDriverManager().install())
|
182 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
183 |
|
184 |
# Verificar si hay sesión activa
|
185 |
cookies_file = "soundeo_cookies.pkl"
|
|
|
308 |
"""Muestra la lista actual de canciones en la lista de descargas de Soundeo"""
|
309 |
from selenium import webdriver
|
310 |
from selenium.webdriver.chrome.options import Options
|
311 |
+
from selenium.webdriver.chrome.service import Service
|
312 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
313 |
from selenium.webdriver.common.by import By
|
314 |
from selenium.webdriver.support.ui import WebDriverWait
|
315 |
from selenium.webdriver.support import expected_conditions as EC
|
|
|
316 |
|
317 |
+
# Obtener credenciales de los secrets
|
318 |
+
username = os.getenv("SOUNDEO_USERNAME")
|
319 |
+
password = os.getenv("SOUNDEO_PASSWORD")
|
320 |
+
|
321 |
+
if not username or not password:
|
322 |
+
return "❌ No se encontraron las credenciales en los secrets"
|
323 |
+
|
324 |
+
# Configurar opciones de Chrome
|
325 |
chrome_options = Options()
|
326 |
chrome_options.add_argument("--headless")
|
327 |
chrome_options.add_argument("--no-sandbox")
|
|
|
329 |
chrome_options.add_argument("--disable-gpu")
|
330 |
|
331 |
try:
|
332 |
+
# Inicializar el driver con WebDriverManager
|
333 |
+
service = Service(ChromeDriverManager().install())
|
334 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
335 |
|
336 |
# Verificar si hay sesión activa
|
337 |
cookies_file = "soundeo_cookies.pkl"
|
|
|
478 |
|
479 |
@tool
|
480 |
def test_recognition_with_samples() -> str:
|
481 |
+
"""Genera un archivo de audio de prueba y lo reconoce"""
|
482 |
+
import numpy as np
|
483 |
import tempfile
|
484 |
import os
|
485 |
+
from scipy.io import wavfile
|
|
|
|
|
486 |
|
487 |
try:
|
488 |
+
# Generar un tono simple (440 Hz, nota La)
|
489 |
+
sample_rate = 44100 # 44.1 kHz
|
490 |
+
duration = 5 # 5 segundos
|
491 |
+
t = np.linspace(0, duration, int(sample_rate * duration), False)
|
492 |
+
|
493 |
+
# Crear una melodía simple con algunas frecuencias
|
494 |
+
note_a = np.sin(2 * np.pi * 440 * t) # La (A4)
|
495 |
+
note_c = np.sin(2 * np.pi * 523.25 * t) # Do (C5)
|
496 |
+
note_e = np.sin(2 * np.pi * 659.25 * t) # Mi (E5)
|
497 |
+
|
498 |
+
# Combinar en una melodía simple
|
499 |
+
melody = np.concatenate([
|
500 |
+
note_a[:sample_rate],
|
501 |
+
note_c[:sample_rate],
|
502 |
+
note_e[:sample_rate],
|
503 |
+
note_c[:sample_rate],
|
504 |
+
note_a[:sample_rate]
|
505 |
+
])
|
506 |
+
|
507 |
+
# Normalizar para evitar clipping
|
508 |
+
melody = melody * 0.3
|
509 |
+
|
510 |
+
# Guardar como archivo WAV
|
511 |
+
fd, temp_path = tempfile.mkstemp(suffix=".wav")
|
512 |
+
os.close(fd)
|
513 |
+
wavfile.write(temp_path, sample_rate, melody.astype(np.float32))
|
514 |
+
|
515 |
+
# Verificar que el archivo existe y tiene contenido
|
516 |
file_size = os.path.getsize(temp_path)
|
517 |
|
518 |
+
# Informar el resultado (en un caso real intentaríamos reconocer,
|
519 |
+
# pero como es un audio generado, probablemente no lo reconocería)
|
520 |
+
return f"✅ Archivo de audio de prueba generado correctamente, tamaño: {file_size} bytes.\n\nNota: Este es un audio sintético generado para pruebas, no una canción real."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
|
522 |
except Exception as e:
|
523 |
return f"❌ Error: {str(e)}"
|