Hi,
I’ve built a chat using these principles.
I added a button to allow users to download their conversation:
To do so, I save the conversation as a temporary JSON file (using json.dump
) and then use it with st.download_button
.
But is there a way to bypass the temporary file?
import json
import streamlit as st
messages = [{"role": "user", "content": "Hello Streamlit"},
{"role": "assistant", "content": "Hello!"}]
file_path = "./tmp.json"
with open(file_path, 'w') as file:
json.dump(messages, file)
with open(file_path, "rb") as file:
st.download_button(label="📥 Save this conversation!",
data=file,
file_name="conversation.json",
mime="application/json")