add caching

This commit is contained in:
deng
2025-11-28 22:51:33 +08:00
parent 2c0cb8dfcd
commit 517c4e5ebe
2 changed files with 17 additions and 7 deletions

View File

@ -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"""

14
hiking_assistant/utils.py Normal file
View File

@ -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()