import streamlit as st import os from datetime import datetime from geopy.geocoders import Nominatim import geocoder # Set page config st.set_page_config(page_title="🛕 Temple Language Corpus", layout="centered") # Title st.markdown("## 🛕 Temple Language Corpus Collection") st.write("Collect sacred stories, audio, and videos from temple environments with location tagging.") # Create submission folder in /tmp submission_dir = "/tmp/submissions" os.makedirs(submission_dir, exist_ok=True) with st.form("corpus_form", clear_on_submit=True): st.markdown("### 👤 User Information") name = st.text_input("Name") email = st.text_input("Email (Optional)") phone = st.text_input("Phone (Optional)") st.markdown("### 📝 Corpus Details") title = st.text_input("Title") description = st.text_area("Description") category = st.selectbox("Category", ["Temple History", "Mythological Story", "Devotional Song", "Festival Ritual", "Others"]) language = st.text_input("Language") st.markdown("### 📍 Location (Auto or Manual)") col1, col2 = st.columns([1, 1]) with col1: latitude = st.text_input("Latitude") with col2: longitude = st.text_input("Longitude") col3, _ = st.columns([1, 5]) with col3: auto_detect = st.form_submit_button("📍 Auto Detect Location") if auto_detect: g = geocoder.ip('me') if g.ok: latitude = str(g.latlng[0]) longitude = str(g.latlng[1]) st.success(f"📍 Location detected: ({latitude}, {longitude})") else: st.error("❌ Location detection failed. Please enter manually.") st.markdown("### 📎 Upload Media") image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"]) media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov", "mpeg4"]) submitted = st.form_submit_button("🚀 Submit") if submitted: timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") user_folder = os.path.join(submission_dir, f"{name.replace(' ', '_')}_{timestamp}") os.makedirs(user_folder, exist_ok=True) # Save form data to a text file with open(os.path.join(user_folder, "info.txt"), "w") as f: f.write(f"Name: {name}\nEmail: {email}\nPhone: {phone}\n") f.write(f"Title: {title}\nDescription: {description}\nCategory: {category}\nLanguage: {language}\n") f.write(f"Latitude: {latitude}\nLongitude: {longitude}\n") if image: with open(os.path.join(user_folder, image.name), "wb") as f: f.write(image.getbuffer()) if media: with open(os.path.join(user_folder, media.name), "wb") as f: f.write(media.getbuffer()) st.success("✅ Submission Successful!") # Show uploaded content if image: st.image(image, caption="📷 Uploaded Image", use_container_width=True) if media: filetype = media.type if "audio" in filetype: st.audio(media) elif "video" in filetype: st.video(media)