Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -143,14 +143,12 @@ def chat_fn(message, history):
|
|
| 143 |
# 6️⃣ Gradio 介面
|
| 144 |
# =============================================
|
| 145 |
|
| 146 |
-
# === Logo 圖片處理 ===
|
| 147 |
# === Logo 圖片處理 ===
|
| 148 |
logo_base64 = ""
|
| 149 |
if os.path.exists(LOGO_PATH):
|
| 150 |
with open(LOGO_PATH, "rb") as f:
|
| 151 |
logo_base64 = base64.b64encode(f.read()).decode("utf-8")
|
| 152 |
|
| 153 |
-
|
| 154 |
with gr.Blocks(
|
| 155 |
theme="soft",
|
| 156 |
css="""
|
|
@@ -225,11 +223,10 @@ with gr.Blocks(
|
|
| 225 |
#chat-row > .gr-textbox { flex: 9 !important; }
|
| 226 |
#chat-row > .gr-button { flex: 1 !important; }
|
| 227 |
|
| 228 |
-
/* ✅ 手機版比例:輸入框 9、按鈕 1
|
| 229 |
@media (max-width: 768px) {
|
| 230 |
#chat-row > .gr-textbox { flex: 9 !important; }
|
| 231 |
#chat-row > .gr-button { flex: 1 !important; }
|
| 232 |
-
|
| 233 |
}
|
| 234 |
"""
|
| 235 |
) as demo:
|
|
@@ -283,26 +280,28 @@ with gr.Blocks(
|
|
| 283 |
return history, gr.update(value="")
|
| 284 |
|
| 285 |
# ✅ 綁定事件(Enter送出、Shift+Enter換行)
|
| 286 |
-
user_input.submit(handle_input, [user_input, chatbot], [chatbot, user_input]) # Enter
|
| 287 |
-
send_btn.click(handle_input, [user_input, chatbot], [chatbot, user_input]) #
|
| 288 |
|
| 289 |
-
# ✅ JS
|
| 290 |
gr.HTML("""
|
| 291 |
<script>
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
|
|
|
| 300 |
});
|
| 301 |
-
|
|
|
|
| 302 |
</script>
|
| 303 |
""")
|
| 304 |
|
| 305 |
-
# 右側:常見問題 +
|
| 306 |
with gr.Column(scale=1, min_width=200):
|
| 307 |
gr.Markdown("### 🔍 常見問題")
|
| 308 |
examples = [
|
|
@@ -324,7 +323,7 @@ with gr.Blocks(
|
|
| 324 |
memory.clear()
|
| 325 |
return [], gr.update(value="")
|
| 326 |
gr.Markdown("---")
|
| 327 |
-
gr.Button("🧹
|
| 328 |
|
| 329 |
gr.HTML("<div id='footer'>© Fintech Assistant — 僅業務使用,非官方授權</div>")
|
| 330 |
|
|
|
|
| 143 |
# 6️⃣ Gradio 介面
|
| 144 |
# =============================================
|
| 145 |
|
|
|
|
| 146 |
# === Logo 圖片處理 ===
|
| 147 |
logo_base64 = ""
|
| 148 |
if os.path.exists(LOGO_PATH):
|
| 149 |
with open(LOGO_PATH, "rb") as f:
|
| 150 |
logo_base64 = base64.b64encode(f.read()).decode("utf-8")
|
| 151 |
|
|
|
|
| 152 |
with gr.Blocks(
|
| 153 |
theme="soft",
|
| 154 |
css="""
|
|
|
|
| 223 |
#chat-row > .gr-textbox { flex: 9 !important; }
|
| 224 |
#chat-row > .gr-button { flex: 1 !important; }
|
| 225 |
|
| 226 |
+
/* ✅ 手機版比例:輸入框 9、按鈕 1 */
|
| 227 |
@media (max-width: 768px) {
|
| 228 |
#chat-row > .gr-textbox { flex: 9 !important; }
|
| 229 |
#chat-row > .gr-button { flex: 1 !important; }
|
|
|
|
| 230 |
}
|
| 231 |
"""
|
| 232 |
) as demo:
|
|
|
|
| 280 |
return history, gr.update(value="")
|
| 281 |
|
| 282 |
# ✅ 綁定事件(Enter送出、Shift+Enter換行)
|
| 283 |
+
user_input.submit(handle_input, [user_input, chatbot], [chatbot, user_input]) # Enter 觸發送出
|
| 284 |
+
send_btn.click(handle_input, [user_input, chatbot], [chatbot, user_input]) # 按鈕觸發送出
|
| 285 |
|
| 286 |
+
# ✅ 修正版 JS:適用桌機與手機
|
| 287 |
gr.HTML("""
|
| 288 |
<script>
|
| 289 |
+
document.addEventListener("DOMContentLoaded", function() {
|
| 290 |
+
const textareas = document.querySelectorAll("textarea");
|
| 291 |
+
textareas.forEach((ta) => {
|
| 292 |
+
ta.addEventListener("keydown", function(e) {
|
| 293 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 294 |
+
e.preventDefault();
|
| 295 |
+
const sendBtn = document.querySelector('#send-btn button, #send-btn');
|
| 296 |
+
if (sendBtn) sendBtn.click();
|
| 297 |
+
}
|
| 298 |
});
|
| 299 |
+
});
|
| 300 |
+
});
|
| 301 |
</script>
|
| 302 |
""")
|
| 303 |
|
| 304 |
+
# 右側:常見問題 + 整理畫面
|
| 305 |
with gr.Column(scale=1, min_width=200):
|
| 306 |
gr.Markdown("### 🔍 常見問題")
|
| 307 |
examples = [
|
|
|
|
| 323 |
memory.clear()
|
| 324 |
return [], gr.update(value="")
|
| 325 |
gr.Markdown("---")
|
| 326 |
+
gr.Button("🧹 整理畫面").click(clear_all, outputs=[chatbot, user_input])
|
| 327 |
|
| 328 |
gr.HTML("<div id='footer'>© Fintech Assistant — 僅業務使用,非官方授權</div>")
|
| 329 |
|