| import streamlit as st |
| import json |
| import os |
|
|
| |
| 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) |
|
|
| |
| script_history = load_script_history() |
|
|
| st.title("Script Secretary ๐") |
| st.header('Manage saved scripts in history.') |
|
|
| |
| if script_history: |
| for idx, entry in enumerate(script_history): |
| |
| with st.expander(entry.get("title","")): |
| |
| st.text_area( |
| "Script Content", |
| value=entry.get("script", ""), |
| height=150, |
| disabled=True, |
| key=f"text_area_{idx}" |
| ) |
|
|
| |
| st.download_button( |
| label="Download Script", |
| data=entry["script"], |
| file_name = f"{entry.get('title', '')}.txt", |
| mime="text/plain" |
| ) |
|
|
| |
| if st.button(f"Delete Script", key=f"delete_{idx}"): |
| |
| del script_history[idx] |
| save_script_history(script_history) |
| st.success(f"Script {idx + 1} deleted!") |
| st.rerun() |
| else: |
| st.info("No script history found!") |
|
|
| |
| 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() |
|
|