Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from dotenv import load_dotenv
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from google.cloud import texttospeech
|
| 10 |
import PyPDF2
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Cargar variables de entorno desde el archivo .env
|
| 13 |
load_dotenv()
|
|
@@ -23,7 +25,7 @@ st.markdown(
|
|
| 23 |
<style>
|
| 24 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 25 |
|
| 26 |
-
}
|
| 27 |
.main {
|
| 28 |
background-color: #000000;
|
| 29 |
color: #ECF0F1;
|
|
@@ -100,7 +102,7 @@ st.markdown("Bienvenido al Asistente Teológico, donde puedes preguntar sobre in
|
|
| 100 |
|
| 101 |
# Barra lateral para la navegación
|
| 102 |
st.sidebar.title("Navegación")
|
| 103 |
-
page = st.sidebar.selectbox("Selecciona una página", ["Chat Asistente", "Generador de Frases Bíblicas", "Recibir Reflexión", "La conexión"])
|
| 104 |
|
| 105 |
# Cargar el modelo de clasificación de imágenes
|
| 106 |
clasificador = pipeline("zero-shot-image-classification")
|
|
@@ -184,7 +186,38 @@ def generar_oracion_desde_pdf():
|
|
| 184 |
respuesta = response['choices'][0]['message']['content']
|
| 185 |
return respuesta
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
# Chat con el asistente
|
| 189 |
st.subheader("🗣️ Chat con el Asistente")
|
| 190 |
if 'mensajes' not in st.session_state:
|
|
@@ -315,3 +348,24 @@ elif page == "La conexión":
|
|
| 315 |
</audio>
|
| 316 |
"""
|
| 317 |
st.markdown(audio_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from google.cloud import texttospeech
|
| 10 |
import PyPDF2
|
| 11 |
+
from fpdf import FPDF
|
| 12 |
+
import tempfile
|
| 13 |
|
| 14 |
# Cargar variables de entorno desde el archivo .env
|
| 15 |
load_dotenv()
|
|
|
|
| 25 |
<style>
|
| 26 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 27 |
|
| 28 |
+
}
|
| 29 |
.main {
|
| 30 |
background-color: #000000;
|
| 31 |
color: #ECF0F1;
|
|
|
|
| 102 |
|
| 103 |
# Barra lateral para la navegación
|
| 104 |
st.sidebar.title("Navegación")
|
| 105 |
+
page = st.sidebar.selectbox("Selecciona una página", ["Página Principal", "Chat Asistente", "Generador de Frases Bíblicas", "Recibir Reflexión", "La conexión", "Diario Reflexivo"])
|
| 106 |
|
| 107 |
# Cargar el modelo de clasificación de imágenes
|
| 108 |
clasificador = pipeline("zero-shot-image-classification")
|
|
|
|
| 186 |
respuesta = response['choices'][0]['message']['content']
|
| 187 |
return respuesta
|
| 188 |
|
| 189 |
+
# Función para generar y descargar un PDF con la entrada del diario
|
| 190 |
+
def generar_pdf(fecha, versiculo, rema, investigacion, reflexion):
|
| 191 |
+
pdf = FPDF()
|
| 192 |
+
pdf.add_page()
|
| 193 |
+
pdf.set_font("Arial", size=12)
|
| 194 |
+
pdf.set_fill_color(230, 230, 230)
|
| 195 |
+
pdf.set_text_color(0, 0, 0)
|
| 196 |
+
pdf.image("flores.png", x=10, y=8, w=190) # Puedes cambiar la imagen por otra
|
| 197 |
+
pdf.ln(20)
|
| 198 |
+
pdf.cell(0, 10, f"Fecha: {fecha}", ln=True, fill=True)
|
| 199 |
+
pdf.cell(0, 10, f"Versículo: {versiculo}", ln=True, fill=True)
|
| 200 |
+
pdf.cell(0, 10, "Rema:", ln=True, fill=True)
|
| 201 |
+
pdf.multi_cell(0, 10, rema, fill=True)
|
| 202 |
+
pdf.cell(0, 10, "Investigación:", ln=True, fill=True)
|
| 203 |
+
pdf.multi_cell(0, 10, investigacion, fill=True)
|
| 204 |
+
pdf.cell(0, 10, "Reflexión:", ln=True, fill=True)
|
| 205 |
+
pdf.multi_cell(0, 10, reflexion, fill=True)
|
| 206 |
+
|
| 207 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
| 208 |
+
pdf.output(tmpfile.name)
|
| 209 |
+
return tmpfile.name
|
| 210 |
+
|
| 211 |
+
if page == "Página Principal":
|
| 212 |
+
# Video de YouTube que se reproduce automáticamente
|
| 213 |
+
st.markdown(
|
| 214 |
+
"""
|
| 215 |
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/dPRrJ8za3qU?autoplay=1&mute=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
|
| 216 |
+
""",
|
| 217 |
+
unsafe_allow_html=True,
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
elif page == "Chat Asistente":
|
| 221 |
# Chat con el asistente
|
| 222 |
st.subheader("🗣️ Chat con el Asistente")
|
| 223 |
if 'mensajes' not in st.session_state:
|
|
|
|
| 348 |
</audio>
|
| 349 |
"""
|
| 350 |
st.markdown(audio_html, unsafe_allow_html=True)
|
| 351 |
+
|
| 352 |
+
elif page == "Diario Reflexivo":
|
| 353 |
+
st.subheader("📔 Diario Reflexivo")
|
| 354 |
+
with st.form("diario_reflexivo_form"):
|
| 355 |
+
fecha = st.date_input("Fecha")
|
| 356 |
+
versiculo = st.text_input("Versículo")
|
| 357 |
+
rema = st.text_area("Rema")
|
| 358 |
+
investigacion = st.text_area("Investigación en la palabra de Dios")
|
| 359 |
+
reflexion = st.text_area("Reflexión")
|
| 360 |
+
|
| 361 |
+
submit_button = st.form_submit_button(label="Guardar en PDF")
|
| 362 |
+
|
| 363 |
+
if submit_button:
|
| 364 |
+
pdf_path = generar_pdf(fecha, versiculo, rema, investigacion, reflexion)
|
| 365 |
+
with open(pdf_path, "rb") as f:
|
| 366 |
+
st.download_button(
|
| 367 |
+
label="Descargar Diario Reflexivo en PDF",
|
| 368 |
+
data=f,
|
| 369 |
+
file_name="diario_reflexivo.pdf",
|
| 370 |
+
mime="application/pdf"
|
| 371 |
+
)
|