Update app.py
Browse files
app.py
CHANGED
|
@@ -206,39 +206,44 @@ with gr.Blocks(css="""
|
|
| 206 |
background-color: #25D366 !important;
|
| 207 |
color: white !important;
|
| 208 |
border: none;
|
| 209 |
-
border-radius:
|
| 210 |
font-size: 20px;
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
margin
|
| 215 |
cursor: pointer;
|
| 216 |
}
|
| 217 |
#chatbox .avatar-container {
|
| 218 |
-
width:
|
| 219 |
-
height:
|
| 220 |
-
min-width:
|
| 221 |
-
min-height:
|
|
|
|
| 222 |
background-size: 100% 100% !important;
|
| 223 |
background-position: center center !important;
|
| 224 |
border-radius: 50% !important;
|
| 225 |
padding: 0 !important;
|
| 226 |
-
margin: 0 !important;
|
| 227 |
border: none !important;
|
| 228 |
box-shadow: none !important;
|
| 229 |
background-color: transparent !important;
|
| 230 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
#chatbox .message.user { background-color: #DCF8C6 !important; }
|
| 232 |
#chatbox .message.assistant { background-color: #ffffff !important; }
|
| 233 |
footer { display: none !important; }
|
| 234 |
.svelte-1ipelgc { display: none !important; }
|
| 235 |
-
.icon-button-wrapper {
|
| 236 |
-
|
| 237 |
-
}
|
| 238 |
-
label.svelte-1to105q {
|
| 239 |
-
display: none !important;
|
| 240 |
-
}
|
| 241 |
""") as demo:
|
|
|
|
|
|
|
| 242 |
gr.HTML("""
|
| 243 |
<script>
|
| 244 |
const waitForChatbox = () => {
|
|
@@ -256,31 +261,36 @@ label.svelte-1to105q {
|
|
| 256 |
</script>
|
| 257 |
""")
|
| 258 |
|
|
|
|
| 259 |
chatbot = gr.Chatbot(
|
| 260 |
elem_id="chatbox",
|
| 261 |
label="",
|
| 262 |
avatar_images=["user_avatar.jpg", "humanlike_avatar.png"],
|
| 263 |
bubble_full_width=False,
|
| 264 |
-
height=
|
| 265 |
show_copy_button=False,
|
| 266 |
type="messages"
|
| 267 |
)
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
| 277 |
|
|
|
|
| 278 |
state = gr.State([])
|
| 279 |
step = gr.State(0)
|
| 280 |
language = gr.State("")
|
| 281 |
questions = gr.State([])
|
| 282 |
followup_mode = gr.State(False)
|
| 283 |
|
|
|
|
| 284 |
demo.load(fn=init, outputs=[chatbot, step, language, questions, followup_mode])
|
| 285 |
user_input.submit(respond, [user_input, state, step, language, questions, followup_mode],
|
| 286 |
[chatbot, user_input, step, language, questions, followup_mode])
|
|
|
|
| 206 |
background-color: #25D366 !important;
|
| 207 |
color: white !important;
|
| 208 |
border: none;
|
| 209 |
+
border-radius: 10px;
|
| 210 |
font-size: 20px;
|
| 211 |
+
height: 42px;
|
| 212 |
+
width: 100%;
|
| 213 |
+
padding: 0;
|
| 214 |
+
margin: 0;
|
| 215 |
cursor: pointer;
|
| 216 |
}
|
| 217 |
#chatbox .avatar-container {
|
| 218 |
+
width: 48px !important;
|
| 219 |
+
height: 48px !important;
|
| 220 |
+
min-width: 48px !important;
|
| 221 |
+
min-height: 48px !important;
|
| 222 |
+
margin-right: 8px !important;
|
| 223 |
background-size: 100% 100% !important;
|
| 224 |
background-position: center center !important;
|
| 225 |
border-radius: 50% !important;
|
| 226 |
padding: 0 !important;
|
|
|
|
| 227 |
border: none !important;
|
| 228 |
box-shadow: none !important;
|
| 229 |
background-color: transparent !important;
|
| 230 |
}
|
| 231 |
+
#chatbox .message {
|
| 232 |
+
line-height: 1.6em !important;
|
| 233 |
+
padding: 10px 14px !important;
|
| 234 |
+
border-radius: 12px !important;
|
| 235 |
+
font-size: 16px !important;
|
| 236 |
+
max-width: 85% !important;
|
| 237 |
+
}
|
| 238 |
#chatbox .message.user { background-color: #DCF8C6 !important; }
|
| 239 |
#chatbox .message.assistant { background-color: #ffffff !important; }
|
| 240 |
footer { display: none !important; }
|
| 241 |
.svelte-1ipelgc { display: none !important; }
|
| 242 |
+
.icon-button-wrapper { display: none !important; }
|
| 243 |
+
label.svelte-1to105q { display: none !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
""") as demo:
|
| 245 |
+
|
| 246 |
+
# 自动滚动到底部的脚本
|
| 247 |
gr.HTML("""
|
| 248 |
<script>
|
| 249 |
const waitForChatbox = () => {
|
|
|
|
| 261 |
</script>
|
| 262 |
""")
|
| 263 |
|
| 264 |
+
# 聊天框
|
| 265 |
chatbot = gr.Chatbot(
|
| 266 |
elem_id="chatbox",
|
| 267 |
label="",
|
| 268 |
avatar_images=["user_avatar.jpg", "humanlike_avatar.png"],
|
| 269 |
bubble_full_width=False,
|
| 270 |
+
height="80vh",
|
| 271 |
show_copy_button=False,
|
| 272 |
type="messages"
|
| 273 |
)
|
| 274 |
|
| 275 |
+
# 输入 + 发送按钮布局(两列)
|
| 276 |
+
with gr.Row(equal_height=True):
|
| 277 |
+
with gr.Column(scale=11):
|
| 278 |
+
user_input = gr.Textbox(
|
| 279 |
+
show_label=False,
|
| 280 |
+
placeholder="Type your message here and press send...",
|
| 281 |
+
container=True
|
| 282 |
+
)
|
| 283 |
+
with gr.Column(scale=1, min_width=48):
|
| 284 |
+
send_btn = gr.Button(value="➤", elem_classes="send-btn")
|
| 285 |
|
| 286 |
+
# 状态变量
|
| 287 |
state = gr.State([])
|
| 288 |
step = gr.State(0)
|
| 289 |
language = gr.State("")
|
| 290 |
questions = gr.State([])
|
| 291 |
followup_mode = gr.State(False)
|
| 292 |
|
| 293 |
+
# 加载和按钮触发
|
| 294 |
demo.load(fn=init, outputs=[chatbot, step, language, questions, followup_mode])
|
| 295 |
user_input.submit(respond, [user_input, state, step, language, questions, followup_mode],
|
| 296 |
[chatbot, user_input, step, language, questions, followup_mode])
|