How to read gpx files in streamlit

Hello comunity,

I’m trying to read a waypoints gpx file on streamlit using the st.file_uploader().
The function seems to work, but then when I use:

file = st.file_uploader("Upload waypoinst file: ",type=["gpx"])
gpx = gpxpy.parse(file)
options = [waypoint.description[2:] for waypoint in gpx.waypoints if (waypoint.description[3] == "D")]
starting_waypoint = st.selectbox("Please select the starting waypoint: ",options=options)

doesn’t seem to work properly as the variable “options” is empty. I tried this code on a jupyter notebook using:

with open(file_path, "r") as file:
       gpx = gpxpy.parse(file)
options = [waypoint.description[2:] for waypoint in gpx.waypoints if (waypoint.description[3] == "D")]
starting_waypoint = st.selectbox("Please select the starting waypoint: ",options=options)

and it works nicely. I wonder if I need to cast the variable “file” obtained with st.file_uploader() to another kind in order to let it be read by gpxpy.

Thank you very much.

No, this should work.
I assume your gpx file or your waypoints processing leads to empty options.
Just add some lines to debug, for example:

st.write(gpx.waypoints)

Uuuups, that’s true, sorry. I was mistakenly trying to read .description instead of .name