Spaces:
Sleeping
Sleeping
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.") | |