adamtobegreat commited on
Commit
008887c
·
verified ·
1 Parent(s): 91723e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -14
app.py CHANGED
@@ -142,11 +142,6 @@ def chat_fn(message, history):
142
  # =============================================
143
  # 6️⃣ Gradio 介面
144
  # =============================================
145
- logo_base64 = ""
146
- if os.path.exists(LOGO_PATH):
147
- with open(LOGO_PATH, "rb") as f:
148
- logo_base64 = base64.b64encode(f.read()).decode("utf-8")
149
-
150
  with gr.Blocks(
151
  theme="soft",
152
  css="""
@@ -169,26 +164,66 @@ with gr.Blocks(
169
  .gradio-container { padding: 8px; }
170
  #footer { font-size: 12px; margin-top: 10px; }
171
  #main-title { font-size: 22px !important; line-height: 1.4; }
172
- #main-title br { display: inline; }
173
  }
174
 
175
- /* 桌面版標題置中 */
176
  #main-title {
177
  text-align: center;
 
178
  font-size: 26px;
179
  margin-top: 60px;
180
  margin-bottom: 6px;
181
- font-weight: bold;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
  """
184
  ) as demo:
185
  if logo_base64:
186
  gr.HTML(f"<div id='logo-top'><img src='data:image/png;base64,{logo_base64}'></div>")
187
 
188
- # 🔹 標題(桌面置中、手機換行)
189
  gr.HTML("""
190
  <div id="main-title">
191
- 👨‍💼 我是小智<br>您的金融好幫手 🫰
 
 
 
192
  </div>
193
  """)
194
  gr.Markdown("<div style='text-align:center; color:gray;'>Powered by Gemini & LangChain</div>")
@@ -197,17 +232,29 @@ with gr.Blocks(
197
  # 左側:聊天區
198
  with gr.Column(scale=4, min_width=300):
199
  chatbot = gr.Chatbot(label="💬 對話紀錄", type="messages", height=500)
200
- user_input = gr.Textbox(placeholder="請輸入您的問題...", show_label=False)
201
- send_btn = gr.Button("送出", variant="primary")
202
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  def handle_input(message, history):
204
  if history is None:
205
  history = []
206
  if not message.strip():
207
  return history, gr.update(value="")
208
  reply = chat_fn(message, history)
209
- history += [{"role": "user", "content": message},
210
- {"role": "assistant", "content": reply}]
 
 
211
  return history, gr.update(value="")
212
 
213
  user_input.submit(handle_input, [user_input, chatbot], [chatbot, user_input])
 
142
  # =============================================
143
  # 6️⃣ Gradio 介面
144
  # =============================================
 
 
 
 
 
145
  with gr.Blocks(
146
  theme="soft",
147
  css="""
 
164
  .gradio-container { padding: 8px; }
165
  #footer { font-size: 12px; margin-top: 10px; }
166
  #main-title { font-size: 22px !important; line-height: 1.4; }
 
167
  }
168
 
169
+ /* === 桌機/手機自適應標題 === */
170
  #main-title {
171
  text-align: center;
172
+ font-weight: bold;
173
  font-size: 26px;
174
  margin-top: 60px;
175
  margin-bottom: 6px;
176
+ }
177
+ .title-line {
178
+ display: flex;
179
+ justify-content: center;
180
+ align-items: center;
181
+ gap: 8px;
182
+ flex-wrap: nowrap;
183
+ }
184
+ .subtitle {
185
+ white-space: nowrap;
186
+ }
187
+ @media (max-width: 768px) {
188
+ .title-line {
189
+ flex-direction: column;
190
+ gap: 4px;
191
+ }
192
+ #main-title {
193
+ font-size: 22px;
194
+ line-height: 1.4;
195
+ }
196
+ }
197
+
198
+ /* ✅ 修正輸入框高度與送出鍵比例 */
199
+ #chat-input textarea {
200
+ height: 48px !important;
201
+ min-height: 48px !important;
202
+ font-size: 16px !important;
203
+ padding: 8px 12px !important;
204
+ border-radius: 10px !important;
205
+ }
206
+ #chat-row {
207
+ align-items: center !important;
208
+ gap: 8px !important;
209
+ }
210
+ #send-btn {
211
+ height: 48px !important;
212
+ font-size: 16px !important;
213
+ border-radius: 10px !important;
214
  }
215
  """
216
  ) as demo:
217
  if logo_base64:
218
  gr.HTML(f"<div id='logo-top'><img src='data:image/png;base64,{logo_base64}'></div>")
219
 
220
+ # 🔹 標題(桌機同行、手機自動換行)
221
  gr.HTML("""
222
  <div id="main-title">
223
+ <span class="title-line">
224
+ 👨‍💼 我是小智
225
+ <span class="subtitle">您的金融好幫手 🫰</span>
226
+ </span>
227
  </div>
228
  """)
229
  gr.Markdown("<div style='text-align:center; color:gray;'>Powered by Gemini & LangChain</div>")
 
232
  # 左側:聊天區
233
  with gr.Column(scale=4, min_width=300):
234
  chatbot = gr.Chatbot(label="💬 對話紀錄", type="messages", height=500)
 
 
235
 
236
+ # ✅ 輸入框與送出鍵同行排列
237
+ with gr.Row(elem_id="chat-row"):
238
+ user_input = gr.Textbox(
239
+ placeholder="請輸入您的問題...",
240
+ show_label=False,
241
+ lines=1,
242
+ max_lines=1,
243
+ elem_id="chat-input"
244
+ )
245
+ send_btn = gr.Button("送出", variant="primary", elem_id="send-btn")
246
+
247
+ # === 輸入邏輯 ===
248
  def handle_input(message, history):
249
  if history is None:
250
  history = []
251
  if not message.strip():
252
  return history, gr.update(value="")
253
  reply = chat_fn(message, history)
254
+ history += [
255
+ {"role": "user", "content": message},
256
+ {"role": "assistant", "content": reply}
257
+ ]
258
  return history, gr.update(value="")
259
 
260
  user_input.submit(handle_input, [user_input, chatbot], [chatbot, user_input])