Guitar_Prep / app.py
VicMata's picture
Update app.py
ce06b06 verified
import streamlit as st
import google.generativeai as genai
import os
import requests
from dotenv import load_dotenv
from urllib.parse import quote_plus
# Cargar API Key
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
genai.configure(api_key=GEMINI_API_KEY)
MODEL_NAME = "gemini-2.5-pro-exp-03-25"
# Tu equipo personal
mis_guitarras = {
"Strandberg Boden Prog": "Humbucker",
"Fender Stratocaster": "Single Coil",
"Fender Jazzmaster": "P-90"
}
mis_plugins = [
"Archetype Plini X",
"Archetype Nolly X",
"Archetype Gojira X",
"Archetype Tim Henson",
"Archetype Rabea",
"Morgan Amps Suite"
]
# UI Config
st.set_page_config(page_title="🎸 Info Musical desde YouTube", layout="centered", page_icon="🎶")
# Estilo visual
st.markdown("""
<style>
.big-title {
font-size: 2.5rem;
font-weight: bold;
color: #FF4B4B;
text-align: center;
}
.subtext {
font-size: 1.2rem;
text-align: center;
color: #aaa;
}
</style>
""", unsafe_allow_html=True)
st.markdown('<div class="big-title">Guitar Prep</div>', unsafe_allow_html=True)
st.markdown('<div class="subtext">Todo lo que necesitas saber antes de aprender esa canción</div>', unsafe_allow_html=True)
st.markdown("---")
youtube_url = st.text_input("🔗 Pon el link de Youtube de la canción que quieres aprender")
if st.button("🎵 Extraer Información"):
if not youtube_url:
st.warning("Por favor ingresa un enlace válido.")
st.stop()
try:
with st.spinner("🔎 Obteniendo título del video..."):
response = requests.get(
"https://www.youtube.com/oembed",
params={"url": youtube_url, "format": "json"}
)
data = response.json()
video_title = data["title"]
except Exception as e:
st.error(f"❌ Error al extraer título del video: {e}")
st.stop()
# Construir el prompt
guitarras_str = "\n".join([f"- {g}: {t}" for g, t in mis_guitarras.items()])
plugins_str = "\n".join([f"- {p}" for p in mis_plugins])
prompt = f"""
Tengo este video de YouTube con el título:
"{video_title}"
Quiero saber:
1. 🎵 Nombre exacto de la canción
2. 🎤 Nombre del artista o banda
3. 📈 BPM aproximado
4. 🎼 Tonalidad musical (Key)
5. 👤 Guitarrista principal de la banda
6. 🎸 Modelo de guitarra que usa
7. 🔊 Amplificador que usa
8. 🎛️ Pedales o efectos más frecuentes
9. 🔗 Link al video de YouTube con más vistas que sea un cover de guitarra de esa canción
Y además:
10. 🎯 Con base en el equipo que usa el guitarrista y **mi equipo personal** (abajo), dime qué guitarra y qué plugin de Neural DSP debería usar para acercarme lo más posible al tono original del guitarrista.
**Mi equipo personal es el siguiente:**
🎸 Guitarras disponibles:
{guitarras_str}
🎛️ Plugins Neural DSP instalados:
{plugins_str}
Responde de forma organizada y con íconos.
"""
with st.spinner("🤖 Consultando a Gemini con tu equipo..."):
try:
model = genai.GenerativeModel(model_name=MODEL_NAME)
response = model.generate_content(prompt)
st.success("✅ Resultado de Gemini:")
st.markdown(response.text)
# Extraer nombre canción/artista para tablatura
lines = response.text.splitlines()
song_line = next((l for l in lines if "Canción" in l or "1." in l), "")
artist_line = next((l for l in lines if "Artista" in l or "2." in l), "")
def extract_value(line):
parts = line.split(":", 1)
return parts[1].strip() if len(parts) > 1 else ""
song_name = extract_value(song_line)
artist_name = extract_value(artist_line)
if song_name and artist_name:
search_url = f"https://www.ultimate-guitar.com/search.php?search_type=title&value={quote_plus(artist_name + ' ' + song_name)}"
st.subheader("🎼 Puedes aprender la canción en este link")
st.markdown(f"[🔗 Ver tablaturas en Ultimate Guitar]({search_url})")
except Exception as e:
st.error(f"❌ Error al consultar Gemini: {e}")