Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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 |
-
#
|
8 |
-
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
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 |
-
|
48 |
-
|
49 |
-
|
50 |
-
"filename": filename,
|
51 |
-
"latitude": st.session_state['location']['lat'],
|
52 |
-
"longitude": st.session_state['location']['lon']
|
53 |
-
}
|
54 |
|
55 |
-
|
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 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
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)
|