add caching
This commit is contained in:
@ -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
14
hiking_assistant/utils.py
Normal 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()
|
||||
Reference in New Issue
Block a user