sathvikk commited on
Commit
58c7a48
Β·
verified Β·
1 Parent(s): 62b5964

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +28 -20
src/streamlit_app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import geocoder
 
4
 
5
  st.set_page_config(page_title="πŸ›• Temple Corpus Collector", layout="centered")
6
 
@@ -18,12 +19,13 @@ st.markdown("""
18
  st.markdown('<div class="title">πŸ›• Temple Language Corpus Collection</div>', unsafe_allow_html=True)
19
  st.write("Collect sacred stories, media and temple history with optional geo-tagging.")
20
 
21
- # Initialize session state for lat/lon
22
- if "latitude" not in st.session_state:
23
- st.session_state.latitude = ""
24
- if "longitude" not in st.session_state:
25
- st.session_state.longitude = ""
26
 
 
27
  with st.form("temple_form"):
28
  st.markdown("### πŸ‘€ Personal Info")
29
  name = st.text_input("Name")
@@ -37,29 +39,30 @@ with st.form("temple_form"):
37
  language = st.text_input("Language")
38
 
39
  st.markdown("### πŸ“ Location")
40
- col1, col2, col3 = st.columns([1, 1, 1.2])
41
  with col1:
42
- lat = st.text_input("Latitude", value=st.session_state.latitude, key="lat_box")
43
  with col2:
44
- lon = st.text_input("Longitude", value=st.session_state.longitude, key="lon_box")
45
  with col3:
46
  if st.form_submit_button("πŸ“ Auto Detect Location"):
47
  g = geocoder.ip("me")
48
  if g.ok:
49
- st.session_state.latitude = str(g.latlng[0])
50
- st.session_state.longitude = str(g.latlng[1])
51
- st.experimental_rerun()
 
52
  else:
53
- st.warning("Couldn't auto-detect location.")
54
 
55
  st.markdown("### πŸ“Ž Upload Media")
56
  uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
57
- uploaded_media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov"])
58
 
59
- submit = st.form_submit_button("πŸš€ Submit")
60
 
61
  # After submission
62
- if submit:
63
  st.success("βœ… Submission received!")
64
  st.write("### 🧾 Summary")
65
  st.write(f"**Name:** {name}")
@@ -69,13 +72,18 @@ if submit:
69
  st.write(f"**Description:** {description}")
70
  st.write(f"**Category:** {category}")
71
  st.write(f"**Language:** {language}")
72
- st.write(f"**Latitude:** {st.session_state.latitude}")
73
- st.write(f"**Longitude:** {st.session_state.longitude}")
74
 
 
75
  if uploaded_image:
76
- st.image(Image.open(uploaded_image), caption="πŸ“· Uploaded Image", use_column_width=True)
 
 
 
77
  if uploaded_media:
 
78
  if uploaded_media.type.startswith("audio"):
79
- st.audio(uploaded_media)
80
  elif uploaded_media.type.startswith("video"):
81
- st.video(uploaded_media)
 
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
 
 
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 initialization
23
+ if "lat" not in st.session_state:
24
+ st.session_state.lat = ""
25
+ if "lon" not in st.session_state:
26
+ st.session_state.lon = ""
27
 
28
+ # Form
29
  with st.form("temple_form"):
30
  st.markdown("### πŸ‘€ Personal Info")
31
  name = st.text_input("Name")
 
39
  language = st.text_input("Language")
40
 
41
  st.markdown("### πŸ“ Location")
42
+ col1, col2, col3 = st.columns([1, 1, 1.5])
43
  with col1:
44
+ lat = st.text_input("Latitude", value=st.session_state.lat, key="lat_input")
45
  with col2:
46
+ lon = st.text_input("Longitude", value=st.session_state.lon, key="lon_input")
47
  with col3:
48
  if st.form_submit_button("πŸ“ Auto Detect Location"):
49
  g = geocoder.ip("me")
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"])
60
+ uploaded_media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov", "mpeg4"])
61
 
62
+ submitted = st.form_submit_button("πŸš€ Submit")
63
 
64
  # After submission
65
+ if submitted:
66
  st.success("βœ… Submission received!")
67
  st.write("### 🧾 Summary")
68
  st.write(f"**Name:** {name}")
 
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
+ # Display image
79
  if uploaded_image:
80
+ image_bytes = uploaded_image.read()
81
+ st.image(Image.open(io.BytesIO(image_bytes)), caption="πŸ“· Uploaded Image", use_container_width=True)
82
+
83
+ # Display audio/video
84
  if uploaded_media:
85
+ media_bytes = uploaded_media.read()
86
  if uploaded_media.type.startswith("audio"):
87
+ st.audio(media_bytes, format=uploaded_media.type)
88
  elif uploaded_media.type.startswith("video"):
89
+ st.video(media_bytes, format=uploaded_media.type)