Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -14
src/streamlit_app.py
CHANGED
|
@@ -1,10 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import geocoder
|
|
|
|
| 4 |
import io
|
|
|
|
| 5 |
|
|
|
|
| 6 |
st.set_page_config(page_title="π Temple Corpus Collector", layout="centered")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
.title {
|
|
@@ -19,7 +25,7 @@ st.markdown("""
|
|
| 19 |
st.markdown('<div class="title">π Temple Language Corpus Collection</div>', unsafe_allow_html=True)
|
| 20 |
st.write("Collect sacred stories, media and temple history with optional geo-tagging.")
|
| 21 |
|
| 22 |
-
# Session state
|
| 23 |
if "lat" not in st.session_state:
|
| 24 |
st.session_state.lat = ""
|
| 25 |
if "lon" not in st.session_state:
|
|
@@ -50,10 +56,6 @@ with st.form("temple_form"):
|
|
| 50 |
if g.ok:
|
| 51 |
st.session_state.lat = str(g.latlng[0])
|
| 52 |
st.session_state.lon = str(g.latlng[1])
|
| 53 |
-
lat = st.session_state.lat
|
| 54 |
-
lon = st.session_state.lon
|
| 55 |
-
else:
|
| 56 |
-
st.warning("Location detection failed.")
|
| 57 |
|
| 58 |
st.markdown("### π Upload Media")
|
| 59 |
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
|
@@ -63,6 +65,10 @@ with st.form("temple_form"):
|
|
| 63 |
|
| 64 |
# After submission
|
| 65 |
if submitted:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
st.success("β
Submission received!")
|
| 67 |
st.write("### π§Ύ Summary")
|
| 68 |
st.write(f"**Name:** {name}")
|
|
@@ -72,18 +78,22 @@ if submitted:
|
|
| 72 |
st.write(f"**Description:** {description}")
|
| 73 |
st.write(f"**Category:** {category}")
|
| 74 |
st.write(f"**Language:** {language}")
|
| 75 |
-
st.write(f"**Latitude:** {lat}")
|
| 76 |
-
st.write(f"**Longitude:** {lon}")
|
| 77 |
|
| 78 |
-
#
|
| 79 |
if uploaded_image:
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
#
|
| 84 |
if uploaded_media:
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
if uploaded_media.type.startswith("audio"):
|
| 87 |
-
st.audio(
|
| 88 |
elif uploaded_media.type.startswith("video"):
|
| 89 |
-
st.video(
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import geocoder
|
| 4 |
+
import os
|
| 5 |
import io
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
+
# Page config
|
| 9 |
st.set_page_config(page_title="π Temple Corpus Collector", layout="centered")
|
| 10 |
|
| 11 |
+
# Create submissions folder
|
| 12 |
+
os.makedirs("submissions", exist_ok=True)
|
| 13 |
+
|
| 14 |
st.markdown("""
|
| 15 |
<style>
|
| 16 |
.title {
|
|
|
|
| 25 |
st.markdown('<div class="title">π Temple Language Corpus Collection</div>', unsafe_allow_html=True)
|
| 26 |
st.write("Collect sacred stories, media and temple history with optional geo-tagging.")
|
| 27 |
|
| 28 |
+
# Session state
|
| 29 |
if "lat" not in st.session_state:
|
| 30 |
st.session_state.lat = ""
|
| 31 |
if "lon" not in st.session_state:
|
|
|
|
| 56 |
if g.ok:
|
| 57 |
st.session_state.lat = str(g.latlng[0])
|
| 58 |
st.session_state.lon = str(g.latlng[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
st.markdown("### π Upload Media")
|
| 61 |
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
|
|
|
| 65 |
|
| 66 |
# After submission
|
| 67 |
if submitted:
|
| 68 |
+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
| 69 |
+
folder = os.path.join("submissions", f"{name}_{timestamp}")
|
| 70 |
+
os.makedirs(folder, exist_ok=True)
|
| 71 |
+
|
| 72 |
st.success("β
Submission received!")
|
| 73 |
st.write("### π§Ύ Summary")
|
| 74 |
st.write(f"**Name:** {name}")
|
|
|
|
| 78 |
st.write(f"**Description:** {description}")
|
| 79 |
st.write(f"**Category:** {category}")
|
| 80 |
st.write(f"**Language:** {language}")
|
| 81 |
+
st.write(f"**Latitude:** {st.session_state.lat}")
|
| 82 |
+
st.write(f"**Longitude:** {st.session_state.lon}")
|
| 83 |
|
| 84 |
+
# Save and display image
|
| 85 |
if uploaded_image:
|
| 86 |
+
image_path = os.path.join(folder, uploaded_image.name)
|
| 87 |
+
with open(image_path, "wb") as f:
|
| 88 |
+
f.write(uploaded_image.getbuffer())
|
| 89 |
+
st.image(Image.open(image_path), caption="π· Uploaded Image", use_container_width=True)
|
| 90 |
|
| 91 |
+
# Save and display audio/video
|
| 92 |
if uploaded_media:
|
| 93 |
+
media_path = os.path.join(folder, uploaded_media.name)
|
| 94 |
+
with open(media_path, "wb") as f:
|
| 95 |
+
f.write(uploaded_media.getbuffer())
|
| 96 |
if uploaded_media.type.startswith("audio"):
|
| 97 |
+
st.audio(media_path)
|
| 98 |
elif uploaded_media.type.startswith("video"):
|
| 99 |
+
st.video(media_path)
|