Download components/utils.py from lifepulse/demo: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/spaces/lifepulse/demo/resolve/main/components/utils.py
- Command line
-
hf download hf://spaces/lifepulse/demo/components/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/lifepulse/demo/resolve/main/components/utils.py
2.11 kB
| import base64 | |
| import streamlit as st | |
| def get_base64(bin_file): | |
| with open(bin_file, 'rb') as f: | |
| data = f.read() | |
| return base64.b64encode(data).decode() | |
| def add_logo(width, padding, margin): | |
| padding_top, padding_right, padding_bottom, padding_left = padding | |
| margin_top, margin_right, margin_bottom, margin_left = margin | |
| bin_str = get_base64('images/logo1.png') | |
| link = 'https://www.lifepulse.ai' | |
| html_code = f''' | |
| <a href="{link}" target = _blank> | |
| <img src="data:image/png;base64,{bin_str}" | |
| style=" | |
| margin: auto; | |
| width: {width}%; | |
| margin-top: {margin_top}px; | |
| margin-right: {margin_right}px; | |
| margin-bottom: {margin_bottom}px; | |
| margin-left: {margin_left}%; | |
| padding-top: {padding_top}px; | |
| padding-right: {padding_right}px; | |
| padding-bottom: {padding_bottom}px; | |
| padding-left: {padding_left}%; | |
| "/> | |
| </a> | |
| ''' | |
| return html_code | |
| def new_line(n=1): | |
| for i in range(n): | |
| st.write("\n") | |
| def local_css(file_name): | |
| with open(file_name) as f: | |
| st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) | |
| def remote_css(url): | |
| st.markdown(f'<link href="{url}" rel="stylesheet">', unsafe_allow_html=True) | |
| def add_header(png_file): | |
| bin_str = get_base64(png_file) | |
| page_bg_img = f''' | |
| <style> | |
| .header {{ | |
| background: url("data:image/png;base64,{bin_str}"); | |
| background-size: cover; /* Adjust as needed */ | |
| background-repeat: no-repeat; /* Adjust as needed */ | |
| background-position: center center; /* Adjust as needed */ | |
| text-align: center; | |
| max-width: 100%; | |
| position: relative; | |
| padding: 3.5rem 0 0.5rem; | |
| margin: 0 0 1rem; | |
| color: #FFF; | |
| z-index: 999999999; | |
| }} | |
| </style> | |
| ''' | |
| st.markdown(page_bg_img, unsafe_allow_html=True) |