Lode Nachtergaele commited on
Commit
7dc0a68
·
1 Parent(s): 827c148

app and route

Browse files
Files changed (3) hide show
  1. app.py +20 -8
  2. poetry.lock +0 -0
  3. pyproject.toml +32 -0
app.py CHANGED
@@ -9,11 +9,15 @@ import numpy as np
9
  import pandas as pd
10
  from scipy.signal import find_peaks
11
  import streamlit as st
 
 
12
  import altair as alt
 
13
 
14
 
15
- def get_gpx(filepath: str):
16
- data = open(filepath)
 
17
  xmldoc = minidom.parse(data)
18
  track = xmldoc.getElementsByTagName("trkpt")
19
  elevation = xmldoc.getElementsByTagName("ele")
@@ -208,19 +212,27 @@ def generate_height_profile_json(df: pd.DataFrame) -> str:
208
  )
209
  chart = (
210
  (elevation + line_peaks)
211
- .properties(width="container")
212
- .configure_view(
213
  strokeWidth=0,
214
  )
215
  )
216
  return chart
217
 
218
 
219
- file_name = st.file_uploader("Upload gpx file")
220
 
221
- if file_name is not None:
222
- ave_lat, ave_lon, lon_list, lat_list, h_list = get_gpx(file_name)
223
  df = pd.DataFrame({"lon": lon_list, "lat": lat_list, "elev": h_list})
 
 
 
 
 
 
 
 
224
  chart = generate_height_profile_json(df)
225
 
226
- st.altair_chart(c, use_container_width=True)
 
9
  import pandas as pd
10
  from scipy.signal import find_peaks
11
  import streamlit as st
12
+ import folium
13
+ from streamlit_folium import st_folium
14
  import altair as alt
15
+ from io import StringIO
16
 
17
 
18
+ def get_gpx(uploaded_file):
19
+ data = StringIO(uploaded_file.getvalue().decode("utf-8"))
20
+
21
  xmldoc = minidom.parse(data)
22
  track = xmldoc.getElementsByTagName("trkpt")
23
  elevation = xmldoc.getElementsByTagName("ele")
 
212
  )
213
  chart = (
214
  (elevation + line_peaks)
215
+ # .properties(width="container")
216
+ .properties(height=100, width=750).configure_view(
217
  strokeWidth=0,
218
  )
219
  )
220
  return chart
221
 
222
 
223
+ gpx_file = st.file_uploader("Upload gpx file", type=["gpx"])
224
 
225
+ if gpx_file is not None:
226
+ ave_lat, ave_lon, lon_list, lat_list, h_list = get_gpx(gpx_file)
227
  df = pd.DataFrame({"lon": lon_list, "lat": lat_list, "elev": h_list})
228
+ route_map = folium.Map(
229
+ location=[ave_lat, ave_lon],
230
+ zoom_start=12,
231
+ )
232
+ folium.PolyLine(
233
+ list(zip(lat_list, lon_list)), color="red", weight=2.5, opacity=1
234
+ ).add_to(route_map)
235
+ st_data = st_folium(route_map, height=450, width=850)
236
  chart = generate_height_profile_json(df)
237
 
238
+ st.altair_chart(chart, use_container_width=False)
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "height_profile"
3
+ version = "0.1.0"
4
+ description = "Hugging Face space that generates a height profile for GPX file"
5
+ authors = ["Arthur Dent <arthur@dent.space>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ # packages = [{include = "python_minimal_boilerplate"}]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = ">=3.10,<3.13"
12
+ streamlit = "1.24.0"
13
+ scipy = "1.11.1"
14
+ altair = "5.0.1"
15
+ watchdog = "^3.0.0"
16
+ folium = "^0.14.0"
17
+ streamlit-folium = "^0.12.0"
18
+
19
+
20
+ [tool.poetry.group.dev.dependencies]
21
+ black = "^23.3.0"
22
+ isort = "^5.10.1"
23
+ pytest = "^7.3.1"
24
+ pre-commit = "^3.3.2"
25
+ ruff = "^0.0.270"
26
+
27
+ [build-system]
28
+ requires = ["poetry-core"]
29
+ build-backend = "poetry.core.masonry.api"
30
+
31
+ [tool.isort]
32
+ profile = "black"