File size: 1,255 Bytes
a36d2f3 74eb349 a82edd7 a36d2f3 a82edd7 74eb349 a82edd7 74eb349 bf0d480 a82edd7 bf0d480 a36d2f3 a82edd7 a36d2f3 bf0d480 a82edd7 a36d2f3 a82edd7 a36d2f3 a82edd7 a36d2f3 a82edd7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
import json
import pandas as pd
import datetime
def download_chat_history(chat_history):
if not chat_history:
st.info("No hay historial de chat para descargar.")
return
# Convertir a DataFrame para facilitar la exportaci贸n a CSV o Excel
df = pd.DataFrame(chat_history)
now = datetime.datetime.now()
df['timestamp'] = now
csv = df.to_csv(index=False)
st.download_button(
label="Descargar conversaci贸n (CSV)",
data=csv,
file_name=f"chat_history_{now.strftime('%Y%m%d_%H%M%S')}.csv",
mime="text/csv",
)
# Opcional: descarga en Excel (requiere openpyxl)
# ... (mismo c贸digo que en la respuesta anterior) ...
# ... (resto de tu c贸digo Streamlit) ...
# Dentro de la secci贸n del chatbot:
chat_history = [] # Inicializa la lista para almacenar el historial del chat
# ... (tu c贸digo para manejar el chat) ...
# Dentro del bucle donde procesas los mensajes:
chat_history.append({"role": message["role"], "content": message["content"]}) #Asumiendo que tus mensajes tienen 'role' y 'content'
# Bot贸n para descargar (al final de la secci贸n del chatbot):
if st.button("Descargar conversaci贸n"):
download_chat_history(chat_history) |