Spencer525 commited on
Commit
6f06d71
·
verified ·
1 Parent(s): f2b8aa1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -8,29 +8,33 @@ from geopy.geocoders import Nominatim
8
  from geopy.exc import GeocoderInsufficientPrivileges
9
  import time
10
  from PIL import Image
 
11
 
12
 
13
  # 設置頁面配置
14
  st.set_page_config(layout="wide")
15
 
16
- # 加載背景圖片
17
- background_image = Image.open("dog_background.png")
 
 
 
18
 
19
- # 添加自定義CSS來設置背景
20
- st.markdown(
21
- f"""
22
  <style>
23
- .stApp {{
24
- background-image: url("data:image/jpg;base64,{Image.open("dog_background.png").tobytes()}");
25
  background-size: cover;
26
- }}
27
  </style>
28
- """,
29
- unsafe_allow_html=True
30
- )
31
-
32
-
33
 
 
 
34
 
35
 
36
 
 
8
  from geopy.exc import GeocoderInsufficientPrivileges
9
  import time
10
  from PIL import Image
11
+ import base64
12
 
13
 
14
  # 設置頁面配置
15
  st.set_page_config(layout="wide")
16
 
17
+ # 讀取背景圖片
18
+ def get_base64_of_bin_file(bin_file):
19
+ with open(bin_file, 'rb') as f:
20
+ data = f.read()
21
+ return base64.b64encode(data).decode()
22
 
23
+ def set_png_as_page_bg(png_file):
24
+ bin_str = get_base64_of_bin_file(png_file)
25
+ page_bg_img = '''
26
  <style>
27
+ .stApp {
28
+ background-image: url("data:image/png;base64,%s");
29
  background-size: cover;
30
+ }
31
  </style>
32
+ ''' % bin_str
33
+
34
+ st.markdown(page_bg_img, unsafe_allow_html=True)
 
 
35
 
36
+ # 設置背景
37
+ set_png_as_page_bg('dog_background.png')
38
 
39
 
40