BettyChen commited on
Commit
bea667c
·
verified ·
1 Parent(s): d7a2392

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -2
app.py CHANGED
@@ -1,14 +1,101 @@
1
  import streamlit as st
2
 
3
- # 🚨 重要:st.set_page_config 必須是第一個 Streamlit 命令
4
- st.set_page_config(page_title="國泰人壽 - 用戶行為預測工具", layout="wide", initial_sidebar_state="collapsed")
 
 
 
 
5
 
6
  import pandas as pd
7
  import numpy as np
 
8
  from datetime import datetime, timedelta
9
  import plotly.express as px
10
  import plotly.graph_objects as go
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # 嘗試載入 TensorFlow 和相關套件
13
  try:
14
  from tensorflow.keras.models import load_model
 
1
  import streamlit as st
2
 
3
+ # 🚨 Important: st.set_page_config must come before other Streamlit commands
4
+ st.set_page_config(
5
+ page_title="國泰人壽 - 用戶行為預測工具",
6
+ layout="centered",
7
+ initial_sidebar_state="collapsed"
8
+ )
9
 
10
  import pandas as pd
11
  import numpy as np
12
+ import base64
13
  from datetime import datetime, timedelta
14
  import plotly.express as px
15
  import plotly.graph_objects as go
16
 
17
+ # Function to load image as Base64
18
+ @st.cache_data
19
+ def get_base64_image(path: str) -> str:
20
+ with open(path, "rb") as img_file:
21
+ data = base64.b64encode(img_file.read()).decode()
22
+ return f"data:image/png;base64,{data}"
23
+
24
+ # Load logo
25
+ image_path = "logo.png"
26
+ img_base64 = get_base64_image(image_path)
27
+
28
+ # Custom CSS for theming
29
+ theme_css = """
30
+ <style>
31
+ body { background-color: #e9f7f5; }
32
+ .stApp { background-color: #e9f7f5; color: #333333; }
33
+
34
+ input, select, textarea {
35
+ background-color: #ffffff !important;
36
+ color: #000000 !important;
37
+ border: 1px solid #cccccc !important;
38
+ border-radius: 6px !important;
39
+ }
40
+
41
+ section[data-testid="stDateInput"] {
42
+ background-color: #ffffff !important;
43
+ border-radius: 6px;
44
+ padding: 4px;
45
+ }
46
+
47
+ button[kind="primary"] {
48
+ background-color: #4fc08d !important;
49
+ color: white !important;
50
+ border-radius: 8px;
51
+ padding: 8px 16px;
52
+ border: none;
53
+ }
54
+
55
+ [data-testid="stNotification"] {
56
+ background-color: #d2f3ea !important;
57
+ color: #000000 !important;
58
+ border: 1px solid #99d6cc;
59
+ }
60
+
61
+ /* Form background */
62
+ div[data-testid="stForm"] {
63
+ background-color: #f8fffc !important;
64
+ border-radius: 12px;
65
+ padding: 20px;
66
+ border: 1px solid #cceee4;
67
+ }
68
+
69
+ /* Expander styling */
70
+ div[data-testid="stExpander"] > div:first-child {
71
+ background-color: #f8fffc !important;
72
+ border-radius: 12px;
73
+ border: 1px solid #cceee4;
74
+ padding: 16px;
75
+ }
76
+
77
+ div[data-testid="stExpander"] > summary {
78
+ font-size: 1.15rem !important;
79
+ font-weight: 600;
80
+ color: #2a6154;
81
+ }
82
+
83
+ label[for="column_selector"] {
84
+ font-size: 1.1rem !important;
85
+ font-weight: 600;
86
+ color: #1f3f3e;
87
+ }
88
+ </style>
89
+ """
90
+ st.markdown(theme_css, unsafe_allow_html=True)
91
+
92
+ # Header with logo and title
93
+ st.markdown(f"""
94
+ <div style="display: flex; align-items: center; margin-bottom: 20px;">
95
+ <img src="{img_base64}" alt="logo" width="40" style="margin-right: 10px;" />
96
+ <h3 style="margin: 0; color: #1f3f3e;">國泰人壽 - 多元訪客進站行為預測</h3>
97
+ </div>
98
+ """, unsafe_allow_html=True)
99
  # 嘗試載入 TensorFlow 和相關套件
100
  try:
101
  from tensorflow.keras.models import load_model