adamtobegreat commited on
Commit
4d1ff56
·
verified ·
1 Parent(s): dabacad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -125
app.py CHANGED
@@ -81,7 +81,7 @@ def chat_fn(message, history):
81
  context = "\n\n".join([d.page_content for d in docs]) if docs else "查無相關內容。"
82
 
83
  prompt = f"""
84
- 你是一位金融客服人員。根據以下公司規章內容回答使用者問題:
85
  ---
86
  {context}
87
  ---
@@ -111,145 +111,39 @@ if os.path.exists(logo_path):
111
  with open(logo_path, "rb") as f:
112
  logo_base64 = base64.b64encode(f.read()).decode("utf-8")
113
 
114
- with gr.Blocks(
115
- theme="soft",
116
- css="""
117
- /* ====== logo 區塊 ====== */
118
- #logo-top {
119
- position: fixed;
120
- top: 12px;
121
- left: 18px;
122
- z-index: 1000;
123
- background-color: white;
124
- border-radius: 10px;
125
- padding: 6px 8px;
126
- box-shadow: 0 0 8px rgba(0,0,0,0.15);
127
- }
128
- #logo-top img {
129
- width: 120px;
130
- height: auto;
131
- display: block;
132
- }
133
-
134
- /* ====== 標題區 ====== */
135
- #main-title-wrapper {
136
- display: flex;
137
- flex-direction: column;
138
- align-items: center;
139
- justify-content: center;
140
- width: 100%;
141
- text-align: center;
142
- margin-top: 20px;
143
- }
144
-
145
  #main-title {
146
  font-size: 28px;
147
  font-weight: bold;
148
- margin: 0;
149
  text-align: center;
150
- display: inline-block;
151
  line-height: 1.4;
 
 
152
  }
153
 
154
- #sub-title {
155
- margin-top: 10px;
156
- font-size: 14px;
157
- color: #666;
158
- letter-spacing: 0.5px;
159
- }
160
-
161
- /* ====== 手機版:兩行置中 ====== */
162
  @media (max-width: 768px) {
163
- #main-title br { display: inline; }
164
  #main-title {
165
- display: block;
166
- text-align: center;
167
  white-space: pre-line;
168
  }
169
- }
170
- @media (min-width: 769px) {
171
- #main-title br { display: none; }
172
- }
173
-
174
- /* ====== footer 區 ====== */
175
- #footer {
176
- position: fixed;
177
- bottom: 40px;
178
- left: 0;
179
- width: 100%;
180
- text-align: center;
181
- font-size: 13px;
182
- color: #999;
183
- font-family: "Segoe UI", "Noto Sans TC", sans-serif;
184
- letter-spacing: 0.3px;
185
- border-top: 1px solid #ddd;
186
- padding-top: 8px;
187
- }
188
-
189
- /* ====== 手機 footer 修正 ====== */
190
- @media (max-width: 768px) {
191
- #logo-top {
192
- position: static;
193
- display: flex;
194
- justify-content: center;
195
- margin-bottom: 8px;
196
- box-shadow: none;
197
- background: transparent;
198
  }
199
- #footer {
200
- position: relative;
201
- margin-top: 40px;
202
- border-top: 1px solid #ddd;
203
- padding-top: 8px;
204
  }
205
  }
 
206
 
207
- /* ====== LINE 風格輸入區 ====== */
208
- #input-row {
209
- display: flex;
210
- align-items: center;
211
- gap: 8px;
212
- margin-top: 10px;
213
- }
214
- #user-input {
215
- flex-grow: 1;
216
- border-radius: 20px;
217
- border: 1px solid #ccc;
218
- padding: 3px 9px;
219
- font-size: 15px;
220
- background-color: #fff;
221
- box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
222
- }
223
- #send-btn {
224
- background-color: #00b900; /* LINE 綠 */
225
- color: white;
226
- border: none;
227
- border-radius: 20px;
228
- padding: 8px 16px;
229
- font-weight: bold;
230
- cursor: pointer;
231
- transition: 0.2s ease;
232
- }
233
- #send-btn:hover {
234
- background-color: #00a000;
235
- }
236
- """
237
- ) as demo:
238
- # 左上角 logo
239
- if logo_base64:
240
- gr.HTML(f"""
241
- <div id="logo-top">
242
- <img src="data:image/png;base64,{logo_base64}" alt="logo">
243
- </div>
244
- """)
245
-
246
- # 主標題與副標題
247
- gr.HTML("""
248
- <div id="main-title-wrapper">
249
- <h1 id='main-title'>👨‍💼 我是小智&nbsp;您的金融好幫手 🫰</h1>
250
- <p id='sub-title'>Powered by Gemini & LangChain</p>
251
- </div>
252
- """)
253
 
254
  with gr.Row():
255
  with gr.Column(scale=4):
 
81
  context = "\n\n".join([d.page_content for d in docs]) if docs else "查無相關內容。"
82
 
83
  prompt = f"""
84
+ 我是一位金融客服人員。根據以下公司規章內容回答使用者問題:
85
  ---
86
  {context}
87
  ---
 
111
  with open(logo_path, "rb") as f:
112
  logo_base64 = base64.b64encode(f.read()).decode("utf-8")
113
 
114
+ gr.HTML("""
115
+ <style>
116
+ /* ====== 桌機預設:單行顯示 ====== */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  #main-title {
118
  font-size: 28px;
119
  font-weight: bold;
 
120
  text-align: center;
 
121
  line-height: 1.4;
122
+ margin: 0;
123
+ display: inline-block;
124
  }
125
 
126
+ /* ====== 手機版:自動兩行顯示 ====== */
 
 
 
 
 
 
 
127
  @media (max-width: 768px) {
 
128
  #main-title {
129
+ font-size: 24px; /* 👈 手機字體略小 */
 
130
  white-space: pre-line;
131
  }
132
+ #main-title::before {
133
+ content: "👨‍💼 我是小智\\A您的金融好幫手 🫰"; /* \\A = 換行 */
134
+ white-space: pre; /* 保留換行格式 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
136
+ #main-title span {
137
+ display: none; /* 隱藏原本的單行文字 */
 
 
 
138
  }
139
  }
140
+ </style>
141
 
142
+ <div id="main-title-wrapper" style="text-align:center; margin-top:20px;">
143
+ <h1 id='main-title'><span>👨‍💼 我是小智&nbsp;&nbsp;您的金融好幫手 🫰</span></h1>
144
+ <p id='sub-title' style='margin-top:10px; font-size:14px; color:#666;'>Powered by Gemini & LangChain</p>
145
+ </div>
146
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  with gr.Row():
149
  with gr.Column(scale=4):