Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,6 @@ st.markdown(
|
|
| 27 |
"""
|
| 28 |
<style>
|
| 29 |
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap');
|
| 30 |
-
|
| 31 |
body {
|
| 32 |
background-color: #1C1C1C;
|
| 33 |
color: #ECF0F1;
|
|
@@ -35,7 +34,6 @@ st.markdown(
|
|
| 35 |
background-size: cover;
|
| 36 |
font-family: 'Poppins', sans-serif;
|
| 37 |
}
|
| 38 |
-
|
| 39 |
.stButton>button {
|
| 40 |
background-color: #007BFF;
|
| 41 |
color: #FFD700;
|
|
@@ -50,7 +48,6 @@ st.markdown(
|
|
| 50 |
background-color: #0056b3;
|
| 51 |
transform: scale(1.05);
|
| 52 |
}
|
| 53 |
-
|
| 54 |
.stTextInput>div>div>input {
|
| 55 |
border: 2px solid #FFD700;
|
| 56 |
border-radius: 8px;
|
|
@@ -59,26 +56,22 @@ st.markdown(
|
|
| 59 |
background-color: #000000;
|
| 60 |
color: #ECF0F1;
|
| 61 |
}
|
| 62 |
-
|
| 63 |
.stMarkdown>div>p {
|
| 64 |
color: #D0D3D4;
|
| 65 |
font-size: 16px;
|
| 66 |
line-height: 1.6;
|
| 67 |
}
|
| 68 |
-
|
| 69 |
.stMarkdown>h1, .stMarkdown>h2, .stMarkdown>h3, .stMarkdown>h4, .stMarkdown>h5, .stMarkdown>h6 {
|
| 70 |
color: #FF6F61;
|
| 71 |
font-family: 'Poppins', sans-serif;
|
| 72 |
font-weight: bold;
|
| 73 |
text-transform: uppercase;
|
| 74 |
}
|
| 75 |
-
|
| 76 |
.stAudio {
|
| 77 |
margin-top: 20px;
|
| 78 |
border: 2px solid #FF6F61;
|
| 79 |
border-radius: 10px;
|
| 80 |
}
|
| 81 |
-
|
| 82 |
.stFileUploader>div>div>input {
|
| 83 |
border: 2px solid #FFD700;
|
| 84 |
border-radius: 8px;
|
|
@@ -87,7 +80,6 @@ st.markdown(
|
|
| 87 |
background-color: #000000;
|
| 88 |
color: #ECF0F1;
|
| 89 |
}
|
| 90 |
-
|
| 91 |
.spinner {
|
| 92 |
border: 8px solid #f3f3f3;
|
| 93 |
border-top: 8px solid #FF6F61;
|
|
@@ -96,20 +88,17 @@ st.markdown(
|
|
| 96 |
height: 60px;
|
| 97 |
animation: spin 1s linear infinite;
|
| 98 |
}
|
| 99 |
-
|
| 100 |
@keyframes spin {
|
| 101 |
0% { transform: rotate(0deg); }
|
| 102 |
100% { transform: rotate(360deg); }
|
| 103 |
}
|
| 104 |
-
|
| 105 |
.video-container {
|
| 106 |
border: 3px solid #FF6F61;
|
| 107 |
background-color: #1C1C1C;
|
| 108 |
padding: 10px;
|
| 109 |
border-radius: 10px;
|
| 110 |
-
margin-bottom: 20px
|
| 111 |
}
|
| 112 |
-
|
| 113 |
.assistant-response {
|
| 114 |
font-size: 16px;
|
| 115 |
color: #D0D3D4;
|
|
@@ -219,197 +208,4 @@ def extraer_texto_pdf(pdf_path):
|
|
| 219 |
|
| 220 |
# Función "La conexión" para generar oraciones del PDF
|
| 221 |
def generar_oracion_desde_pdf():
|
| 222 |
-
pdf_path = "diario-de-oraciones.pdf" # Ruta
|
| 223 |
-
texto_pdf = extraer_texto_pdf(pdf_path)
|
| 224 |
-
prompt = f"Genera una oración inspiradora basada en el siguiente texto: {texto_pdf[:2000]}" # Limitar a los primeros 2000 caracteres
|
| 225 |
-
respuesta = obtener_respuesta(prompt)
|
| 226 |
-
return respuesta
|
| 227 |
-
|
| 228 |
-
# Función para generar y descargar un PDF con la entrada del diario
|
| 229 |
-
def generar_pdf(fecha, versiculo, rema, investigacion, reflexion):
|
| 230 |
-
pdf = FPDF()
|
| 231 |
-
pdf.add_page()
|
| 232 |
-
pdf.set_font("Arial", size=12)
|
| 233 |
-
pdf.set_fill_color(230, 230, 230)
|
| 234 |
-
pdf.set_text_color(0, 0, 0)
|
| 235 |
-
pdf.image("flores.png", x=10, y=8, w=190) # Puedes cambiar la imagen por otra
|
| 236 |
-
pdf.ln(20)
|
| 237 |
-
pdf.cell(0, 10, f"Fecha: {fecha}", ln=True, fill=True)
|
| 238 |
-
pdf.cell(0, 10, f"Versículo: {versiculo}", ln=True, fill=True)
|
| 239 |
-
pdf.cell(0, 10, "Rema:", ln=True, fill=True)
|
| 240 |
-
pdf.multi_cell(0, 10, rema, fill=True)
|
| 241 |
-
pdf.cell(0, 10, "Investigación:", ln=True, fill=True)
|
| 242 |
-
pdf.multi_cell(0, 10, investigacion, fill=True)
|
| 243 |
-
pdf.cell(0, 10, "Reflexión:", ln=True, fill=True)
|
| 244 |
-
pdf.multi_cell(0, 10, reflexion, fill=True)
|
| 245 |
-
|
| 246 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
| 247 |
-
pdf.output(tmpfile.name)
|
| 248 |
-
return tmpfile.name
|
| 249 |
-
|
| 250 |
-
if page == "Página Principal":
|
| 251 |
-
# Video de YouTube que se reproduce automáticamente
|
| 252 |
-
st.markdown(
|
| 253 |
-
"""
|
| 254 |
-
<iframe width="560" height="315" src="https://www.youtube.com/embed/dPRrJ8za3qU?autoplay=1&mute=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
|
| 255 |
-
""",
|
| 256 |
-
unsafe_allow_html=True,
|
| 257 |
-
)
|
| 258 |
-
|
| 259 |
-
elif page == "Chat Asistente":
|
| 260 |
-
# Chat con el asistente
|
| 261 |
-
st.subheader("🗣️ Chat con el Asistente")
|
| 262 |
-
if 'mensajes' not in st.session_state:
|
| 263 |
-
st.session_state.mensajes = []
|
| 264 |
-
|
| 265 |
-
for mensaje in st.session_state.mensajes:
|
| 266 |
-
with st.chat_message(mensaje["role"]):
|
| 267 |
-
if isinstance(mensaje["content"], str):
|
| 268 |
-
st.markdown(mensaje["content"])
|
| 269 |
-
elif isinstance(mensaje["content"], bytes):
|
| 270 |
-
st.image(mensaje["content"])
|
| 271 |
-
|
| 272 |
-
pregunta_usuario = st.text_input("Escribe tu pregunta sobre la Biblia:", key="pregunta_input")
|
| 273 |
-
imagen_usuario = st.file_uploader("Sube una imagen (opcional):", type=["png", "jpg", "jpeg"])
|
| 274 |
-
|
| 275 |
-
if st.button("Enviar"):
|
| 276 |
-
if pregunta_usuario or imagen_usuario:
|
| 277 |
-
if pregunta_usuario:
|
| 278 |
-
st.session_state.mensajes.append({"role": "user", "content": pregunta_usuario, "timestamp": time.time()})
|
| 279 |
-
with st.chat_message("user"):
|
| 280 |
-
st.markdown(pregunta_usuario)
|
| 281 |
-
|
| 282 |
-
if imagen_usuario:
|
| 283 |
-
imagen_bytes = imagen_usuario.getvalue()
|
| 284 |
-
st.session_state.mensajes.append({"role": "user", "content": imagen_bytes, "timestamp": time.time()})
|
| 285 |
-
with st.chat_message("user"):
|
| 286 |
-
st.image(imagen_bytes)
|
| 287 |
-
|
| 288 |
-
# Limpiar el campo de texto usando JavaScript para evitar el error de modificación del estado
|
| 289 |
-
st.markdown(
|
| 290 |
-
"""
|
| 291 |
-
<script>
|
| 292 |
-
document.querySelector('input[type="text"]').value = "";
|
| 293 |
-
</script>
|
| 294 |
-
""",
|
| 295 |
-
unsafe_allow_html=True,
|
| 296 |
-
)
|
| 297 |
-
|
| 298 |
-
with st.spinner("Meditando su respuesta..."):
|
| 299 |
-
with st.empty():
|
| 300 |
-
spinner = st.markdown('<div class="spinner"></div>', unsafe_allow_html=True)
|
| 301 |
-
time.sleep(2) # Simulación del tiempo de procesamiento
|
| 302 |
-
spinner.empty()
|
| 303 |
-
|
| 304 |
-
if pregunta_usuario:
|
| 305 |
-
respuesta = generar_reflexion(pregunta_usuario)
|
| 306 |
-
st.session_state.mensajes.append({"role": "assistant", "content": respuesta, "timestamp": time.time()})
|
| 307 |
-
with st.chat_message("assistant"):
|
| 308 |
-
st.markdown(f'<div class="assistant-response">{respuesta}</div>', unsafe_allow_html=True)
|
| 309 |
-
|
| 310 |
-
# Convertir texto a voz
|
| 311 |
-
audio_base64 = text_to_speech_base64(respuesta)
|
| 312 |
-
if "Error" not in audio_base64:
|
| 313 |
-
audio_html = f"""
|
| 314 |
-
<audio autoplay>
|
| 315 |
-
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
| 316 |
-
</audio>
|
| 317 |
-
"""
|
| 318 |
-
st.markdown(audio_html, unsafe_allow_html=True)
|
| 319 |
-
|
| 320 |
-
# Mostrar imagen aleatoria
|
| 321 |
-
imagen_path = obtener_imagen_aleatoria()
|
| 322 |
-
if imagen_path:
|
| 323 |
-
st.image(imagen_path)
|
| 324 |
-
|
| 325 |
-
# Reproducir video automáticamente
|
| 326 |
-
st.markdown('<div class="video-container">', unsafe_allow_html=True)
|
| 327 |
-
st.markdown(
|
| 328 |
-
"""
|
| 329 |
-
<video autoplay loop muted playsinline style="width: 100%;">
|
| 330 |
-
<source src="https://cdn.pika.art/v1/3d0aafad-36b6-4341-b2bf-b4d5fbcf0445/Hola_bienvenido_a_este_maravilloso_programa._Donde_podr_s_conocer_y_profundizar_m_s_en_la_palabra_de_seed3422648958323119.mp4" type="video/mp4">
|
| 331 |
-
</video>
|
| 332 |
-
""",
|
| 333 |
-
unsafe_allow_html=True,
|
| 334 |
-
)
|
| 335 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 336 |
-
else:
|
| 337 |
-
st.warning("Por favor, ingresa una pregunta antes de enviar.")
|
| 338 |
-
|
| 339 |
-
elif page == "Generador de Frases Bíblicas":
|
| 340 |
-
# Función para generar una imagen y reflexión
|
| 341 |
-
def generar_imagen_y_reflexion(keyword):
|
| 342 |
-
try:
|
| 343 |
-
reflexion = generar_reflexion(keyword)
|
| 344 |
-
audio_base64 = text_to_speech_base64(reflexion)
|
| 345 |
-
if "Error" not in audio_base64:
|
| 346 |
-
imagen_path = obtener_imagen_aleatoria()
|
| 347 |
-
if imagen_path:
|
| 348 |
-
st.image(imagen_path)
|
| 349 |
-
st.markdown(f'<div class="assistant-response">{reflexion}</div>', unsafe_allow_html=True)
|
| 350 |
-
audio_html = f"""
|
| 351 |
-
<audio autoplay>
|
| 352 |
-
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
| 353 |
-
</audio>
|
| 354 |
-
"""
|
| 355 |
-
st.markdown(audio_html, unsafe_allow_html=True)
|
| 356 |
-
except Exception as e:
|
| 357 |
-
st.error(f"Error al generar la imagen y reflexión: {e}")
|
| 358 |
-
|
| 359 |
-
st.subheader("✨ Generador de Frases Bíblicas")
|
| 360 |
-
keyword = st.text_input("Introduce una palabra clave:")
|
| 361 |
-
if st.button("Generar"):
|
| 362 |
-
if keyword:
|
| 363 |
-
generar_imagen_y_reflexion(keyword)
|
| 364 |
-
else:
|
| 365 |
-
st.warning("Por favor, introduce una palabra clave.")
|
| 366 |
-
|
| 367 |
-
elif page == "Recibir Reflexión":
|
| 368 |
-
st.subheader("🔊 Recibir Reflexión")
|
| 369 |
-
if st.button("Reproducir Reflexión"):
|
| 370 |
-
audio_base64, audio_nombre = obtener_audio_aleatorio()
|
| 371 |
-
if audio_base64:
|
| 372 |
-
st.markdown(f"Reproduciendo: {audio_nombre}")
|
| 373 |
-
audio_html = f"""
|
| 374 |
-
<audio autoplay>
|
| 375 |
-
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
| 376 |
-
</audio>
|
| 377 |
-
"""
|
| 378 |
-
st.markdown(audio_html, unsafe_allow_html=True)
|
| 379 |
-
else:
|
| 380 |
-
st.warning("No se encontraron reflexiones en la carpeta especificada.")
|
| 381 |
-
|
| 382 |
-
elif page == "La conexión":
|
| 383 |
-
st.subheader("🙏 La conexión: Generador de Oraciones")
|
| 384 |
-
if st.button("Generar Oración"):
|
| 385 |
-
oracion = generar_oracion_desde_pdf()
|
| 386 |
-
st.markdown(f'<div class="assistant-response">{oracion}</div>', unsafe_allow_html=True)
|
| 387 |
-
audio_base64 = text_to_speech_base64(oracion)
|
| 388 |
-
if "Error" not in audio_base64:
|
| 389 |
-
audio_html = f"""
|
| 390 |
-
<audio autoplay>
|
| 391 |
-
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
| 392 |
-
</audio>
|
| 393 |
-
"""
|
| 394 |
-
st.markdown(audio_html, unsafe_allow_html=True)
|
| 395 |
-
|
| 396 |
-
elif page == "Diario Reflexivo":
|
| 397 |
-
st.subheader("📔 Diario Reflexivo")
|
| 398 |
-
with st.form("diario_reflexivo_form"):
|
| 399 |
-
fecha = st.date_input("Fecha")
|
| 400 |
-
versiculo = st.text_input("Versículo")
|
| 401 |
-
rema = st.text_area("Rema")
|
| 402 |
-
investigacion = st.text_area("Investigación en la palabra de Dios")
|
| 403 |
-
reflexion = st.text_area("Reflexión")
|
| 404 |
-
|
| 405 |
-
submit_button = st.form_submit_button(label="Guardar en PDF")
|
| 406 |
-
|
| 407 |
-
if submit_button:
|
| 408 |
-
pdf_path = generar_pdf(fecha, versiculo, rema, investigacion, reflexion)
|
| 409 |
-
with open(pdf_path, "rb") as f:
|
| 410 |
-
st.download_button(
|
| 411 |
-
label="Descargar Diario Reflexivo en PDF",
|
| 412 |
-
data=f,
|
| 413 |
-
file_name="diario_reflexivo.pdf",
|
| 414 |
-
mime="application/pdf"
|
| 415 |
-
)
|
|
|
|
| 27 |
"""
|
| 28 |
<style>
|
| 29 |
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap');
|
|
|
|
| 30 |
body {
|
| 31 |
background-color: #1C1C1C;
|
| 32 |
color: #ECF0F1;
|
|
|
|
| 34 |
background-size: cover;
|
| 35 |
font-family: 'Poppins', sans-serif;
|
| 36 |
}
|
|
|
|
| 37 |
.stButton>button {
|
| 38 |
background-color: #007BFF;
|
| 39 |
color: #FFD700;
|
|
|
|
| 48 |
background-color: #0056b3;
|
| 49 |
transform: scale(1.05);
|
| 50 |
}
|
|
|
|
| 51 |
.stTextInput>div>div>input {
|
| 52 |
border: 2px solid #FFD700;
|
| 53 |
border-radius: 8px;
|
|
|
|
| 56 |
background-color: #000000;
|
| 57 |
color: #ECF0F1;
|
| 58 |
}
|
|
|
|
| 59 |
.stMarkdown>div>p {
|
| 60 |
color: #D0D3D4;
|
| 61 |
font-size: 16px;
|
| 62 |
line-height: 1.6;
|
| 63 |
}
|
|
|
|
| 64 |
.stMarkdown>h1, .stMarkdown>h2, .stMarkdown>h3, .stMarkdown>h4, .stMarkdown>h5, .stMarkdown>h6 {
|
| 65 |
color: #FF6F61;
|
| 66 |
font-family: 'Poppins', sans-serif;
|
| 67 |
font-weight: bold;
|
| 68 |
text-transform: uppercase;
|
| 69 |
}
|
|
|
|
| 70 |
.stAudio {
|
| 71 |
margin-top: 20px;
|
| 72 |
border: 2px solid #FF6F61;
|
| 73 |
border-radius: 10px;
|
| 74 |
}
|
|
|
|
| 75 |
.stFileUploader>div>div>input {
|
| 76 |
border: 2px solid #FFD700;
|
| 77 |
border-radius: 8px;
|
|
|
|
| 80 |
background-color: #000000;
|
| 81 |
color: #ECF0F1;
|
| 82 |
}
|
|
|
|
| 83 |
.spinner {
|
| 84 |
border: 8px solid #f3f3f3;
|
| 85 |
border-top: 8px solid #FF6F61;
|
|
|
|
| 88 |
height: 60px;
|
| 89 |
animation: spin 1s linear infinite;
|
| 90 |
}
|
|
|
|
| 91 |
@keyframes spin {
|
| 92 |
0% { transform: rotate(0deg); }
|
| 93 |
100% { transform: rotate(360deg); }
|
| 94 |
}
|
|
|
|
| 95 |
.video-container {
|
| 96 |
border: 3px solid #FF6F61;
|
| 97 |
background-color: #1C1C1C;
|
| 98 |
padding: 10px;
|
| 99 |
border-radius: 10px;
|
| 100 |
+
margin-bottom: 20px.
|
| 101 |
}
|
|
|
|
| 102 |
.assistant-response {
|
| 103 |
font-size: 16px;
|
| 104 |
color: #D0D3D4;
|
|
|
|
| 208 |
|
| 209 |
# Función "La conexión" para generar oraciones del PDF
|
| 210 |
def generar_oracion_desde_pdf():
|
| 211 |
+
pdf_path = "diario-de-oraciones.pdf" # Ruta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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