ImaGen / secretary.py
fmmkii's picture
Updated secretary.py
5bdd142
import streamlit as st
import json
import os
# Load script history
history_file = "script_history.json"
def load_script_history():
if os.path.exists(history_file):
with open(history_file, "r") as file:
return json.load(file)
return []
def save_script_history(history):
with open(history_file, "w") as file:
json.dump(history, file, indent=4)
# Load the script history
script_history = load_script_history()
st.title("Script Secretary ๐Ÿ“š")
st.header('Manage saved scripts in history.')
# Display entries and provide delete/download functionality
if script_history:
for idx, entry in enumerate(script_history):
# Add an expander for each script
with st.expander(entry.get("title","")):
# Display script content in a read-only text area
st.text_area(
"Script Content",
value=entry.get("script", ""),
height=150,
disabled=True,
key=f"text_area_{idx}" # Unique key for each text area
)
# Add a button to download the script as a text file
st.download_button(
label="Download Script",
data=entry["script"],
file_name = f"{entry.get('title', '')}.txt",
mime="text/plain"
)
# Add a delete button for each entry
if st.button(f"Delete Script", key=f"delete_{idx}"):
# Delete the selected entry
del script_history[idx]
save_script_history(script_history)
st.success(f"Script {idx + 1} deleted!")
st.rerun() # Refresh the page to reflect the deletion
else:
st.info("No script history found!")
# Add a button to clear all history
with st.sidebar:
if script_history and st.button("Clear All Scripts"):
script_history = []
save_script_history(script_history)
st.success("All script history cleared!")
st.rerun()