|
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 |
|
|
|
|
|
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", |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat_history = [] |
|
|
|
|
|
|
|
|
|
chat_history.append({"role": message["role"], "content": message["content"]}) |
|
|
|
|
|
|
|
if st.button("Descargar conversaci贸n"): |
|
download_chat_history(chat_history) |