import streamlit as st import json import os # --- Paths --- COMMENTS_FILE = "data/comments.json" os.makedirs("data", exist_ok=True) # --- Load existing comments --- if os.path.exists(COMMENTS_FILE): with open(COMMENTS_FILE, "r") as f: comments = json.load(f) else: comments = [] # --- Shader Editor --- st.subheader("Shader Editor") default_shader = """// Fresh GLSL shader example #ifdef GL_ES precision mediump float; #endif uniform float iTime; uniform vec2 iResolution; void main() { vec2 uv = gl_FragCoord.xy / iResolution.xy; vec3 color = 0.5 + 0.5 * cos(iTime + uv.xyx * 3.0); gl_FragColor = vec4(color, 1.0); } """ shader_code = st.text_area("Edit shader code", default_shader, height=300) # --- Comments Section --- st.subheader("Comments") if comments: for c in comments: st.write(f"**{c['name']}**: {c['content']}") else: st.write("_No comments yet_") # --- Add a new comment --- 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!") st.experimental_rerun() # refresh to show new comment immediately