CODIGOSDIOS / Historial /historial_chat.py
Josedcape's picture
Update Historial/historial_chat.py
2f82086 verified
raw
history blame contribute delete
638 Bytes
# 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)