import streamlit as st
import re
import base64
import validators
from pathlib import Path
def add_logo(logo_url: str, height: int = 100, svg=False):
if svg:
svg_logo = read_svg(logo_url)
b64 = base64.b64encode(svg_logo.encode("utf-8")).decode("utf-8")
logo = f'url("data:image/svg+xml;base64,{b64}")'
elif validators.url(logo_url):
logo = f'url({logo_url})'
else:
logo = f'url("data:image/png;base64,{base64.b64encode(Path(logo_url).read_bytes()).decode()}")'
st.markdown(
f"""
""",
unsafe_allow_html=True,
)
def read_svg(path_svg):
try:
with open(path_svg, "r") as file:
svg_logo = file.read().splitlines()
_maped_list = map(str, svg_logo)
svg_logo = "".join(_maped_list)
temp_svg_logo = re.findall("", svg_logo, flags=re.IGNORECASE)
svg_logo = temp_svg_logo[0]
except:
svg_logo = ''
return svg_logo
def render_svg(svg):
b64 = base64.b64encode(svg.encode("utf-8")).decode("utf-8")
html = (
r"""
"""
% b64
)
st.markdown(html, unsafe_allow_html=True)