Update app.py
Browse files
app.py
CHANGED
|
@@ -186,10 +186,6 @@ with gr.Blocks(css="""
|
|
| 186 |
font-family: 'Segoe UI', sans-serif;
|
| 187 |
}
|
| 188 |
|
| 189 |
-
.gr-chatbot {
|
| 190 |
-
background-color: transparent !important;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
.message.user {
|
| 194 |
background-color: #cce6ff !important; /* Much lighter blue */
|
| 195 |
color: #000000 !important;
|
|
@@ -263,12 +259,12 @@ with gr.Blocks(css="""
|
|
| 263 |
请回答下面的问题,开始你的职业规划之旅!
|
| 264 |
""")
|
| 265 |
|
| 266 |
-
# 创建聊天界面
|
| 267 |
chatbot = gr.Chatbot(
|
| 268 |
height=500,
|
| 269 |
-
bubble_full_width=False,
|
| 270 |
show_label=False,
|
| 271 |
-
show_copy_button=True
|
|
|
|
| 272 |
)
|
| 273 |
|
| 274 |
# 输入框和按钮
|
|
@@ -287,27 +283,39 @@ with gr.Blocks(css="""
|
|
| 287 |
with gr.Row():
|
| 288 |
reset_btn = gr.Button("🔄 重新开始")
|
| 289 |
|
| 290 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
submit_btn.click(
|
| 292 |
-
fn=
|
| 293 |
inputs=[msg, chatbot],
|
| 294 |
-
outputs=[msg, chatbot]
|
| 295 |
-
queue=False
|
| 296 |
).then(
|
| 297 |
-
fn=
|
| 298 |
-
inputs=[chatbot
|
| 299 |
-
outputs=[chatbot
|
| 300 |
)
|
| 301 |
|
|
|
|
| 302 |
msg.submit(
|
| 303 |
-
fn=
|
| 304 |
inputs=[msg, chatbot],
|
| 305 |
-
outputs=[msg, chatbot]
|
| 306 |
-
queue=False
|
| 307 |
).then(
|
| 308 |
-
fn=
|
| 309 |
-
inputs=[chatbot
|
| 310 |
-
outputs=[chatbot
|
| 311 |
)
|
| 312 |
|
| 313 |
# 重置功能
|
|
@@ -327,10 +335,9 @@ with gr.Blocks(css="""
|
|
| 327 |
)
|
| 328 |
|
| 329 |
# 当页面加载时自动触发第一个问题
|
| 330 |
-
def auto_first_question():
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
|
| 335 |
-
|
| 336 |
-
demo.load(auto_first_question, inputs=None, outputs=chatbot, show_progress=False)
|
|
|
|
| 186 |
font-family: 'Segoe UI', sans-serif;
|
| 187 |
}
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
.message.user {
|
| 190 |
background-color: #cce6ff !important; /* Much lighter blue */
|
| 191 |
color: #000000 !important;
|
|
|
|
| 259 |
请回答下面的问题,开始你的职业规划之旅!
|
| 260 |
""")
|
| 261 |
|
| 262 |
+
# 创建聊天界面 - 修复类型和属性
|
| 263 |
chatbot = gr.Chatbot(
|
| 264 |
height=500,
|
|
|
|
| 265 |
show_label=False,
|
| 266 |
+
show_copy_button=True,
|
| 267 |
+
type="messages" # 指定类型为messages
|
| 268 |
)
|
| 269 |
|
| 270 |
# 输入框和按钮
|
|
|
|
| 283 |
with gr.Row():
|
| 284 |
reset_btn = gr.Button("🔄 重新开始")
|
| 285 |
|
| 286 |
+
# 修复事件处理
|
| 287 |
+
def add_message(message, history):
|
| 288 |
+
history = history or []
|
| 289 |
+
history.append({"role": "user", "content": message})
|
| 290 |
+
return "", history
|
| 291 |
+
|
| 292 |
+
def bot_response(history):
|
| 293 |
+
history = history or []
|
| 294 |
+
user_message = history[-1]["content"]
|
| 295 |
+
bot_message = predict(user_message, history[:-1] if len(history) > 1 else [])
|
| 296 |
+
history.append({"role": "assistant", "content": bot_message})
|
| 297 |
+
return history
|
| 298 |
+
|
| 299 |
+
# 提交按钮点击事件
|
| 300 |
submit_btn.click(
|
| 301 |
+
fn=add_message,
|
| 302 |
inputs=[msg, chatbot],
|
| 303 |
+
outputs=[msg, chatbot]
|
|
|
|
| 304 |
).then(
|
| 305 |
+
fn=bot_response,
|
| 306 |
+
inputs=[chatbot],
|
| 307 |
+
outputs=[chatbot]
|
| 308 |
)
|
| 309 |
|
| 310 |
+
# 文本框提交事件
|
| 311 |
msg.submit(
|
| 312 |
+
fn=add_message,
|
| 313 |
inputs=[msg, chatbot],
|
| 314 |
+
outputs=[msg, chatbot]
|
|
|
|
| 315 |
).then(
|
| 316 |
+
fn=bot_response,
|
| 317 |
+
inputs=[chatbot],
|
| 318 |
+
outputs=[chatbot]
|
| 319 |
)
|
| 320 |
|
| 321 |
# 重置功能
|
|
|
|
| 335 |
)
|
| 336 |
|
| 337 |
# 当页面加载时自动触发第一个问题
|
| 338 |
+
def auto_first_question():
|
| 339 |
+
return [{"role": "assistant", "content": questions[0][1]}]
|
| 340 |
+
|
| 341 |
+
demo.load(auto_first_question, inputs=None, outputs=chatbot)
|
| 342 |
|
| 343 |
+
demo.launch()
|
|
|