File size: 3,282 Bytes
e7ef9ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import pdfplumber
from resumen_utils import (
    detectar_idioma,
    traducir_texto,
    exportar_a_pdf,
    resumir_texto,
    transcribir_youtube,
    generar_preguntas_clave,
    extraer_entidades,
    texto_a_voz,
)

st.set_page_config(page_title="🧠 Bot de currículum de IA", layout="centered")

st.title("🧠 Bot de currículum de IA")
st.write("Resumen automático de PDFs, textos y vídeos de YouTube, ahora con funciones avanzadas.")

opcion = st.radio(
    "Selecciona la fuente de texto:",
    ("📄 PDF", "✍️ Texto manual", "🎥 YouTube")
)

texto_original = ""

if opcion == "📄 PDF":
    archivo_pdf = st.file_uploader("Sube un archivo PDF", type=["pdf"])
    if archivo_pdf is not None:
        with pdfplumber.open(archivo_pdf) as pdf:
            texto_original = "\n".join([page.extract_text() or "" for page in pdf.pages])

elif opcion == "✍️ Texto manual":
    texto_original = st.text_area("Introduce el texto aquí:", height=300)

elif opcion == "🎥 YouTube":
    url_video = st.text_input("Introduce la URL del vídeo de YouTube")
    if url_video:
        with st.spinner("Obteniendo transcripción..."):
            texto_youtube, error = transcribir_youtube(url_video)
        if error:
            st.error(error)
        else:
            texto_original = texto_youtube
            st.success("Transcripción obtenida correctamente.")

if texto_original:
    idioma_detectado = detectar_idioma(texto_original)
    st.markdown(f"🌐 **Idioma detectado:** {idioma_detectado}")

    texto_para_resumir = texto_original
    if idioma_detectado != "es":
        texto_para_resumir = traducir_texto(texto_original, idioma_origen=idioma_detectado, idioma_destino="es")
        st.info("🔄 Texto traducido automáticamente al español para mejor resumen.")

    resumen_generado = resumir_texto(texto_para_resumir)

    st.subheader("📝 Resumen generado:")
    st.write(resumen_generado)

    # Botones para acciones avanzadas
    if st.button("📥 Exportar resumen a PDF"):
        exportar_a_pdf(resumen_generado)
        st.success("✅ Resumen exportado como 'resumen.pdf'. Revisa la carpeta de ejecución.")

    if st.button("🔊 Escuchar resumen en voz alta"):
        audio_html = texto_a_voz(resumen_generado, lang="es")
        if audio_html:
            st.markdown(audio_html, unsafe_allow_html=True)
        else:
            st.error("No se pudo reproducir el audio.")

    if st.button("🔍 Mostrar entidades nombradas"):
        entidades = extraer_entidades(texto_para_resumir)
        if entidades:
            for tipo, lista in entidades.items():
                st.markdown(f"**{tipo}:** {', '.join(lista)}")
        else:
            st.info("No se detectaron entidades nombradas.")

    if st.button("❓ Generar preguntas clave para reflexión"):
        preguntas = generar_preguntas_clave(texto_para_resumir)
        if preguntas:
            st.subheader("❓ Preguntas clave para reflexión:")
            for i, pregunta in enumerate(preguntas, 1):
                st.write(f"{i}. {pregunta}")
        else:
            st.info("No se pudieron generar preguntas clave para este texto.")