Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from google.cloud import texttospeech
|
|
| 8 |
import PyPDF2
|
| 9 |
from fpdf import FPDF
|
| 10 |
import tempfile
|
|
|
|
| 11 |
|
| 12 |
# Cargar variables de entorno desde el archivo .env
|
| 13 |
load_dotenv()
|
|
@@ -129,11 +130,20 @@ page = st.sidebar.selectbox("Selecciona una p谩gina", ["P谩gina Principal", "Cha
|
|
| 129 |
|
| 130 |
# Funci贸n para generar texto con Groq
|
| 131 |
def generar_texto_groq(prompt):
|
| 132 |
-
# L贸gica para generar texto usando Groq
|
| 133 |
try:
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
except Exception as e:
|
| 138 |
return f"Error en la generaci贸n de texto: {e}"
|
| 139 |
|
|
@@ -319,7 +329,7 @@ elif page == "Generador de Frases B铆blicas":
|
|
| 319 |
imagen_path = obtener_imagen_aleatoria()
|
| 320 |
if imagen_path:
|
| 321 |
st.image(imagen_path)
|
| 322 |
-
st.markdown(reflexion)
|
| 323 |
audio_html = f"""
|
| 324 |
<audio autoplay>
|
| 325 |
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
|
@@ -356,7 +366,7 @@ elif page == "La conexi贸n":
|
|
| 356 |
st.subheader("馃檹 La conexi贸n: Generador de Oraciones")
|
| 357 |
if st.button("Generar Oraci贸n"):
|
| 358 |
oracion = generar_oracion_desde_pdf()
|
| 359 |
-
st.markdown(oracion)
|
| 360 |
audio_base64 = text_to_speech_base64(oracion)
|
| 361 |
if "Error" not in audio_base64:
|
| 362 |
audio_html = f"""
|
|
@@ -386,4 +396,3 @@ elif page == "Diario Reflexivo":
|
|
| 386 |
file_name="diario_reflexivo.pdf",
|
| 387 |
mime="application/pdf"
|
| 388 |
)
|
| 389 |
-
|
|
|
|
| 8 |
import PyPDF2
|
| 9 |
from fpdf import FPDF
|
| 10 |
import tempfile
|
| 11 |
+
import requests # Aseg煤rate de tener instalada la librer铆a requests
|
| 12 |
|
| 13 |
# Cargar variables de entorno desde el archivo .env
|
| 14 |
load_dotenv()
|
|
|
|
| 130 |
|
| 131 |
# Funci贸n para generar texto con Groq
|
| 132 |
def generar_texto_groq(prompt):
|
|
|
|
| 133 |
try:
|
| 134 |
+
headers = {
|
| 135 |
+
"Authorization": f"Bearer {groq_api_key}",
|
| 136 |
+
"Content-Type": "application/json"
|
| 137 |
+
}
|
| 138 |
+
data = {
|
| 139 |
+
"prompt": prompt,
|
| 140 |
+
"max_tokens": 1000,
|
| 141 |
+
"model": "groq_model" # Aseg煤rate de usar el modelo correcto de Groq
|
| 142 |
+
}
|
| 143 |
+
response = requests.post("https://api.groq.com/v1/completions", headers=headers, json=data)
|
| 144 |
+
response.raise_for_status()
|
| 145 |
+
result = response.json()
|
| 146 |
+
return result['choices'][0]['text'].strip()
|
| 147 |
except Exception as e:
|
| 148 |
return f"Error en la generaci贸n de texto: {e}"
|
| 149 |
|
|
|
|
| 329 |
imagen_path = obtener_imagen_aleatoria()
|
| 330 |
if imagen_path:
|
| 331 |
st.image(imagen_path)
|
| 332 |
+
st.markdown(f'<div class="assistant-response">{reflexion}</div>', unsafe_allow_html=True)
|
| 333 |
audio_html = f"""
|
| 334 |
<audio autoplay>
|
| 335 |
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
|
|
|
| 366 |
st.subheader("馃檹 La conexi贸n: Generador de Oraciones")
|
| 367 |
if st.button("Generar Oraci贸n"):
|
| 368 |
oracion = generar_oracion_desde_pdf()
|
| 369 |
+
st.markdown(f'<div class="assistant-response">{oracion}</div>', unsafe_allow_html=True)
|
| 370 |
audio_base64 = text_to_speech_base64(oracion)
|
| 371 |
if "Error" not in audio_base64:
|
| 372 |
audio_html = f"""
|
|
|
|
| 396 |
file_name="diario_reflexivo.pdf",
|
| 397 |
mime="application/pdf"
|
| 398 |
)
|
|
|