adamtobegreat commited on
Commit
11fb5fe
·
verified ·
1 Parent(s): 55fb709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -23
app.py CHANGED
@@ -105,6 +105,12 @@ if os.path.exists(logo_path):
105
  with open(logo_path, "rb") as f:
106
  logo_base64 = base64.b64encode(f.read()).decode("utf-8")
107
 
 
 
 
 
 
 
108
  with gr.Blocks(
109
  theme="soft",
110
  css="""
@@ -152,22 +158,17 @@ with gr.Blocks(
152
  letter-spacing: 0.5px;
153
  }
154
 
155
- /* ====== 手機版:強制兩行並置中對齊 ====== */
156
  @media (max-width: 768px) {
157
- #main-title br {
158
- display: inline;
159
- }
160
  #main-title {
161
  display: block;
162
- text-align: center; /* ✅ 讓兩行都水平置中 */
163
  white-space: pre-line;
164
  }
165
  }
166
-
167
  @media (min-width: 769px) {
168
- #main-title br {
169
- display: none;
170
- }
171
  }
172
 
173
  /* ====== footer 區 ====== */
@@ -185,7 +186,7 @@ with gr.Blocks(
185
  padding-top: 8px;
186
  }
187
 
188
- /* ====== 手機版 footer 修正 ====== */
189
  @media (max-width: 768px) {
190
  #logo-top {
191
  position: static;
@@ -202,6 +203,36 @@ with gr.Blocks(
202
  padding-top: 8px;
203
  }
204
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  """
206
  ) as demo:
207
  # 左上角 logo
@@ -220,23 +251,22 @@ with gr.Blocks(
220
  </div>
221
  """)
222
 
223
- # 底部版權列
224
- gr.HTML("<div id='footer'>© 2025 Mega Fintech Assistant — All Rights Reserved</div>")
225
-
226
- # 手機鍵盤彈出時捲動補丁
227
- demo.load(None, None, None, js="""
228
- window.addEventListener('focusin', () => {
229
- document.querySelector('textarea')?.scrollIntoView({ behavior: 'smooth', block: 'center' });
230
- });
231
- """)
232
-
233
-
234
  with gr.Row():
235
  with gr.Column(scale=4):
236
  chatbox = gr.Chatbot(label="💬 對話紀錄", type="messages")
237
- user_input = gr.Textbox(label="輸入訊息", placeholder="請輸入問題...")
 
 
 
 
 
 
 
 
238
 
239
  def handle_input(message, history):
 
 
240
  reply = chat_fn(message, history)
241
  history = history + [
242
  {"role": "user", "content": message},
@@ -245,6 +275,7 @@ with gr.Blocks(
245
  return history, gr.update(value="")
246
 
247
  user_input.submit(handle_input, [user_input, chatbox], [chatbox, user_input])
 
248
 
249
  with gr.Column(scale=1):
250
  gr.Markdown("### 👇 快速提問")
@@ -261,7 +292,17 @@ with gr.Blocks(
261
 
262
  def clear_memory():
263
  memory.clear()
264
- return [], gr.update(value="", placeholder="請輸入問題...")
265
  gr.Button("🧹 整理畫面").click(clear_memory, outputs=[chatbox, user_input])
266
 
 
 
 
 
 
 
 
 
 
 
267
  demo.launch()
 
105
  with open(logo_path, "rb") as f:
106
  logo_base64 = base64.b64encode(f.read()).decode("utf-8")
107
 
108
+ logo_path = os.path.join(BASE_DIR, "mega.png")
109
+ logo_base64 = ""
110
+ 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="""
 
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 區 ====== */
 
186
  padding-top: 8px;
187
  }
188
 
189
+ /* ====== 手機 footer 修正 ====== */
190
  @media (max-width: 768px) {
191
  #logo-top {
192
  position: static;
 
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: 10px 14px;
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: 10px 18px;
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
 
251
  </div>
252
  """)
253
 
 
 
 
 
 
 
 
 
 
 
 
254
  with gr.Row():
255
  with gr.Column(scale=4):
256
  chatbox = gr.Chatbot(label="💬 對話紀錄", type="messages")
257
+
258
+ with gr.Row(elem_id="input-row"):
259
+ user_input = gr.Textbox(
260
+ elem_id="user-input",
261
+ show_label=False,
262
+ placeholder="輸入訊息...",
263
+ scale=8
264
+ )
265
+ send_btn = gr.Button("送出", elem_id="send-btn", scale=1)
266
 
267
  def handle_input(message, history):
268
+ if not message.strip():
269
+ return history, gr.update(value="")
270
  reply = chat_fn(message, history)
271
  history = history + [
272
  {"role": "user", "content": message},
 
275
  return history, gr.update(value="")
276
 
277
  user_input.submit(handle_input, [user_input, chatbox], [chatbox, user_input])
278
+ send_btn.click(handle_input, [user_input, chatbox], [chatbox, user_input])
279
 
280
  with gr.Column(scale=1):
281
  gr.Markdown("### 👇 快速提問")
 
292
 
293
  def clear_memory():
294
  memory.clear()
295
+ return [], gr.update(value="", placeholder="輸入訊息...")
296
  gr.Button("🧹 整理畫面").click(clear_memory, outputs=[chatbox, user_input])
297
 
298
+ # 底部版權列
299
+ gr.HTML("<div id='footer'>© Fintech Assistant — 僅業務使用,非官方授權</div>")
300
+
301
+ # 手機鍵盤彈出時捲動補丁
302
+ demo.load(None, None, None, js="""
303
+ window.addEventListener('focusin', () => {
304
+ document.querySelector('textarea')?.scrollIntoView({ behavior: 'smooth', block: 'center' });
305
+ });
306
+ """)
307
+
308
  demo.launch()