diff --git a/hiking_assistant/app.py b/hiking_assistant/app.py index ce68a28..55cad1b 100644 --- a/hiking_assistant/app.py +++ b/hiking_assistant/app.py @@ -3,7 +3,6 @@ # author: deng # date: 20251127 -import base64 from datetime import datetime import streamlit as st @@ -12,6 +11,7 @@ from elevation import ElevationRenderer from gpx import GPXProcessor from map import MapRenderer from streamlit_folium import st_folium +from utils import convert_image_to_base64 from weather import WeatherFetcher @@ -23,17 +23,13 @@ class HikingAssistant: with open('assets/config.yaml', 'r') as f: return yaml.safe_load(f) - def _convert_image_to_base64(self, image_path): - with open(image_path, 'rb') as f: - return base64.b64encode(f.read()).decode() - def _set_page_background(self, image_path, opacity=0.8): """Set background image for the application. Args: image_path: Path to the background image """ - image_data = self._convert_image_to_base64(image_path) + image_data = convert_image_to_base64(image_path) ext = image_path.split('.')[-1] overlay = f'rgba(255, 255, 255, {1 - opacity})' st.markdown( @@ -51,7 +47,7 @@ class HikingAssistant: ) def _add_custom_title(self, title, image_path): - favicon_data = self._convert_image_to_base64(image_path) + favicon_data = convert_image_to_base64(image_path) ext = image_path.split('.')[-1] st.markdown( f""" diff --git a/hiking_assistant/utils.py b/hiking_assistant/utils.py new file mode 100644 index 0000000..c46b20c --- /dev/null +++ b/hiking_assistant/utils.py @@ -0,0 +1,14 @@ +# utils.py +# +# author: deng +# date: 20251128 + +import base64 + +import streamlit as st + + +@st.cache_data +def convert_image_to_base64(image_path): + with open(image_path, 'rb') as f: + return base64.b64encode(f.read()).decode()