sathvikk commited on
Commit
5c51397
Β·
verified Β·
1 Parent(s): ca4dad7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +54 -59
src/streamlit_app.py CHANGED
@@ -1,73 +1,68 @@
1
  import streamlit as st
2
  import os
3
- import geocoder
4
- from huggingface_hub import upload_file
5
  from datetime import datetime
 
 
 
 
 
 
 
 
6
 
7
- # App Title
8
- st.title("πŸ›• Temple Submission App")
9
- st.write("Upload temple details, image, audio/video with location")
10
-
11
- # Input Fields
12
- temple_name = st.text_input("Temple Name")
13
- history = st.text_area("Temple History")
14
- language = st.selectbox("Language", ["Telugu", "Hindi", "Tamil", "English", "Other"])
15
-
16
- # Location Detection
17
- st.subheader("πŸ“ Location")
18
- col1, col2 = st.columns([1, 2])
19
- with col1:
20
- detect = st.button("Auto Detect Location")
21
- with col2:
22
  latitude = st.text_input("Latitude")
23
  longitude = st.text_input("Longitude")
24
 
25
- if detect:
26
- g = geocoder.ip('me')
27
- if g.latlng:
28
- latitude, longitude = str(g.latlng[0]), str(g.latlng[1])
29
- st.success(f"Location Detected: {latitude}, {longitude}")
30
- st.experimental_rerun()
31
-
32
- # Media Upload
33
- st.subheader("πŸ“Ž Upload Media")
34
- image = st.file_uploader("Upload Image (JPG, PNG)", type=["jpg", "jpeg", "png"])
35
- media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov", "mpeg4"])
36
-
37
- # Optional email
38
- email = st.text_input("Email (optional)")
39
-
40
- # Submit Button
41
- if st.button("Submit"):
42
- if not temple_name or not history or not language:
43
- st.warning("Please fill in all required fields.")
44
- elif not image and not media:
45
- st.warning("Please upload at least one file (image or media).")
46
- else:
47
- st.success("Submitting your data...")
48
- # Unique ID
49
- uid = f"{temple_name.replace(' ', '_')}_{datetime.now().strftime('%Y%m%d%H%M%S')}"
50
- base_path = f"submissions/{uid}"
51
-
52
- hf_token = st.secrets["HF_TOKEN"]
53
- repo_id = "your-username/temple-submissions" # Replace with your actual username
54
-
55
- # Upload text file
56
- info_text = f"Temple: {temple_name}\nLanguage: {language}\nHistory: {history}\nLat: {latitude}\nLong: {longitude}\nEmail: {email}"
57
- with open("info.txt", "w", encoding="utf-8") as f:
58
- f.write(info_text)
59
- upload_file("info.txt", f"{base_path}/info.txt", repo_id=repo_id, repo_type="dataset", token=hf_token)
60
-
61
- # Upload image
62
  if image:
63
- with open(image.name, "wb") as f:
 
64
  f.write(image.getbuffer())
65
- upload_file(image.name, f"{base_path}/{image.name}", repo_id=repo_id, repo_type="dataset", token=hf_token)
66
 
67
- # Upload media
68
  if media:
69
- with open(media.name, "wb") as f:
 
70
  f.write(media.getbuffer())
71
- upload_file(media.name, f"{base_path}/{media.name}", repo_id=repo_id, repo_type="dataset", token=hf_token)
72
 
73
  st.success("βœ… Submission uploaded successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
+ import uuid
 
4
  from datetime import datetime
5
+ from huggingface_hub import upload_file
6
+ from streamlit_js_eval import streamlit_js_eval
7
+
8
+ # Dataset repo details
9
+ REPO_ID = "your-username/temple-submissions" # change to your repo
10
+ HF_TOKEN = st.secrets["HF_TOKEN"] # must add in Hugging Face secrets
11
+
12
+ st.set_page_config(page_title="Temple Submission", layout="centered")
13
 
14
+ st.title("πŸ›• Temple History Submission")
15
+
16
+ with st.form("temple_form", clear_on_submit=False):
17
+ name = st.text_input("Temple Name")
18
+ lang = st.text_input("Language")
19
+ location = st.text_input("πŸ“ Location")
 
 
 
 
 
 
 
 
 
20
  latitude = st.text_input("Latitude")
21
  longitude = st.text_input("Longitude")
22
 
23
+ st.markdown("#### πŸ“Ž Upload Media")
24
+
25
+ image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
26
+ media = st.file_uploader("Upload Audio or Video", type=["mp3", "wav", "m4a", "mp4", "mov", "mpeg4"])
27
+
28
+ if st.form_submit_button("πŸ“© Submit"):
29
+ uid = str(uuid.uuid4())[:8]
30
+ folder = f"{uid}_{datetime.now().strftime('%Y%m%d%H%M%S')}"
31
+
32
+ os.makedirs("/tmp/" + folder, exist_ok=True)
33
+
34
+ # Save info text
35
+ info_file = f"/tmp/{folder}/info.txt"
36
+ with open(info_file, "w", encoding="utf-8") as f:
37
+ f.write(f"Temple Name: {name}\nLanguage: {lang}\nLocation: {location}\nLatitude: {latitude}\nLongitude: {longitude}")
38
+
39
+ upload_file(info_file, f"{folder}/info.txt", repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
40
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  if image:
42
+ image_path = f"/tmp/{folder}/{image.name}"
43
+ with open(image_path, "wb") as f:
44
  f.write(image.getbuffer())
45
+ upload_file(image_path, f"{folder}/{image.name}", repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
46
 
 
47
  if media:
48
+ media_path = f"/tmp/{folder}/{media.name}"
49
+ with open(media_path, "wb") as f:
50
  f.write(media.getbuffer())
51
+ upload_file(media_path, f"{folder}/{media.name}", repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
52
 
53
  st.success("βœ… Submission uploaded successfully!")
54
+
55
+ # Auto location button
56
+ js = streamlit_js_eval(js_expressions="navigator.geolocation.getCurrentPosition((loc) => { window.streamlitLatitude = loc.coords.latitude; window.streamlitLongitude = loc.coords.longitude; }, console.error)", key="geo")
57
+ if js and js.get("window.streamlitLatitude"):
58
+ st.session_state["latitude"] = js["window.streamlitLatitude"]
59
+ st.session_state["longitude"] = js["window.streamlitLongitude"]
60
+ st.experimental_rerun()
61
+
62
+ if "latitude" in st.session_state:
63
+ st.text_input("Latitude", value=str(st.session_state["latitude"]), key="lat_input")
64
+ if "longitude" in st.session_state:
65
+ st.text_input("Longitude", value=str(st.session_state["longitude"]), key="lon_input")
66
+
67
+ if st.button("πŸ“ Auto Detect Location"):
68
+ pass # triggers JS above