Spaces:
Sleeping
Sleeping
Update utils/data_manager.py
Browse files- utils/data_manager.py +98 -3
utils/data_manager.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
| 1 |
-
# data_manager.py
|
| 2 |
-
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
class PedidoAgent:
|
| 7 |
def __init__(self, menu_csv_path):
|
| 8 |
self.menu_csv_path = menu_csv_path
|
|
@@ -54,4 +60,93 @@ class CalculoPedidoAgent:
|
|
| 54 |
total = df_pedidos["Cantidad"].mul(df_pedidos["Precio"]).sum()
|
| 55 |
st.markdown(f"**Total: ${total:.2f}**")
|
| 56 |
else:
|
| 57 |
-
st.info("El pedido está vacío.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import openai
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Configuración de la clave API
|
| 8 |
+
load_dotenv()
|
| 9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
|
| 11 |
+
# Clases para la gestión de pedidos
|
| 12 |
class PedidoAgent:
|
| 13 |
def __init__(self, menu_csv_path):
|
| 14 |
self.menu_csv_path = menu_csv_path
|
|
|
|
| 60 |
total = df_pedidos["Cantidad"].mul(df_pedidos["Precio"]).sum()
|
| 61 |
st.markdown(f"**Total: ${total:.2f}**")
|
| 62 |
else:
|
| 63 |
+
st.info("El pedido está vacío.")
|
| 64 |
+
|
| 65 |
+
# Función para obtener respuesta de OpenAI
|
| 66 |
+
def obtener_respuesta(pregunta, modelo="gpt-4", temperatura=0.5):
|
| 67 |
+
respuesta = openai.Completion.create(
|
| 68 |
+
engine=modelo,
|
| 69 |
+
prompt=f"Pregunta: {pregunta}\nRespuesta:",
|
| 70 |
+
max_tokens=150,
|
| 71 |
+
temperature=temperatura,
|
| 72 |
+
).choices[0].text.strip()
|
| 73 |
+
return respuesta
|
| 74 |
+
|
| 75 |
+
# Configuración de Streamlit
|
| 76 |
+
st.set_page_config(page_title="Asistente Teológico", page_icon="📖")
|
| 77 |
+
|
| 78 |
+
# Estilos CSS personalizados
|
| 79 |
+
st.markdown(
|
| 80 |
+
"""
|
| 81 |
+
<style>
|
| 82 |
+
body {
|
| 83 |
+
background: #f2f3f5;
|
| 84 |
+
color: #333;
|
| 85 |
+
}
|
| 86 |
+
.stButton>button {
|
| 87 |
+
background-color: #4CAF50;
|
| 88 |
+
color: white;
|
| 89 |
+
border-radius: 10px;
|
| 90 |
+
}
|
| 91 |
+
.stTextInput>div>div>input {
|
| 92 |
+
border: 1px solid #4CAF50;
|
| 93 |
+
border-radius: 10px;
|
| 94 |
+
}
|
| 95 |
+
.stMarkdown>div>p {
|
| 96 |
+
color: #4CAF50;
|
| 97 |
+
font-weight: bold;
|
| 98 |
+
}
|
| 99 |
+
.stAudio {
|
| 100 |
+
margin-top: 20px;
|
| 101 |
+
border: 2px solid #4CAF50;
|
| 102 |
+
border-radius: 10px;
|
| 103 |
+
}
|
| 104 |
+
.stFileUploader>div>div>input {
|
| 105 |
+
border: 1px solid #4CAF50;
|
| 106 |
+
border-radius: 10px;
|
| 107 |
+
}
|
| 108 |
+
</style>
|
| 109 |
+
""",
|
| 110 |
+
unsafe_allow_html=True,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Encabezado
|
| 114 |
+
st.image("biblia.jpg")
|
| 115 |
+
st.title("📖 Asistente Teológico - BOTIDINAMIX AI")
|
| 116 |
+
st.markdown("Bienvenido al Asistente Teológico, donde puedes preguntar sobre interpretaciones y reflexiones bíblicas.")
|
| 117 |
+
|
| 118 |
+
# Chat
|
| 119 |
+
st.subheader("🗣️ Chat con el Asistente")
|
| 120 |
+
if 'mensajes' not in st.session_state:
|
| 121 |
+
st.session_state.mensajes = []
|
| 122 |
+
|
| 123 |
+
for mensaje in st.session_state.mensajes:
|
| 124 |
+
with st.chat_message(mensaje["role"]):
|
| 125 |
+
st.markdown(mensaje["content"])
|
| 126 |
+
|
| 127 |
+
pregunta_usuario = st.text_input("Escribe tu pregunta sobre la Biblia:")
|
| 128 |
+
if st.button("Enviar"):
|
| 129 |
+
if pregunta_usuario:
|
| 130 |
+
st.session_state.mensajes.append({"role": "user", "content": pregunta_usuario, "timestamp": time.time()})
|
| 131 |
+
with st.chat_message("user"):
|
| 132 |
+
st.markdown(pregunta_usuario)
|
| 133 |
+
|
| 134 |
+
with st.spinner("Generando respuesta..."):
|
| 135 |
+
respuesta = obtener_respuesta(pregunta_usuario)
|
| 136 |
+
st.session_state.mensajes.append({"role": "assistant", "content": respuesta, "timestamp": time.time()})
|
| 137 |
+
with st.chat_message("assistant"):
|
| 138 |
+
st.markdown(respuesta)
|
| 139 |
+
else:
|
| 140 |
+
st.warning("Por favor, ingresa una pregunta antes de enviar.")
|
| 141 |
+
|
| 142 |
+
# Gestión de pedidos
|
| 143 |
+
st.subheader("📋 Gestión de Pedidos")
|
| 144 |
+
menu_csv_path = "menu.csv" # Ruta al archivo CSV del menú
|
| 145 |
+
if 'pedidos' not in st.session_state:
|
| 146 |
+
st.session_state.pedidos = []
|
| 147 |
+
|
| 148 |
+
pedido_agent = PedidoAgent(menu_csv_path)
|
| 149 |
+
calculo_pedido_agent = CalculoPedidoAgent()
|
| 150 |
+
|
| 151 |
+
pedido_agent.realizar_pedido(st.session_state)
|
| 152 |
+
calculo_pedido_agent.calcular_total(st.session_state)
|