Spaces:
Sleeping
Sleeping
| # Historial/historial_chat.py | |
| import os | |
| import json | |
| import streamlit as st # Asegúrate de importar Streamlit aquí | |
| HISTORIAL_PATH = "Historial/historial.json" | |
| def cargar_historial(): | |
| if os.path.exists(HISTORIAL_PATH): | |
| try: | |
| with open(HISTORIAL_PATH, "r") as f: | |
| historial = json.load(f) | |
| return historial | |
| except (json.JSONDecodeError, IOError): | |
| st.warning("El historial de chat está dañado o vacío. Se creará un nuevo historial.") | |
| return [] | |
| def guardar_historial(mensajes): | |
| with open(HISTORIAL_PATH, "w") as f: | |
| json.dump(mensajes, f, indent=4) |