File size: 2,512 Bytes
08f7b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from Recomendation import recommend_song_interface
import gradio as gr
import requests



def search_youtube(song, artist, api_key):
    query = f"{song} by {artist}"
    search_url = "https://www.googleapis.com/youtube/v3/search"
    params = {
        'part': 'snippet',
        'q': query,
        'type': 'video',
        'maxResults': 1,
        'key': api_key
    }

    response = requests.get(search_url, params=params)
    response_json = response.json()

    if 'items' in response_json and response_json['items']:
        video_id = response_json['items'][0]['id']['videoId']
        youtube_link = f"https://www.youtube.com/watch?v={video_id}"
        return youtube_link
    else:
        return "No se encontraron resultados."

def add_youtube_links(recommendations, api_key):
    recommendations_with_links = []
    for recommendation in recommendations:
        if recommendation:  # Si la recomendaci贸n no es una cadena vac铆a
            song, artist = recommendation.split(" by ")
            youtube_link = search_youtube(song, artist, api_key)
            recommendations_with_links.append(f"{recommendation} - YouTube Link: {youtube_link}")
        else:
            recommendations_with_links.append("")

    return recommendations_with_links

def recommend_with_youtube_links(song_name, artist_name):
    api_key = "AIzaSyAp-D7Mfafd6gJQo2gtAXRXwDlG8_uNXnU"
    recommendations = recommend_song_interface(song_name, artist_name)
    recommendations_with_links = add_youtube_links(recommendations, api_key)
    return recommendations_with_links

# Configuraci贸n de la interfaz Gradio
iface = gr.Interface(
    fn=recommend_with_youtube_links,
    inputs=[
        gr.Textbox(placeholder="Ingrese el t铆tulo de la canci贸n", label="T铆tulo de la Canci贸n"),
        gr.Textbox(placeholder="Ingrese el nombre del artista", label="Nombre del Artista")
    ],
   outputs=[
    gr.Text(label="Recomendaci贸n 1"),
    gr.Text(label="Recomendaci贸n 2"),
    gr.Text(label="Recomendaci贸n 3"),
    gr.Text(label="Recomendaci贸n 4"),],
    title="Recomendador de Canciones con Enlaces de YouTube",
    description="Ingrese el t铆tulo de una canci贸n y el nombre del artista.",
    theme="dark",  # Comenta o elimina si el tema oscuro no est谩 disponible
    css="""
        body {font-family: Arial, sans-serif;}
        .input_text {background-color: #f0f0f0; border-radius: 5px;}
        .output_text {border: 2px solid #f0f0f0; border-radius: 5px; padding: 10px;}
        """
)

iface.launch()