Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,28 +41,28 @@ st.markdown(
|
|
| 41 |
}
|
| 42 |
.stMarkdown>div>p {
|
| 43 |
color: #4CAF50;
|
| 44 |
-
font-weight: bold
|
| 45 |
}
|
| 46 |
.stAudio {
|
| 47 |
margin-top: 20px;
|
| 48 |
border: 2px solid #4CAF50;
|
| 49 |
-
border-radius: 10px
|
| 50 |
}
|
| 51 |
.stFileUploader>div>div>input {
|
| 52 |
-
border: 1px solid #4CAF50
|
| 53 |
-
border-radius: 10px
|
| 54 |
}
|
| 55 |
.spinner {
|
| 56 |
-
border: 8px solid #f3f3f3
|
| 57 |
-
border-top: 8px solid #4CAF50
|
| 58 |
-
border-radius: 50%
|
| 59 |
-
width: 60px
|
| 60 |
-
height: 60px
|
| 61 |
-
animation: spin 1s linear infinite
|
| 62 |
}
|
| 63 |
@keyframes spin {
|
| 64 |
-
0% { transform: rotate(0deg)
|
| 65 |
-
100% { transform: rotate(360deg)
|
| 66 |
}
|
| 67 |
</style>
|
| 68 |
""",
|
|
@@ -135,6 +135,28 @@ def obtener_audio_aleatorio():
|
|
| 135 |
return base64.b64encode(audio_bytes).decode("utf-8")
|
| 136 |
return None
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
if page == "Chat Asistente":
|
| 139 |
# Chat con el asistente
|
| 140 |
st.subheader("🗣️ Chat con el Asistente")
|
|
@@ -196,6 +218,7 @@ elif page == "Gestión de Pedidos":
|
|
| 196 |
if 'pedidos' not in st.session_state:
|
| 197 |
st.session_state.pedidos = []
|
| 198 |
|
|
|
|
| 199 |
pedido_agent = PedidoAgent(menu_csv_path)
|
| 200 |
calculo_pedido_agent = CalculoPedidoAgent()
|
| 201 |
|
|
@@ -208,4 +231,18 @@ elif page == "Generador de Frases Bíblicas":
|
|
| 208 |
try:
|
| 209 |
reflexion, consulta_imagen = generar_reflexion_y_consulta(keyword)
|
| 210 |
image_urls = buscar_imagenes(consulta_imagen)
|
| 211 |
-
for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
.stMarkdown>div>p {
|
| 43 |
color: #4CAF50;
|
| 44 |
+
font-weight: bold;
|
| 45 |
}
|
| 46 |
.stAudio {
|
| 47 |
margin-top: 20px;
|
| 48 |
border: 2px solid #4CAF50;
|
| 49 |
+
border-radius: 10px;
|
| 50 |
}
|
| 51 |
.stFileUploader>div>div>input {
|
| 52 |
+
border: 1px solid #4CAF50;
|
| 53 |
+
border-radius: 10px;
|
| 54 |
}
|
| 55 |
.spinner {
|
| 56 |
+
border: 8px solid #f3f3f3;
|
| 57 |
+
border-top: 8px solid #4CAF50;
|
| 58 |
+
border-radius: 50%;
|
| 59 |
+
width: 60px;
|
| 60 |
+
height: 60px;
|
| 61 |
+
animation: spin 1s linear infinite;
|
| 62 |
}
|
| 63 |
@keyframes spin {
|
| 64 |
+
0% { transform: rotate(0deg); }
|
| 65 |
+
100% { transform: rotate(360deg); }
|
| 66 |
}
|
| 67 |
</style>
|
| 68 |
""",
|
|
|
|
| 135 |
return base64.b64encode(audio_bytes).decode("utf-8")
|
| 136 |
return None
|
| 137 |
|
| 138 |
+
# Función para convertir texto a voz
|
| 139 |
+
def text_to_speech_base64(text):
|
| 140 |
+
client = texttospeech.TextToSpeechClient()
|
| 141 |
+
input_text = texttospeech.SynthesisInput(text=text)
|
| 142 |
+
voice = texttospeech.VoiceSelectionParams(language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL)
|
| 143 |
+
audio_config = texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3)
|
| 144 |
+
response = client.synthesize_speech(input=input_text, voice=voice, audio_config=audio_config)
|
| 145 |
+
return base64.b64encode(response.audio_content).decode("utf-8")
|
| 146 |
+
|
| 147 |
+
# Función para obtener respuesta del asistente
|
| 148 |
+
def obtener_respuesta(pregunta):
|
| 149 |
+
prompt = f"Responde a la siguiente pregunta bíblica: {pregunta}"
|
| 150 |
+
response = openai.ChatCompletion.create(
|
| 151 |
+
model="gpt-4",
|
| 152 |
+
messages=[{"role": "system", "content": "Eres un asistente teológico."},
|
| 153 |
+
{"role": "user", "content": prompt}],
|
| 154 |
+
temperature=0.7,
|
| 155 |
+
max_tokens=200,
|
| 156 |
+
)
|
| 157 |
+
respuesta = response['choices'][0]['message']['content']
|
| 158 |
+
return respuesta
|
| 159 |
+
|
| 160 |
if page == "Chat Asistente":
|
| 161 |
# Chat con el asistente
|
| 162 |
st.subheader("🗣️ Chat con el Asistente")
|
|
|
|
| 218 |
if 'pedidos' not in st.session_state:
|
| 219 |
st.session_state.pedidos = []
|
| 220 |
|
| 221 |
+
# Asumimos que estas clases están definidas en algún otro lado
|
| 222 |
pedido_agent = PedidoAgent(menu_csv_path)
|
| 223 |
calculo_pedido_agent = CalculoPedidoAgent()
|
| 224 |
|
|
|
|
| 231 |
try:
|
| 232 |
reflexion, consulta_imagen = generar_reflexion_y_consulta(keyword)
|
| 233 |
image_urls = buscar_imagenes(consulta_imagen)
|
| 234 |
+
for image_url in image_urls:
|
| 235 |
+
if verificar_imagen(image_url, keyword):
|
| 236 |
+
st.image(image_url)
|
| 237 |
+
st.markdown(reflexion)
|
| 238 |
+
break
|
| 239 |
+
except Exception as e:
|
| 240 |
+
st.error(f"Error al generar la imagen y reflexión: {e}")
|
| 241 |
+
|
| 242 |
+
st.subheader("✨ Generador de Frases Bíblicas")
|
| 243 |
+
keyword = st.text_input("Introduce una palabra clave:")
|
| 244 |
+
if st.button("Generar"):
|
| 245 |
+
if keyword:
|
| 246 |
+
generar_imagen_y_reflexion(keyword)
|
| 247 |
+
else:
|
| 248 |
+
st.warning("Por favor, introduce una palabra clave.")
|