sathvikk commited on
Commit
0ae4ba5
Β·
verified Β·
1 Parent(s): aff7880

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +71 -57
src/streamlit_app.py CHANGED
@@ -1,70 +1,84 @@
1
  import streamlit as st
2
  import os
3
- import geocoder
4
- import pandas as pd
5
  from datetime import datetime
 
 
6
 
7
- # Create submissions folder if not exists
8
- UPLOAD_FOLDER = "submissions"
9
- os.makedirs(UPLOAD_FOLDER, exist_ok=True)
10
-
11
- # CSV to track uploads
12
- CSV_LOG = "submissions_log.csv"
13
 
14
  # Title
15
- st.title("πŸ“Έ Upload Image with Geo Coordinates")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- # File uploader
18
- uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
19
 
20
- # Detect location on button click
21
- if st.button("πŸ“ Detect Location"):
22
- g = geocoder.ip('me')
23
- if g.ok:
24
- lat, lon = g.latlng
25
- st.session_state['location'] = {'lat': lat, 'lon': lon}
26
- st.success(f"πŸ“ Location Detected: ({lat}, {lon})")
27
- else:
28
- st.error("❌ Failed to detect location")
29
 
30
- # Show current detected coordinates
31
- if 'location' in st.session_state:
32
- st.write("**Latitude:**", st.session_state['location']['lat'])
33
- st.write("**Longitude:**", st.session_state['location']['lon'])
 
34
 
35
- # Save file with timestamp and location
36
- if uploaded_file and 'location' in st.session_state:
37
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
38
- filename = f"{timestamp}_{uploaded_file.name}"
39
- file_path = os.path.join(UPLOAD_FOLDER, filename)
40
-
41
- # Save image
42
- with open(file_path, "wb") as f:
43
- f.write(uploaded_file.getbuffer())
44
-
45
- st.success(f"βœ… Saved file as {filename}")
46
 
47
- # Log to CSV
48
- entry = {
49
- "timestamp": timestamp,
50
- "filename": filename,
51
- "latitude": st.session_state['location']['lat'],
52
- "longitude": st.session_state['location']['lon']
53
- }
54
 
55
- # Append to log
56
- if os.path.exists(CSV_LOG):
57
- df = pd.read_csv(CSV_LOG)
58
- df = pd.concat([df, pd.DataFrame([entry])], ignore_index=True)
59
- else:
60
- df = pd.DataFrame([entry])
61
- df.to_csv(CSV_LOG, index=False)
62
 
63
- # Show the saved log
64
- st.subheader("πŸ“„ Upload History")
65
- st.dataframe(df)
66
- else:
67
- if not uploaded_file:
68
- st.info("πŸ“ Please upload an image.")
69
- elif 'location' not in st.session_state:
70
- st.info("πŸ“ Click 'Detect Location' first.")
 
 
1
  import streamlit as st
2
  import os
 
 
3
  from datetime import datetime
4
+ from geopy.geocoders import Nominatim
5
+ import geocoder
6
 
7
+ # Set page config
8
+ st.set_page_config(page_title="πŸ›• Temple Language Corpus", layout="centered")
 
 
 
 
9
 
10
  # Title
11
+ st.markdown("## πŸ›• Temple Language Corpus Collection")
12
+ st.write("Collect sacred stories, audio, and videos from temple environments with location tagging.")
13
+
14
+ # Create submission folder in /tmp
15
+ submission_dir = "/tmp/submissions"
16
+ os.makedirs(submission_dir, exist_ok=True)
17
+
18
+ with st.form("corpus_form", clear_on_submit=True):
19
+ st.markdown("### πŸ‘€ User Information")
20
+ name = st.text_input("Name")
21
+ email = st.text_input("Email (Optional)")
22
+ phone = st.text_input("Phone (Optional)")
23
+
24
+ st.markdown("### πŸ“ Corpus Details")
25
+ title = st.text_input("Title")
26
+ description = st.text_area("Description")
27
+ category = st.selectbox("Category", ["Temple History", "Mythological Story", "Devotional Song", "Festival Ritual", "Others"])
28
+ language = st.text_input("Language")
29
+
30
+ st.markdown("### πŸ“ Location (Auto or Manual)")
31
+ col1, col2 = st.columns([1, 1])
32
+ with col1:
33
+ latitude = st.text_input("Latitude")
34
+ with col2:
35
+ longitude = st.text_input("Longitude")
36
+
37
+ col3, _ = st.columns([1, 5])
38
+ with col3:
39
+ auto_detect = st.form_submit_button("πŸ“ Auto Detect Location")
40
+ if auto_detect:
41
+ g = geocoder.ip('me')
42
+ if g.ok:
43
+ latitude = str(g.latlng[0])
44
+ longitude = str(g.latlng[1])
45
+ st.success(f"πŸ“ Location detected: ({latitude}, {longitude})")
46
+ else:
47
+ st.error("❌ Location detection failed. Please enter manually.")
48
+
49
+ st.markdown("### πŸ“Ž Upload Media")
50
+ image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
51
+ media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov", "mpeg4"])
52
 
53
+ submitted = st.form_submit_button("πŸš€ Submit")
 
54
 
55
+ if submitted:
56
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
57
+ user_folder = os.path.join(submission_dir, f"{name.replace(' ', '_')}_{timestamp}")
58
+ os.makedirs(user_folder, exist_ok=True)
 
 
 
 
 
59
 
60
+ # Save form data to a text file
61
+ with open(os.path.join(user_folder, "info.txt"), "w") as f:
62
+ f.write(f"Name: {name}\nEmail: {email}\nPhone: {phone}\n")
63
+ f.write(f"Title: {title}\nDescription: {description}\nCategory: {category}\nLanguage: {language}\n")
64
+ f.write(f"Latitude: {latitude}\nLongitude: {longitude}\n")
65
 
66
+ if image:
67
+ with open(os.path.join(user_folder, image.name), "wb") as f:
68
+ f.write(image.getbuffer())
 
 
 
 
 
 
 
 
69
 
70
+ if media:
71
+ with open(os.path.join(user_folder, media.name), "wb") as f:
72
+ f.write(media.getbuffer())
 
 
 
 
73
 
74
+ st.success("βœ… Submission Successful!")
 
 
 
 
 
 
75
 
76
+ # Show uploaded content
77
+ if image:
78
+ st.image(image, caption="πŸ“· Uploaded Image", use_container_width=True)
79
+ if media:
80
+ filetype = media.type
81
+ if "audio" in filetype:
82
+ st.audio(media)
83
+ elif "video" in filetype:
84
+ st.video(media)