Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
"""
|
| 2 |
======================================================
|
| 3 |
📘 金融客服小智(Fintech Assistant)
|
| 4 |
-
版本:v3.
|
| 5 |
更新重點:
|
| 6 |
-
1.
|
| 7 |
-
2. LINE
|
| 8 |
-
3.
|
| 9 |
-
4. 清除對話按鈕移至右側
|
| 10 |
======================================================
|
| 11 |
"""
|
| 12 |
|
|
@@ -134,13 +133,14 @@ def chat_fn(message, history):
|
|
| 134 |
except Exception as e:
|
| 135 |
reply = f"⚠️ 生成錯誤:{e}"
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
|
|
|
| 139 |
return reply
|
| 140 |
|
| 141 |
|
| 142 |
# =============================================
|
| 143 |
-
# 6️⃣ Gradio
|
| 144 |
# =============================================
|
| 145 |
logo_base64 = ""
|
| 146 |
if os.path.exists(LOGO_PATH):
|
|
@@ -160,34 +160,6 @@ with gr.Blocks(
|
|
| 160 |
|
| 161 |
#footer { text-align:center; font-size:13px; color:#aaa; margin-top: 20px; }
|
| 162 |
|
| 163 |
-
/* 💬 LINE風格輸入列 */
|
| 164 |
-
.input-container {
|
| 165 |
-
display: flex;
|
| 166 |
-
flex-direction: row;
|
| 167 |
-
align-items: center;
|
| 168 |
-
border: 1px solid #ccc;
|
| 169 |
-
border-radius: 25px;
|
| 170 |
-
padding: 5px 8px;
|
| 171 |
-
background-color: #fff;
|
| 172 |
-
}
|
| 173 |
-
.input-container textarea {
|
| 174 |
-
border: none !important;
|
| 175 |
-
outline: none !important;
|
| 176 |
-
resize: none;
|
| 177 |
-
box-shadow: none !important;
|
| 178 |
-
font-size: 15px;
|
| 179 |
-
padding: 8px 10px;
|
| 180 |
-
width: 100%;
|
| 181 |
-
}
|
| 182 |
-
.send-btn {
|
| 183 |
-
border-radius: 20px !important;
|
| 184 |
-
padding: 6px 14px !important;
|
| 185 |
-
margin-left: 6px !important;
|
| 186 |
-
background-color: #007bff !important;
|
| 187 |
-
color: white !important;
|
| 188 |
-
border: none !important;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
/* 手機寬度下讓 Row 自動垂直排列 */
|
| 192 |
@media (max-width: 768px) {
|
| 193 |
.gr-block.gr-row {
|
|
@@ -221,15 +193,12 @@ with gr.Blocks(
|
|
| 221 |
""")
|
| 222 |
gr.Markdown("<div style='text-align:center; color:gray;'>Powered by Gemini & LangChain</div>")
|
| 223 |
|
| 224 |
-
with gr.Row(equal_height=False):
|
| 225 |
# 左側:聊天區
|
| 226 |
with gr.Column(scale=4, min_width=300):
|
| 227 |
chatbot = gr.Chatbot(label="💬 對話紀錄", type="messages", height=500)
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
with gr.Group(elem_classes="input-container"):
|
| 231 |
-
user_input = gr.Textbox(placeholder="輸入訊息...", show_label=False)
|
| 232 |
-
send_btn = gr.Button("送出", elem_classes="send-btn")
|
| 233 |
|
| 234 |
def handle_input(message, history):
|
| 235 |
if history is None:
|
|
@@ -262,7 +231,6 @@ with gr.Blocks(
|
|
| 262 |
outputs=[chatbot, user_input]
|
| 263 |
)
|
| 264 |
|
| 265 |
-
# ✅ 清除按鈕
|
| 266 |
def clear_all():
|
| 267 |
memory.clear()
|
| 268 |
return [], gr.update(value="")
|
|
|
|
| 1 |
"""
|
| 2 |
======================================================
|
| 3 |
📘 金融客服小智(Fintech Assistant)
|
| 4 |
+
版本:v3.2 (穩定正式版)
|
| 5 |
更新重點:
|
| 6 |
+
1. 修正 LangChain 記憶格式(避免 ValueError)
|
| 7 |
+
2. 回復原生輸入框樣式(類似 LINE 的簡潔列)
|
| 8 |
+
3. 保留手機自適應、桌面置中、右欄清除鍵
|
|
|
|
| 9 |
======================================================
|
| 10 |
"""
|
| 11 |
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
reply = f"⚠️ 生成錯誤:{e}"
|
| 135 |
|
| 136 |
+
# ✅ 修正記憶體格式,避免 ValueError
|
| 137 |
+
memory.save_context({"input": message}, {"output": reply})
|
| 138 |
+
|
| 139 |
return reply
|
| 140 |
|
| 141 |
|
| 142 |
# =============================================
|
| 143 |
+
# 6️⃣ Gradio 介面
|
| 144 |
# =============================================
|
| 145 |
logo_base64 = ""
|
| 146 |
if os.path.exists(LOGO_PATH):
|
|
|
|
| 160 |
|
| 161 |
#footer { text-align:center; font-size:13px; color:#aaa; margin-top: 20px; }
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
/* 手機寬度下讓 Row 自動垂直排列 */
|
| 164 |
@media (max-width: 768px) {
|
| 165 |
.gr-block.gr-row {
|
|
|
|
| 193 |
""")
|
| 194 |
gr.Markdown("<div style='text-align:center; color:gray;'>Powered by Gemini & LangChain</div>")
|
| 195 |
|
| 196 |
+
with gr.Row(equal_height=False):
|
| 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:
|
|
|
|
| 231 |
outputs=[chatbot, user_input]
|
| 232 |
)
|
| 233 |
|
|
|
|
| 234 |
def clear_all():
|
| 235 |
memory.clear()
|
| 236 |
return [], gr.update(value="")
|