File size: 3,206 Bytes
cb907a8
6a07df8
 
0ae4ba5
 
5c51397
0ae4ba5
 
aff7880
 
0ae4ba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aff7880
0ae4ba5
aff7880
0ae4ba5
 
 
 
aff7880
0ae4ba5
 
 
 
 
aff7880
0ae4ba5
 
 
aff7880
0ae4ba5
 
 
aff7880
0ae4ba5
aff7880
0ae4ba5
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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)