| | import streamlit as st |
| | import json |
| | import os |
| |
|
| | |
| | COMMENTS_FILE = "data/comments.json" |
| | os.makedirs("data", exist_ok=True) |
| |
|
| | |
| | if os.path.exists(COMMENTS_FILE): |
| | with open(COMMENTS_FILE, "r") as f: |
| | comments = json.load(f) |
| | else: |
| | comments = [] |
| |
|
| | |
| | st.subheader("Comments") |
| | if comments: |
| | for c in comments: |
| | st.write(f"**{c['name']}**: {c['content']}") |
| | else: |
| | st.write("_No comments yet_") |
| |
|
| | |
| | with st.form("comment_form", clear_on_submit=True): |
| | user_name = st.text_input("Your name", "") |
| | user_content = st.text_area("Content", height=80) |
| | submitted = st.form_submit_button("Submit") |
| |
|
| | if submitted and user_content.strip(): |
| | |
| | new_comment = { |
| | "name": user_name or "Anonymous", |
| | "content": user_content |
| | } |
| |
|
| | |
| | comments.append(new_comment) |
| | with open(COMMENTS_FILE, "w") as f: |
| | json.dump(comments, f, indent=2) |
| |
|
| | st.success("Saved!") |
| |
|
| |
|