json-settings / app.py
louiecerv's picture
first save
7bc0e3e
import streamlit as st
import json
import os
# File path for settings.json
SETTINGS_FILE = "settings.json"
# Initialize the settings file if it doesn't exist
def initialize_settings():
if not os.path.exists(SETTINGS_FILE):
with open(SETTINGS_FILE, "w") as file:
json.dump({"topic": "", "instructions": ""}, file)
# Load settings from the file
def load_settings():
with open(SETTINGS_FILE, "r") as file:
return json.load(file)
# Save settings to the file
def save_settings(settings):
with open(SETTINGS_FILE, "w") as file:
json.dump(settings, file, indent=4)
# Dummy function to simulate prompt generation
def generate_prompt(topic, instructions):
return f"Generated prompt based on topic '{topic}' and instructions: '{instructions}'."
# Initialize the app
initialize_settings()
# Load settings
settings = load_settings()
# Main app
def main():
st.title("AI Prompt Configuration")
# Create text areas for topic and instructions
topic = st.text_area("Topic", value=settings.get("topic", ""), key="topic")
instructions = st.text_area("Custom Instructions", value=settings.get("instructions", ""), key="instructions")
# Update the JSON file if the text areas are changed
if topic != settings.get("topic") or instructions != settings.get("instructions"):
settings["topic"] = topic
settings["instructions"] = instructions
save_settings(settings)
# Button to generate a prompt
if st.button("Generate Prompt"):
result = generate_prompt(topic, instructions)
st.success(result)
st.write("The settings.json file is being used to persist values across app executions.")
if __name__ == "__main__":
main()