Spaces:
Sleeping
Sleeping
pjgerrits
commited on
Commit
·
4433fdf
1
Parent(s):
8c316dd
Initial commit
Browse files- .DS_Store +0 -0
- .gitignore +6 -0
- app.py +94 -0
- requirements.txt +53 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
########################################################################
|
| 2 |
+
# Python - https://github.com/github/gitignore/blob/master/Python.gitignore
|
| 3 |
+
########################################################################
|
| 4 |
+
# Byte-compiled / optimized / DLL files
|
| 5 |
+
|
| 6 |
+
.streamlit
|
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import folium
|
| 3 |
+
from folium.plugins import Draw
|
| 4 |
+
from streamlit_folium import st_folium
|
| 5 |
+
import psycopg2
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Set the page layout
|
| 9 |
+
st.set_page_config(layout="wide")
|
| 10 |
+
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def connect_to_db():
|
| 13 |
+
return psycopg2.connect(**st.secrets["postgres"])
|
| 14 |
+
|
| 15 |
+
conn = connect_to_db()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Function to connect to the database
|
| 19 |
+
# def connect_to_db():
|
| 20 |
+
# try:
|
| 21 |
+
# conn = psycopg2.connect(
|
| 22 |
+
# dbname=st.write(st.secrets["DB_NAME"]),
|
| 23 |
+
# user=st.write(st.secrets["DB_USER"]),
|
| 24 |
+
# password=st.write(st.secrets["DB_PASS"]),
|
| 25 |
+
# host=st.write(st.secrets["DB_HOST"]),
|
| 26 |
+
# port=st.write(st.secrets["DB_PORT"]),
|
| 27 |
+
# sslmode='prefer'
|
| 28 |
+
# )
|
| 29 |
+
# return conn
|
| 30 |
+
# except Exception as e:
|
| 31 |
+
# st.error(f"An error occurred while connecting to the database: {e}")
|
| 32 |
+
# return None
|
| 33 |
+
|
| 34 |
+
# Function to fetch previously saved data points
|
| 35 |
+
def fetch_saved_data():
|
| 36 |
+
# conn = connect_to_db()
|
| 37 |
+
if conn:
|
| 38 |
+
cursor = conn.cursor()
|
| 39 |
+
cursor.execute('SELECT "X", "Y", description, gl_certainty FROM public.gettinglost_tracking')
|
| 40 |
+
data = cursor.fetchall()
|
| 41 |
+
cursor.close()
|
| 42 |
+
# conn.close()
|
| 43 |
+
return data
|
| 44 |
+
return []
|
| 45 |
+
|
| 46 |
+
# Function to save data to the database
|
| 47 |
+
def save_data(lat, lon, description, rating):
|
| 48 |
+
conn = connect_to_db()
|
| 49 |
+
if conn:
|
| 50 |
+
cursor = conn.cursor()
|
| 51 |
+
cursor.execute('INSERT INTO public.gettinglost_tracking ("X", "Y", geom, description, gl_certainty) VALUES (%s, %s, ST_SetSRID(ST_MakePoint(%s, %s), 4326), %s, %s)',
|
| 52 |
+
(lat, lon, lon, lat, description, rating))
|
| 53 |
+
conn.commit()
|
| 54 |
+
cursor.close()
|
| 55 |
+
conn.close()
|
| 56 |
+
st.sidebar.success("Data recorded successfully!")
|
| 57 |
+
else:
|
| 58 |
+
st.sidebar.error("Failed to save data.")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
st.title('Getting Lost Mapping')
|
| 62 |
+
|
| 63 |
+
# Create the Folium map with Draw plugin for point markers
|
| 64 |
+
m = folium.Map(location=[51.505, -0.09], zoom_start=13, width=1500, height=600)
|
| 65 |
+
draw = Draw(draw_options={'polyline': False, "marker": True, 'rectangle': False, 'polygon': False, 'circle': False, 'circlemarker': False})
|
| 66 |
+
m.add_child(draw)
|
| 67 |
+
|
| 68 |
+
# Display previously saved data points on the map
|
| 69 |
+
for point in fetch_saved_data():
|
| 70 |
+
lat, lon, desc, rating = point
|
| 71 |
+
folium.Marker([lat, lon], popup=f"{desc} (Certainty: {rating})").add_to(m)
|
| 72 |
+
|
| 73 |
+
# Render the map
|
| 74 |
+
map_output = st_folium(m, width='100%', height=600)
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
# Extract coordinates from drawn point
|
| 78 |
+
coords = map_output["all_drawings"][-1]["geometry"]["coordinates"]
|
| 79 |
+
st.session_state.coord = coords
|
| 80 |
+
except:
|
| 81 |
+
# Default coordinates if no point has been drawn yet
|
| 82 |
+
coords = [0,0]
|
| 83 |
+
|
| 84 |
+
# Data Entry Form in the sidebar
|
| 85 |
+
st.sidebar.write("Click on the map to select a location, then fill out the form.")
|
| 86 |
+
description = st.sidebar.text_area("Description:")
|
| 87 |
+
rating = st.sidebar.selectbox('Certainty (1-5)', ['1', '2', '3', '4', '5'])
|
| 88 |
+
|
| 89 |
+
# Placeholder for clicked coordinates (this is a simplification and might not capture all map clicks in Streamlit)
|
| 90 |
+
clicked_lat = coords[1] # Default value, should ideally be updated on map click
|
| 91 |
+
clicked_lon = coords[0] # Default value, should ideally be updated on map click
|
| 92 |
+
|
| 93 |
+
if st.sidebar.button('Save'):
|
| 94 |
+
save_data(clicked_lat, clicked_lon, description, rating)
|
requirements.txt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
altair==5.0.1
|
| 2 |
+
attrs==23.1.0
|
| 3 |
+
backports.zoneinfo==0.2.1
|
| 4 |
+
blinker==1.6.2
|
| 5 |
+
branca==0.6.0
|
| 6 |
+
cachetools==5.3.1
|
| 7 |
+
certifi==2023.7.22
|
| 8 |
+
charset-normalizer==3.2.0
|
| 9 |
+
click==8.1.7
|
| 10 |
+
folium==0.14.0
|
| 11 |
+
gitdb==4.0.10
|
| 12 |
+
GitPython==3.1.32
|
| 13 |
+
idna==3.4
|
| 14 |
+
importlib-metadata==6.8.0
|
| 15 |
+
importlib-resources==6.0.1
|
| 16 |
+
Jinja2==3.1.2
|
| 17 |
+
jsonschema==4.19.0
|
| 18 |
+
jsonschema-specifications==2023.7.1
|
| 19 |
+
markdown-it-py==3.0.0
|
| 20 |
+
MarkupSafe==2.1.3
|
| 21 |
+
mdurl==0.1.2
|
| 22 |
+
numpy==1.24.4
|
| 23 |
+
packaging==23.1
|
| 24 |
+
pandas==2.0.3
|
| 25 |
+
Pillow==9.5.0
|
| 26 |
+
pkgutil_resolve_name==1.3.10
|
| 27 |
+
protobuf==4.24.1
|
| 28 |
+
psycopg2 @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_98luv3o0hn/croot/psycopg2_1687443459133/work
|
| 29 |
+
pyarrow==12.0.1
|
| 30 |
+
pydeck==0.8.0
|
| 31 |
+
Pygments==2.16.1
|
| 32 |
+
Pympler==1.0.1
|
| 33 |
+
python-dateutil==2.8.2
|
| 34 |
+
pytz==2023.3
|
| 35 |
+
pytz-deprecation-shim==0.1.0.post0
|
| 36 |
+
referencing==0.30.2
|
| 37 |
+
requests==2.31.0
|
| 38 |
+
rich==13.5.2
|
| 39 |
+
rpds-py==0.9.2
|
| 40 |
+
six==1.16.0
|
| 41 |
+
smmap==5.0.0
|
| 42 |
+
streamlit==1.25.0
|
| 43 |
+
streamlit-folium==0.13.0
|
| 44 |
+
tenacity==8.2.3
|
| 45 |
+
toml==0.10.2
|
| 46 |
+
toolz==0.12.0
|
| 47 |
+
tornado==6.3.3
|
| 48 |
+
typing_extensions==4.7.1
|
| 49 |
+
tzdata==2023.3
|
| 50 |
+
tzlocal==4.3.1
|
| 51 |
+
urllib3==2.0.4
|
| 52 |
+
validators==0.21.2
|
| 53 |
+
zipp==3.16.2
|