import streamlit as st from datetime import datetime # Page config st.set_page_config(page_title="Temple Tales", page_icon="🛕", layout="wide") # Custom CSS st.markdown(""" """, unsafe_allow_html=True) # Init state if 'stories' not in st.session_state: st.session_state.stories = [ { "temple_name": "Meenakshi Temple", "location": "Madurai, India", "story": "Legend says the Meenakshi Temple was created by Indra who was carrying a golden lotus...", "submitter": "Anonymous", "date": "July 17, 2023", "timestamp": 1689600000, "likes": 42 }, { "temple_name": "Fushimi Inari", "location": "Kyoto, Japan", "story": "The thousands of torii gates represent donations from individuals and companies...", "submitter": "Traveler123", "date": "June 5, 2023", "timestamp": 1686000000, "likes": 35 } ] def main(): st.title("🛕 Temple Tales") st.subheader("Share and Discover Stories Behind the Shrines") menu = ["Browse Stories", "Submit Story", "About"] choice = st.sidebar.selectbox("Menu", menu) if choice == "Browse Stories": browse_stories() elif choice == "Submit Story": submit_story() else: about_page() def browse_stories(): st.header("Explore Temple Stories") col1, col2 = st.columns([2, 1]) with col1: search_term = st.text_input("Search by temple name or location", key="search") with col2: sort_option = st.selectbox("Sort by", ["Newest First", "Oldest First", "Most Popular"], key="sort") stories = st.session_state.stories if search_term.strip(): search_term = search_term.lower() stories = [s for s in stories if search_term in s["temple_name"].lower() or search_term in s["location"].lower()] if sort_option == "Newest First": stories = sorted(stories, key=lambda x: x["timestamp"], reverse=True) elif sort_option == "Oldest First": stories = sorted(stories, key=lambda x: x["timestamp"]) else: stories = sorted(stories, key=lambda x: x.get("likes", 0), reverse=True) if not stories: st.warning("No stories found.") else: for story in stories: display_story(story) def display_story(story): with st.expander(f"🏛 {story['temple_name']} - {story['location']}"): col1, col2 = st.columns([1, 3]) with col1: st.image("https://via.placeholder.com/150?text=Temple", width=150) with col2: st.markdown(f"**Submitted by:** {story.get('submitter', 'Anonymous')}") st.markdown(f"**Date:** {story['date']}") st.markdown("**Story:**") st.write(story["story"]) likes = story.get("likes", 0) if st.button(f"❤️ {likes}", key=f"like_{story['timestamp']}"): story["likes"] = likes + 1 st.experimental_rerun() def submit_story(): st.header("Share a Temple Story") with st.form("story_form"): temple_name = st.text_input("Temple/Shrine Name*", help="Official or local name of the temple") location = st.text_input("Location*", help="City, village, or specific address") story_text = st.text_area("Your Story*", height=200, help="Share mythology, legend, or experience (50–2000 characters)") submitter_name = st.text_input("Your Name (optional)") submitted = st.form_submit_button("Submit Story") if submitted: if not temple_name or not location or not story_text: st.error("Please fill in all required fields (*)") elif len(story_text) < 50 or len(story_text) > 2000: st.error("Story must be between 50 and 2000 characters") else: new_story = { "temple_name": temple_name, "location": location, "story": story_text, "submitter": submitter_name or "Anonymous", "date": datetime.now().strftime("%B %d, %Y"), "timestamp": datetime.now().timestamp(), "likes": 0 } st.session_state.stories.append(new_story) st.success("Thank you for sharing your temple story!") st.balloons() def about_page(): st.header("About Temple Tales") st.markdown(""" Temple Tales is a platform to preserve and share the oral histories, myths, and beliefs associated with temples and shrines around the world. **Why this matters:** - Many religious sites have local stories passed down for generations - These stories are at risk of being forgotten - Sharing them helps preserve cultural heritage **How to contribute:** - Go to "Submit Story" - Add temple details and story - Help protect cultural memory! """) st.markdown("---") st.markdown('', unsafe_allow_html=True) if __name__ == "__main__": main()