Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ import time
|
|
| 12 |
from google.cloud import texttospeech
|
| 13 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode
|
| 14 |
from Historial.historial_chat import cargar_historial, guardar_historial
|
| 15 |
-
from agent_functions import
|
| 16 |
|
| 17 |
# Configuración de NLTK
|
| 18 |
nltk.download('punkt')
|
|
@@ -221,60 +221,52 @@ def main():
|
|
| 221 |
|
| 222 |
elif pagina == "Agentes":
|
| 223 |
st.subheader("📋 Menú y Pedidos")
|
| 224 |
-
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
st.write(menu_df)
|
| 230 |
|
| 231 |
-
|
| 232 |
-
if
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
else:
|
| 235 |
-
|
| 236 |
-
st.markdown("Selecciona los items del menú:")
|
| 237 |
-
items_seleccionados = st.multiselect("Items", menu_df['item'].tolist())
|
| 238 |
-
|
| 239 |
-
if st.button("Tomar Pedido"):
|
| 240 |
-
if items_seleccionados:
|
| 241 |
-
pedido_usuario = ','.join(items_seleccionados)
|
| 242 |
-
confirmados = tomar_pedido_agente(pedido_usuario, menu_df)
|
| 243 |
-
st.info(f"Pedido confirmado: {confirmados}")
|
| 244 |
-
|
| 245 |
-
total = procesar_orden_agente(','.join(confirmados), menu_df)
|
| 246 |
-
st.success(f"Total del pedido: ${total}")
|
| 247 |
-
|
| 248 |
-
# Generar PDF de la orden
|
| 249 |
-
order_details = {item: {'price': menu_df[menu_df['item'] == item]['price'].values[0]} for item in confirmados}
|
| 250 |
-
pdf_path = generar_pdf_orden(order_details)
|
| 251 |
-
st.markdown(f"[Descargar PDF de la Orden]({pdf_path})", unsafe_allow_html=True)
|
| 252 |
-
|
| 253 |
-
# --- Chat para Agentes ---
|
| 254 |
-
st.subheader("Chat con Agentes")
|
| 255 |
-
if 'mensajes_agente' not in st.session_state:
|
| 256 |
-
st.session_state.mensajes_agente = []
|
| 257 |
-
|
| 258 |
-
for mensaje in st.session_state.mensajes_agente:
|
| 259 |
-
with st.chat_message(mensaje["role"]):
|
| 260 |
-
st.markdown(mensaje["content"])
|
| 261 |
-
|
| 262 |
-
agente_pregunta = st.text_input("Escribe tu pregunta para el agente:")
|
| 263 |
-
if st.button("Enviar al Agente"):
|
| 264 |
-
if agente_pregunta:
|
| 265 |
-
st.session_state.mensajes_agente.append({"role": "user", "content": agente_pregunta, "timestamp": time.time()})
|
| 266 |
-
with st.chat_message("user"):
|
| 267 |
-
st.markdown(agente_pregunta)
|
| 268 |
-
|
| 269 |
-
# Procesar la respuesta del agente
|
| 270 |
-
with st.spinner("El agente está respondiendo..."):
|
| 271 |
-
respuesta_agente, audio_path = obtener_respuesta(agente_pregunta, '', modelo="gpt-4", temperatura=0.5)
|
| 272 |
-
st.session_state.mensajes_agente.append({"role": "assistant", "content": respuesta_agente, "timestamp": time.time()})
|
| 273 |
-
with st.chat_message("assistant"):
|
| 274 |
-
st.markdown(respuesta_agente)
|
| 275 |
-
st.audio(audio_path, format="audio/mp3", start_time=0)
|
| 276 |
-
else:
|
| 277 |
-
st.warning("Por favor, ingresa una pregunta antes de enviar.")
|
| 278 |
|
| 279 |
if __name__ == "__main__":
|
| 280 |
main()
|
|
|
|
| 12 |
from google.cloud import texttospeech
|
| 13 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode
|
| 14 |
from Historial.historial_chat import cargar_historial, guardar_historial
|
| 15 |
+
from agent_functions import menu_df, tomar_pedido_agente, procesar_orden_agente, generar_pdf_orden, obtener_respuesta
|
| 16 |
|
| 17 |
# Configuración de NLTK
|
| 18 |
nltk.download('punkt')
|
|
|
|
| 221 |
|
| 222 |
elif pagina == "Agentes":
|
| 223 |
st.subheader("📋 Menú y Pedidos")
|
| 224 |
+
st.success("Menú cargado exitosamente. Listo para tomar pedidos.")
|
| 225 |
+
st.write(menu_df)
|
| 226 |
|
| 227 |
+
# Captura de pedido
|
| 228 |
+
st.markdown("Selecciona los items del menú:")
|
| 229 |
+
items_seleccionados = st.multiselect("Items", menu_df['item'].tolist())
|
|
|
|
| 230 |
|
| 231 |
+
if st.button("Tomar Pedido"):
|
| 232 |
+
if items_seleccionados:
|
| 233 |
+
pedido_usuario = ','.join(items_seleccionados)
|
| 234 |
+
confirmados = tomar_pedido_agente(pedido_usuario)
|
| 235 |
+
st.info(f"Pedido confirmado: {confirmados}")
|
| 236 |
+
|
| 237 |
+
total = procesar_orden_agente(','.join(confirmados))
|
| 238 |
+
st.success(f"Total del pedido: ${total}")
|
| 239 |
+
|
| 240 |
+
# Generar PDF de la orden
|
| 241 |
+
order_details = {item: {'price': menu_df[menu_df['item'] == item]['price'].values[0]} for item in confirmados}
|
| 242 |
+
pdf_path = generar_pdf_orden(order_details)
|
| 243 |
+
st.markdown(f"[Descargar PDF de la Orden]({pdf_path})", unsafe_allow_html=True)
|
| 244 |
+
|
| 245 |
+
# --- Chat para Agentes ---
|
| 246 |
+
st.subheader("Chat con Agentes")
|
| 247 |
+
if 'mensajes_agente' not in st.session_state:
|
| 248 |
+
st.session_state.mensajes_agente = []
|
| 249 |
+
|
| 250 |
+
for mensaje in st.session_state.mensajes_agente:
|
| 251 |
+
with st.chat_message(mensaje["role"]):
|
| 252 |
+
st.markdown(mensaje["content"])
|
| 253 |
+
|
| 254 |
+
agente_pregunta = st.text_input("Escribe tu pregunta para el agente:")
|
| 255 |
+
if st.button("Enviar al Agente"):
|
| 256 |
+
if agente_pregunta:
|
| 257 |
+
st.session_state.mensajes_agente.append({"role": "user", "content": agente_pregunta, "timestamp": time.time()})
|
| 258 |
+
with st.chat_message("user"):
|
| 259 |
+
st.markdown(agente_pregunta)
|
| 260 |
+
|
| 261 |
+
# Procesar la respuesta del agente
|
| 262 |
+
with st.spinner("El agente está respondiendo..."):
|
| 263 |
+
respuesta_agente, audio_path = obtener_respuesta(agente_pregunta, '', modelo="gpt-4", temperatura=0.5)
|
| 264 |
+
st.session_state.mensajes_agente.append({"role": "assistant", "content": respuesta_agente, "timestamp": time.time()})
|
| 265 |
+
with st.chat_message("assistant"):
|
| 266 |
+
st.markdown(respuesta_agente)
|
| 267 |
+
st.audio(audio_path, format="audio/mp3", start_time=0)
|
| 268 |
else:
|
| 269 |
+
st.warning("Por favor, ingresa una pregunta antes de enviar.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
if __name__ == "__main__":
|
| 272 |
main()
|