Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -143,6 +143,7 @@ def chat_fn(message, history):
|
|
| 143 |
# 6️⃣ Gradio 介面
|
| 144 |
# =============================================
|
| 145 |
|
|
|
|
| 146 |
# === Logo 圖片處理 ===
|
| 147 |
logo_base64 = ""
|
| 148 |
if os.path.exists(LOGO_PATH):
|
|
@@ -171,7 +172,6 @@ with gr.Blocks(
|
|
| 171 |
#logo-top img { width: 90px; }
|
| 172 |
.gradio-container { padding: 8px; }
|
| 173 |
#footer { font-size: 12px; margin-top: 10px; }
|
| 174 |
-
#main-title { font-size: 22px !important; line-height: 1.4; }
|
| 175 |
}
|
| 176 |
|
| 177 |
/* === 桌機/手機自適應標題 === */
|
|
@@ -203,7 +203,7 @@ with gr.Blocks(
|
|
| 203 |
}
|
| 204 |
}
|
| 205 |
|
| 206 |
-
/* ✅
|
| 207 |
#chat-input textarea {
|
| 208 |
height: 48px !important;
|
| 209 |
min-height: 48px !important;
|
|
@@ -220,15 +220,31 @@ with gr.Blocks(
|
|
| 220 |
font-size: 16px !important;
|
| 221 |
border-radius: 10px !important;
|
| 222 |
}
|
| 223 |
-
|
| 224 |
-
/* ✅ 桌機版比例:輸入框 8、按鈕 2 */
|
| 225 |
-
#chat-row > .gr-textbox { flex: 8 !important; }
|
| 226 |
-
#chat-row > .gr-button { flex: 2 !important; }
|
| 227 |
|
| 228 |
-
/* ✅
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
@media (max-width: 768px) {
|
| 230 |
#chat-row > .gr-textbox { flex: 9 !important; }
|
| 231 |
#chat-row > .gr-button { flex: 1 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
| 233 |
"""
|
| 234 |
) as demo:
|
|
@@ -251,17 +267,22 @@ with gr.Blocks(
|
|
| 251 |
with gr.Column(scale=4, min_width=300):
|
| 252 |
chatbot = gr.Chatbot(label="💬 對話紀錄", type="messages", height=500)
|
| 253 |
|
| 254 |
-
# ✅
|
| 255 |
with gr.Row(elem_id="chat-row"):
|
| 256 |
user_input = gr.Textbox(
|
| 257 |
-
placeholder="
|
| 258 |
show_label=False,
|
| 259 |
lines=1,
|
| 260 |
-
max_lines=
|
| 261 |
elem_id="chat-input",
|
| 262 |
scale=9
|
| 263 |
)
|
| 264 |
-
send_btn = gr.Button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
# === 輸入邏輯 ===
|
| 267 |
def handle_input(message, history):
|
|
@@ -276,8 +297,25 @@ with gr.Blocks(
|
|
| 276 |
]
|
| 277 |
return history, gr.update(value="")
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# 右側:常見問題 + 清除對話
|
| 283 |
with gr.Column(scale=1, min_width=200):
|
|
|
|
| 143 |
# 6️⃣ Gradio 介面
|
| 144 |
# =============================================
|
| 145 |
|
| 146 |
+
# === Logo 圖片處理 ===
|
| 147 |
# === Logo 圖片處理 ===
|
| 148 |
logo_base64 = ""
|
| 149 |
if os.path.exists(LOGO_PATH):
|
|
|
|
| 172 |
#logo-top img { width: 90px; }
|
| 173 |
.gradio-container { padding: 8px; }
|
| 174 |
#footer { font-size: 12px; margin-top: 10px; }
|
|
|
|
| 175 |
}
|
| 176 |
|
| 177 |
/* === 桌機/手機自適應標題 === */
|
|
|
|
| 203 |
}
|
| 204 |
}
|
| 205 |
|
| 206 |
+
/* ✅ 修正輸入框高度與按鈕比例 */
|
| 207 |
#chat-input textarea {
|
| 208 |
height: 48px !important;
|
| 209 |
min-height: 48px !important;
|
|
|
|
| 220 |
font-size: 16px !important;
|
| 221 |
border-radius: 10px !important;
|
| 222 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
+
/* ✅ 桌機版比例:輸入框 9、按鈕 1 */
|
| 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 |
+
#chat-row {
|
| 235 |
+
position: fixed !important;
|
| 236 |
+
bottom: 0 !important;
|
| 237 |
+
left: 0 !important;
|
| 238 |
+
width: 100% !important;
|
| 239 |
+
background-color: white !important;
|
| 240 |
+
padding: 8px !important;
|
| 241 |
+
box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
|
| 242 |
+
z-index: 999;
|
| 243 |
+
}
|
| 244 |
+
/* 確保聊天區不被輸入列擋住 */
|
| 245 |
+
.gr-chatbot {
|
| 246 |
+
padding-bottom: 100px !important;
|
| 247 |
+
}
|
| 248 |
}
|
| 249 |
"""
|
| 250 |
) as demo:
|
|
|
|
| 267 |
with gr.Column(scale=4, min_width=300):
|
| 268 |
chatbot = gr.Chatbot(label="💬 對話紀錄", type="messages", height=500)
|
| 269 |
|
| 270 |
+
# ✅ 輸入框與送出鍵同行排列(桌機 8:2、手機 9:1)
|
| 271 |
with gr.Row(elem_id="chat-row"):
|
| 272 |
user_input = gr.Textbox(
|
| 273 |
+
placeholder="請輸入您的問題(Enter 送出 / Shift+Enter 換行)...",
|
| 274 |
show_label=False,
|
| 275 |
lines=1,
|
| 276 |
+
max_lines=3,
|
| 277 |
elem_id="chat-input",
|
| 278 |
scale=9
|
| 279 |
)
|
| 280 |
+
send_btn = gr.Button(
|
| 281 |
+
"送出",
|
| 282 |
+
variant="primary",
|
| 283 |
+
elem_id="send-btn",
|
| 284 |
+
scale=1
|
| 285 |
+
)
|
| 286 |
|
| 287 |
# === 輸入邏輯 ===
|
| 288 |
def handle_input(message, history):
|
|
|
|
| 297 |
]
|
| 298 |
return history, gr.update(value="")
|
| 299 |
|
| 300 |
+
# ✅ 綁定事件(Enter送出、Shift+Enter換行)
|
| 301 |
+
user_input.submit(handle_input, [user_input, chatbot], [chatbot, user_input]) # Enter
|
| 302 |
+
send_btn.click(handle_input, [user_input, chatbot], [chatbot, user_input]) # Button click
|
| 303 |
+
|
| 304 |
+
# ✅ JS 事件處理:Shift+Enter 換行、Enter 送出
|
| 305 |
+
gr.HTML("""
|
| 306 |
+
<script>
|
| 307 |
+
const textarea = document.querySelector('textarea');
|
| 308 |
+
if (textarea) {
|
| 309 |
+
textarea.addEventListener('keydown', function(e) {
|
| 310 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 311 |
+
e.preventDefault();
|
| 312 |
+
const sendBtn = document.querySelector('#send-btn button');
|
| 313 |
+
if (sendBtn) sendBtn.click();
|
| 314 |
+
}
|
| 315 |
+
});
|
| 316 |
+
}
|
| 317 |
+
</script>
|
| 318 |
+
""")
|
| 319 |
|
| 320 |
# 右側:常見問題 + 清除對話
|
| 321 |
with gr.Column(scale=1, min_width=200):
|