import streamlit as st import base64 PAGE_ICON = 'src/frontend/images/jb_events_logo.jpg' PAGE_LAYOUT = 'wide' PAGE_TITLE = 'JB Events' INITIAL_SIBEBAR_STATE = 'collapsed' def set_up_page(): st.set_page_config(page_icon=PAGE_ICON,layout=PAGE_LAYOUT,page_title=PAGE_TITLE,initial_sidebar_state=INITIAL_SIBEBAR_STATE) def navbar_with_title(): st.markdown(f"""
""", unsafe_allow_html=True) def img_to_base64(image_path): """Convert image to base64.""" try: with open(image_path, "rb") as img_file: return base64.b64encode(img_file.read()).decode() except Exception as e: # logger.error(f"Error converting image to base64: {str(e)}") return None def set_bg_image(file_path, opacity=0.5): """ Sets a background image for the Streamlit application with optional opacity control. This function applies a background image to the entire Streamlit app (`.stApp` container) using CSS with a linear gradient overlay. The overlay enhances text readability by adding a semi-transparent dark layer over the image. Args: file_path (str): The file path of the background image (supports PNG, JPG, etc.). opacity (float, optional): The opacity level of the dark overlay. Values range from 0 (fully transparent) to 1 (fully opaque). Default is 0.5, providing balanced readability and background visibility. Example Usage: ```python set_bg_image("src/frontend/images/health_care_banner.png", opacity=0.6) ``` Notes: - Ensure the provided `file_path` is accessible and the image is properly encoded in base64 format. - For optimal results, use high-resolution images with suitable contrast to enhance readability. """ encoded_img = img_to_base64(file_path) st.markdown( f""" """, unsafe_allow_html=True )