subhankarfynd commited on
Commit
5fcedcc
·
1 Parent(s): 6ae4785

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +44 -0
utils.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import base64
3
+
4
+
5
+ @st.cache_data
6
+ def get_base64_of_bin_file(png_file):
7
+ with open(png_file, "rb") as f:
8
+ data = f.read()
9
+ return base64.b64encode(data).decode()
10
+
11
+
12
+ def build_markup_for_logo(
13
+ png_file,
14
+ background_position="50% 10%",
15
+ margin_top="10%",
16
+ image_width="60%",
17
+ image_height="",
18
+ ):
19
+ binary_string = get_base64_of_bin_file(png_file)
20
+ return """
21
+ <style>
22
+ [data-testid="stSidebarNav"] {
23
+ background-image: url("data:image/png;base64,%s");
24
+ background-repeat: no-repeat;
25
+ background-position: %s;
26
+ margin-top: %s;
27
+ background-size: %s %s;
28
+ }
29
+ </style>
30
+ """ % (
31
+ binary_string,
32
+ background_position,
33
+ margin_top,
34
+ image_width,
35
+ image_height,
36
+ )
37
+
38
+
39
+ def add_logo(png_file):
40
+ logo_markup = build_markup_for_logo(png_file)
41
+ st.markdown(
42
+ logo_markup,
43
+ unsafe_allow_html=True,
44
+ )