Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,19 +19,18 @@ genai.configure(api_key=os.getenv("AIzaSyCXSnXFNarDiECkKIbVjoEdFxEIFP-P14U"))
|
|
| 19 |
# Configuraci贸n de Streamlit
|
| 20 |
st.set_page_config(page_title="Asistente Teol贸gico", page_icon="馃摉")
|
| 21 |
|
| 22 |
-
# Estilos CSS personalizados
|
| 23 |
st.markdown(
|
| 24 |
"""
|
| 25 |
<style>
|
| 26 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
.stButton>button {
|
| 36 |
background-color: #4CAF50;
|
| 37 |
color: white;
|
|
@@ -49,46 +48,46 @@ st.markdown(
|
|
| 49 |
color: black;
|
| 50 |
max-height: 300px;
|
| 51 |
overflow-y: auto;
|
| 52 |
-
font-size: 16px
|
| 53 |
}
|
| 54 |
.stMarkdown>h1, .stMarkdown>h2, .stMarkdown>h3, .stMarkdown>h4, .stMarkdown>h5, .stMarkdown>h6 {
|
| 55 |
color: white;
|
| 56 |
font-weight: bold;
|
| 57 |
-
font-style: italic
|
| 58 |
}
|
| 59 |
.stAudio {
|
| 60 |
margin-top: 20px;
|
| 61 |
-
border: 2px solid #4CAF50
|
| 62 |
-
border-radius: 10px
|
| 63 |
}
|
| 64 |
.stFileUploader>div>div>input {
|
| 65 |
-
border: 1px solid #4CAF50
|
| 66 |
-
border-radius: 10px
|
| 67 |
-
font-size: 16px
|
| 68 |
}
|
| 69 |
.spinner {
|
| 70 |
-
border: 8px solid #f3f3f3
|
| 71 |
-
border-top: 8px solid #4CAF50
|
| 72 |
-
border-radius: 50%
|
| 73 |
-
width: 60px
|
| 74 |
-
height: 60px
|
| 75 |
-
animation: spin 1s linear infinite
|
| 76 |
}
|
| 77 |
@keyframes spin {
|
| 78 |
-
0% { transform: rotate(0deg)
|
| 79 |
-
100% { transform: rotate(360deg)
|
| 80 |
}
|
| 81 |
.video-container {
|
| 82 |
-
border: 3px solid blue
|
| 83 |
-
background-color: gold
|
| 84 |
-
padding: 10px
|
| 85 |
-
border-radius: 10px
|
| 86 |
-
margin-bottom: 20px
|
| 87 |
}
|
| 88 |
.assistant-response {
|
| 89 |
-
max-height: 200px
|
| 90 |
-
overflow-y: auto
|
| 91 |
-
font-size: 16px
|
| 92 |
}
|
| 93 |
</style>
|
| 94 |
""",
|
|
@@ -115,10 +114,12 @@ def listar_imagenes(carpeta):
|
|
| 115 |
imagenes.append(os.path.join(carpeta, archivo))
|
| 116 |
return imagenes
|
| 117 |
|
|
|
|
| 118 |
def generar_reflexion(keyword):
|
| 119 |
prompt = f"Genera una reflexi贸n inspiradora sobre {keyword} en el contexto de la espiritualidad y la Biblia."
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
return respuesta
|
| 123 |
|
| 124 |
# Funci贸n para convertir texto a voz
|
|
@@ -134,7 +135,7 @@ def text_to_speech_base64(text):
|
|
| 134 |
def obtener_audio_aleatorio():
|
| 135 |
carpeta_reflexiones = "reflexiones" # Cambia esta ruta por la correcta
|
| 136 |
archivos = os.listdir(carpeta_reflexiones)
|
| 137 |
-
archivos_mp3 = [archivo for archivo in archivos
|
| 138 |
if archivos_mp3:
|
| 139 |
audio_seleccionado = random.choice(archivos_mp3)
|
| 140 |
with open(os.path.join(carpeta_reflexiones, audio_seleccionado), "rb") as audio_file:
|
|
@@ -142,11 +143,6 @@ def obtener_audio_aleatorio():
|
|
| 142 |
return base64.b64encode(audio_bytes).decode("utf-8"), audio_seleccionado
|
| 143 |
return None, None
|
| 144 |
|
| 145 |
-
def google_gemini_api_request(prompt):
|
| 146 |
-
model = genai.GenerativeModel('models/gemini-1.5-pro') # Reemplaza con el ID real
|
| 147 |
-
response = model.generate_content(prompt=prompt)
|
| 148 |
-
return response
|
| 149 |
-
|
| 150 |
# Funci贸n para extraer texto de un PDF
|
| 151 |
def extraer_texto_pdf(pdf_path):
|
| 152 |
text = ""
|
|
@@ -161,8 +157,9 @@ def generar_oracion_desde_pdf():
|
|
| 161 |
pdf_path = "diario-de-oraciones.pdf" # Ruta al PDF
|
| 162 |
texto_pdf = extraer_texto_pdf(pdf_path)
|
| 163 |
prompt = f"Genera una oraci贸n inspiradora basada en el siguiente texto: {texto_pdf[:2000]}" # Limitar a los primeros 2000 caracteres
|
| 164 |
-
|
| 165 |
-
|
|
|
|
| 166 |
return respuesta
|
| 167 |
|
| 168 |
# Funci贸n para generar y descargar un PDF con la entrada del diario
|
|
@@ -178,9 +175,12 @@ def generar_pdf(fecha, versiculo, rema, investigacion, reflexion):
|
|
| 178 |
pdf.cell(0, 10, f"Vers铆culo: {versiculo}", ln=True, fill=True)
|
| 179 |
pdf.cell(0, 10, "Rema:", ln=True, fill=True)
|
| 180 |
pdf.multi_cell(0, 10, rema, fill=True)
|
| 181 |
-
pdf.cell(0, 10, "Investigaci贸n:",
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
| 184 |
pdf.output(tmpfile.name)
|
| 185 |
return tmpfile.name
|
| 186 |
|
|
@@ -239,7 +239,10 @@ elif page == "Chat Asistente":
|
|
| 239 |
spinner.empty()
|
| 240 |
|
| 241 |
if pregunta_usuario:
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
| 243 |
st.session_state.mensajes.append({"role": "assistant", "content": respuesta, "timestamp": time.time()})
|
| 244 |
with st.chat_message("assistant"):
|
| 245 |
st.markdown(f'<div class="assistant-response">{respuesta}</div>', unsafe_allow_html=True)
|
|
@@ -272,7 +275,7 @@ elif page == "Generador de Frases B铆blicas":
|
|
| 272 |
def generar_imagen_y_reflexion(keyword):
|
| 273 |
try:
|
| 274 |
reflexion = generar_reflexion(keyword)
|
| 275 |
-
audio_base64 =
|
| 276 |
imagenes = listar_imagenes("imagenes") # Cambia "imagenes" por la ruta de tu carpeta de im谩genes
|
| 277 |
if imagenes:
|
| 278 |
imagen_seleccionada = random.choice(imagenes)
|
|
@@ -344,4 +347,4 @@ elif page == "Diario Reflexivo":
|
|
| 344 |
data=f,
|
| 345 |
file_name="diario_reflexivo.pdf",
|
| 346 |
mime="application/pdf"
|
| 347 |
-
)
|
|
|
|
| 19 |
# Configuraci贸n de Streamlit
|
| 20 |
st.set_page_config(page_title="Asistente Teol贸gico", page_icon="馃摉")
|
| 21 |
|
| 22 |
+
# Estilos CSS personalizados
|
| 23 |
st.markdown(
|
| 24 |
"""
|
| 25 |
<style>
|
| 26 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 27 |
+
body {
|
| 28 |
+
background-color: #000000;
|
| 29 |
+
color: #ECF0F1;
|
| 30 |
+
background-image: url('https://s1.1zoom.me/big0/395/Fields_Sunrises_and_499477.jpg');
|
| 31 |
+
background-size: cover;
|
| 32 |
+
font-family: 'Roboto', sans-serif;
|
| 33 |
+
}
|
|
|
|
| 34 |
.stButton>button {
|
| 35 |
background-color: #4CAF50;
|
| 36 |
color: white;
|
|
|
|
| 48 |
color: black;
|
| 49 |
max-height: 300px;
|
| 50 |
overflow-y: auto;
|
| 51 |
+
font-size: 16px;
|
| 52 |
}
|
| 53 |
.stMarkdown>h1, .stMarkdown>h2, .stMarkdown>h3, .stMarkdown>h4, .stMarkdown>h5, .stMarkdown>h6 {
|
| 54 |
color: white;
|
| 55 |
font-weight: bold;
|
| 56 |
+
font-style: italic;
|
| 57 |
}
|
| 58 |
.stAudio {
|
| 59 |
margin-top: 20px;
|
| 60 |
+
border: 2px solid #4CAF50;
|
| 61 |
+
border-radius: 10px;
|
| 62 |
}
|
| 63 |
.stFileUploader>div>div>input {
|
| 64 |
+
border: 1px solid #4CAF50;
|
| 65 |
+
border-radius: 10px;
|
| 66 |
+
font-size: 16px;
|
| 67 |
}
|
| 68 |
.spinner {
|
| 69 |
+
border: 8px solid #f3f3f3;
|
| 70 |
+
border-top: 8px solid #4CAF50;
|
| 71 |
+
border-radius: 50%;
|
| 72 |
+
width: 60px;
|
| 73 |
+
height: 60px;
|
| 74 |
+
animation: spin 1s linear infinite;
|
| 75 |
}
|
| 76 |
@keyframes spin {
|
| 77 |
+
0% { transform: rotate(0deg); }
|
| 78 |
+
100% { transform: rotate(360deg); }
|
| 79 |
}
|
| 80 |
.video-container {
|
| 81 |
+
border: 3px solid blue;
|
| 82 |
+
background-color: gold;
|
| 83 |
+
padding: 10px;
|
| 84 |
+
border-radius: 10px;
|
| 85 |
+
margin-bottom: 20px;
|
| 86 |
}
|
| 87 |
.assistant-response {
|
| 88 |
+
max-height: 200px;
|
| 89 |
+
overflow-y: auto;
|
| 90 |
+
font-size: 16px;
|
| 91 |
}
|
| 92 |
</style>
|
| 93 |
""",
|
|
|
|
| 114 |
imagenes.append(os.path.join(carpeta, archivo))
|
| 115 |
return imagenes
|
| 116 |
|
| 117 |
+
# Funci贸n para generar reflexi贸n usando Google Gemini
|
| 118 |
def generar_reflexion(keyword):
|
| 119 |
prompt = f"Genera una reflexi贸n inspiradora sobre {keyword} en el contexto de la espiritualidad y la Biblia."
|
| 120 |
+
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
|
| 121 |
+
response = model.generate_content([prompt])
|
| 122 |
+
respuesta = response[0]['text']
|
| 123 |
return respuesta
|
| 124 |
|
| 125 |
# Funci贸n para convertir texto a voz
|
|
|
|
| 135 |
def obtener_audio_aleatorio():
|
| 136 |
carpeta_reflexiones = "reflexiones" # Cambia esta ruta por la correcta
|
| 137 |
archivos = os.listdir(carpeta_reflexiones)
|
| 138 |
+
archivos_mp3 = [archivo for archivo in archivos if archivo.endswith(".mp3")]
|
| 139 |
if archivos_mp3:
|
| 140 |
audio_seleccionado = random.choice(archivos_mp3)
|
| 141 |
with open(os.path.join(carpeta_reflexiones, audio_seleccionado), "rb") as audio_file:
|
|
|
|
| 143 |
return base64.b64encode(audio_bytes).decode("utf-8"), audio_seleccionado
|
| 144 |
return None, None
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
# Funci贸n para extraer texto de un PDF
|
| 147 |
def extraer_texto_pdf(pdf_path):
|
| 148 |
text = ""
|
|
|
|
| 157 |
pdf_path = "diario-de-oraciones.pdf" # Ruta al PDF
|
| 158 |
texto_pdf = extraer_texto_pdf(pdf_path)
|
| 159 |
prompt = f"Genera una oraci贸n inspiradora basada en el siguiente texto: {texto_pdf[:2000]}" # Limitar a los primeros 2000 caracteres
|
| 160 |
+
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
|
| 161 |
+
response = model.generate_content([prompt])
|
| 162 |
+
respuesta = response[0]['text']
|
| 163 |
return respuesta
|
| 164 |
|
| 165 |
# Funci贸n para generar y descargar un PDF con la entrada del diario
|
|
|
|
| 175 |
pdf.cell(0, 10, f"Vers铆culo: {versiculo}", ln=True, fill=True)
|
| 176 |
pdf.cell(0, 10, "Rema:", ln=True, fill=True)
|
| 177 |
pdf.multi_cell(0, 10, rema, fill=True)
|
| 178 |
+
pdf.cell(0, 10, "Investigaci贸n:", ln=True, fill=True)
|
| 179 |
+
pdf.multi_cell(0, 10, investigacion, fill=True)
|
| 180 |
+
pdf.cell(0, 10, "Reflexi贸n:", ln=True, fill=True)
|
| 181 |
+
pdf.multi_cell(0, 10, reflexion, fill=True)
|
| 182 |
|
| 183 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
| 184 |
pdf.output(tmpfile.name)
|
| 185 |
return tmpfile.name
|
| 186 |
|
|
|
|
| 239 |
spinner.empty()
|
| 240 |
|
| 241 |
if pregunta_usuario:
|
| 242 |
+
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
|
| 243 |
+
prompt = f"Genera una reflexi贸n inspiradora basada en la pregunta: {pregunta_usuario}"
|
| 244 |
+
response = model.generate_content([prompt])
|
| 245 |
+
respuesta = response[0]['text']
|
| 246 |
st.session_state.mensajes.append({"role": "assistant", "content": respuesta, "timestamp": time.time()})
|
| 247 |
with st.chat_message("assistant"):
|
| 248 |
st.markdown(f'<div class="assistant-response">{respuesta}</div>', unsafe_allow_html=True)
|
|
|
|
| 275 |
def generar_imagen_y_reflexion(keyword):
|
| 276 |
try:
|
| 277 |
reflexion = generar_reflexion(keyword)
|
| 278 |
+
audio_base64 = text_to_speech_base64(reflexion)
|
| 279 |
imagenes = listar_imagenes("imagenes") # Cambia "imagenes" por la ruta de tu carpeta de im谩genes
|
| 280 |
if imagenes:
|
| 281 |
imagen_seleccionada = random.choice(imagenes)
|
|
|
|
| 347 |
data=f,
|
| 348 |
file_name="diario_reflexivo.pdf",
|
| 349 |
mime="application/pdf"
|
| 350 |
+
)
|