Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -204,142 +204,39 @@ def main():
|
|
| 204 |
unsafe_allow_html=True,
|
| 205 |
)
|
| 206 |
|
| 207 |
-
# --- Opciones adicionales ---
|
| 208 |
-
st.markdown("---")
|
| 209 |
-
temperatura = st.slider("🌡️ Temperatura", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
| 210 |
-
|
| 211 |
-
# --- Video de fondo ---
|
| 212 |
-
with st.container():
|
| 213 |
-
st.markdown(
|
| 214 |
-
f"""
|
| 215 |
-
<style>
|
| 216 |
-
#video-container {{
|
| 217 |
-
position: relative;
|
| 218 |
-
width: 100%;
|
| 219 |
-
padding-bottom: 56.25%;
|
| 220 |
-
background-color: lightblue;
|
| 221 |
-
overflow: hidden;
|
| 222 |
-
}}
|
| 223 |
-
#background-video {{
|
| 224 |
-
position: absolute;
|
| 225 |
-
top: 0;
|
| 226 |
-
left: 0;
|
| 227 |
-
width: 100%;
|
| 228 |
-
height: 100%;
|
| 229 |
-
}}
|
| 230 |
-
</style>
|
| 231 |
-
<div id="video-container">
|
| 232 |
-
<video id="background-video" autoplay loop muted playsinline>
|
| 233 |
-
<source src="https://cdn.leonardo.ai/users/645c3d5c-ca1b-4ce8-aefa-a091494e0d09/generations/dd8e0b28-efa4-4937-aaab-a1a8ffa47568/dd8e0b28-efa4-4937-aaab-a1a8ffa47568.mp4" type="video/mp4">
|
| 234 |
-
</video>
|
| 235 |
-
</div>
|
| 236 |
-
""",
|
| 237 |
-
unsafe_allow_html=True,
|
| 238 |
-
)
|
| 239 |
-
|
| 240 |
# --- Barra lateral ---
|
| 241 |
with st.sidebar:
|
| 242 |
st.image("hamburguesa napolitana.jpg")
|
| 243 |
st.title("🤖 RESTAURANTE SAZON BURGER 🍔✨-BOTIDINAMIX AI")
|
| 244 |
st.markdown("---")
|
| 245 |
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
st.
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
st.session_state.run_webrtc = True
|
| 276 |
-
if st.session_state.get("run_webrtc", False):
|
| 277 |
-
webrtc_ctx = webrtc_streamer(
|
| 278 |
-
key="example", mode=WebRtcMode.SENDONLY,
|
| 279 |
-
in_audio=True, on_audio_frame=on_audio,
|
| 280 |
-
)
|
| 281 |
-
|
| 282 |
-
st.markdown("---")
|
| 283 |
-
st.subheader("📄 Subir PDF")
|
| 284 |
-
st.info("Sube un archivo PDF y el asistente responderá en función de su contenido.")
|
| 285 |
-
archivo_pdf = st.file_uploader("Selecciona un archivo PDF", type=["pdf"])
|
| 286 |
-
|
| 287 |
-
texto_extraido = ""
|
| 288 |
-
if archivo_pdf:
|
| 289 |
-
texto_extraido = extraer_texto_pdf(archivo_pdf)
|
| 290 |
-
st.success("Texto extraído del PDF exitosamente.")
|
| 291 |
-
st.text_area("Texto extraído", value=texto_extraido, height=200)
|
| 292 |
-
|
| 293 |
-
if not texto_extraido:
|
| 294 |
-
texto_extraido = st.text_area("Texto extraído", height=200)
|
| 295 |
-
|
| 296 |
-
texto_preprocesado = preprocesar_texto(texto_extraido)
|
| 297 |
-
|
| 298 |
-
# --- Opciones de entrada de usuario ---
|
| 299 |
-
st.markdown("---")
|
| 300 |
-
pregunta_usuario = st.text_input("Escribe tu pregunta:")
|
| 301 |
-
if st.button("Enviar"):
|
| 302 |
-
if pregunta_usuario:
|
| 303 |
-
st.session_state.mensajes.append({"role": "user", "content": pregunta_usuario, "timestamp": time.time()})
|
| 304 |
-
with st.chat_message("user"):
|
| 305 |
-
st.markdown(pregunta_usuario)
|
| 306 |
-
|
| 307 |
-
with st.spinner("Generando respuesta..."):
|
| 308 |
-
respuesta = obtener_respuesta(pregunta_usuario, texto_preprocesado, modelo="gpt-4", temperatura=0.5)
|
| 309 |
-
st.session_state.mensajes.append({"role": "assistant", "content": respuesta, "timestamp": time.time()})
|
| 310 |
-
with st.chat_message("assistant"):
|
| 311 |
-
st.markdown(respuesta)
|
| 312 |
-
|
| 313 |
-
guardar_historial(st.session_state.mensajes)
|
| 314 |
-
else:
|
| 315 |
-
st.warning("Por favor, ingresa una pregunta antes de enviar.")
|
| 316 |
-
|
| 317 |
-
# --- Lectura del menú desde CSV y creación de agentes ---
|
| 318 |
-
st.subheader("📋 Menú y Pedidos")
|
| 319 |
-
menu_csv = st.file_uploader("Sube el archivo CSV del menú", type=["csv"])
|
| 320 |
-
|
| 321 |
-
if menu_csv:
|
| 322 |
-
menu_df = leer_menu_csv(menu_csv)
|
| 323 |
-
st.success("Menú cargado exitosamente. Listo para tomar pedidos.")
|
| 324 |
-
st.write(menu_df)
|
| 325 |
-
|
| 326 |
-
# Captura de pedido
|
| 327 |
-
pedido_usuario = st.text_input("Ingresa tu pedido (separado por comas):")
|
| 328 |
-
if st.button("Tomar Pedido"):
|
| 329 |
-
if pedido_usuario:
|
| 330 |
-
confirmados = tomar_pedido_agente(pedido_usuario, menu_df)
|
| 331 |
-
st.info(f"Pedido confirmado: {confirmados}")
|
| 332 |
-
|
| 333 |
-
total = procesar_orden_agente(','.join(confirmados), menu_df)
|
| 334 |
-
st.success(f"Total del pedido: ${total}")
|
| 335 |
-
|
| 336 |
-
# Generar PDF de la orden
|
| 337 |
-
order_details = {item: {'price': menu_df[menu_df['item'] == item]['price'].values[0]} for item in confirmados}
|
| 338 |
-
pdf_path = generar_pdf_orden(order_details)
|
| 339 |
-
st.markdown(f"[Descargar PDF de la Orden]({pdf_path})", unsafe_allow_html=True)
|
| 340 |
-
else:
|
| 341 |
-
st.warning("Por favor, ingresa el pedido antes de continuar.")
|
| 342 |
-
|
| 343 |
-
if __name__ == "__main__":
|
| 344 |
-
main()
|
| 345 |
|
|
|
|
| 204 |
unsafe_allow_html=True,
|
| 205 |
)
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
# --- Barra lateral ---
|
| 208 |
with st.sidebar:
|
| 209 |
st.image("hamburguesa napolitana.jpg")
|
| 210 |
st.title("🤖 RESTAURANTE SAZON BURGER 🍔✨-BOTIDINAMIX AI")
|
| 211 |
st.markdown("---")
|
| 212 |
|
| 213 |
+
# Opciones de navegación
|
| 214 |
+
pagina = st.selectbox("Selecciona una página", ["Chat", "Subir PDF", "Agentes"])
|
| 215 |
+
|
| 216 |
+
# --- Página principal ---
|
| 217 |
+
if pagina == "Chat":
|
| 218 |
+
# --- Botones de historial ---
|
| 219 |
+
if st.button("Buscar Historial"):
|
| 220 |
+
st.session_state.mostrar_historial = True
|
| 221 |
+
if st.button("Borrar Historial"):
|
| 222 |
+
st.session_state.mensajes = []
|
| 223 |
+
st.session_state.mostrar_historial = False
|
| 224 |
+
st.success("Historial borrado correctamente")
|
| 225 |
+
|
| 226 |
+
# --- Chatbot ---
|
| 227 |
+
if 'mensajes' not in st.session_state:
|
| 228 |
+
st.session_state.mensajes = cargar_historial()
|
| 229 |
+
|
| 230 |
+
for mensaje in st.session_state.mensajes:
|
| 231 |
+
with st.chat_message(mensaje["role"]):
|
| 232 |
+
st.markdown(mensaje["content"])
|
| 233 |
+
|
| 234 |
+
# Función para manejar la entrada de audio
|
| 235 |
+
def on_audio(audio_bytes):
|
| 236 |
+
with st.spinner("Transcribiendo..."):
|
| 237 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_bytes)
|
| 238 |
+
pregunta_usuario = transcript["text"]
|
| 239 |
+
st.session_state.mensajes.append({"role": "user", "content": pregunta_usuario, "timestamp": time.time()})
|
| 240 |
+
with st.chat_message("user"):
|
| 241 |
+
st.markdown(p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|