leonsimon23 commited on
Commit
6e456bb
·
verified ·
1 Parent(s): 9ef3461

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -28
app.py CHANGED
@@ -111,10 +111,8 @@ class FastGPTChat:
111
  return "", chat_history
112
 
113
  def create_chat_interface():
114
- # 创建FastGPT聊天实例
115
  fastgpt_chat = FastGPTChat()
116
 
117
- # 创建美化后的Gradio界面
118
  with gr.Blocks(
119
  title="AI用药咨询助手",
120
  css="""
@@ -170,42 +168,55 @@ def create_chat_interface():
170
  background-color: #ff6b81 !important;
171
  transform: translateY(-2px);
172
  }
173
- /* 优化对话区域样式 */
174
  .chatbot {
175
  background-color: #f8f9fa;
176
  border-radius: 10px;
177
  padding: 15px;
178
  margin-bottom: 20px;
179
  }
180
- /* 用户消息样式 */
181
- .chatbot .user-message {
182
- background-color: #fce4ec !important; /* 浅粉色背景 */
183
- border-radius: 15px 15px 2px 15px !important;
184
- padding: 10px 15px !important;
185
- margin: 5px 0 !important;
186
- max-width: 85% !important;
187
- float: right !important;
188
- clear: both !important;
189
- border: 1px solid #f48fb1 !important; /* 稍深一点的粉色边框 */
190
- }
 
 
 
 
 
 
191
  /* AI响应消息样式 */
192
  .chatbot .bot-message {
193
- background-color: #ffffff !important;
194
  border-radius: 15px 15px 15px 2px !important;
195
- padding: 10px 15px !important;
196
- margin: 5px 0 !important;
197
  max-width: 85% !important;
198
  float: left !important;
199
  clear: both !important;
200
- border: 1px solid #e0e0e0 !important;
201
- }
202
- /* 消息文本样式 */
203
- .chatbot .message-text {
204
  font-size: 15px !important;
205
- line-height: 1.5 !important;
206
- color: #2c3e50 !important;
207
- margin: 0 !important;
208
- word-wrap: break-word !important;
 
 
 
 
 
 
 
 
 
 
209
  }
210
  """
211
  ) as interface:
@@ -258,19 +269,16 @@ def create_chat_interface():
258
  api_name="chat"
259
  )
260
 
261
- # 添加回车发送支持
262
  message.submit(
263
  fastgpt_chat.chat,
264
  inputs=[message, chatbot],
265
  outputs=[message, chatbot]
266
  )
267
 
268
- # 清空对话
269
  clear.click(lambda: None, None, chatbot, queue=False)
270
 
271
  return interface
272
 
273
- # 使用示例
274
  if __name__ == "__main__":
275
  demo = create_chat_interface()
276
  demo.launch(debug=True)
 
111
  return "", chat_history
112
 
113
  def create_chat_interface():
 
114
  fastgpt_chat = FastGPTChat()
115
 
 
116
  with gr.Blocks(
117
  title="AI用药咨询助手",
118
  css="""
 
168
  background-color: #ff6b81 !important;
169
  transform: translateY(-2px);
170
  }
 
171
  .chatbot {
172
  background-color: #f8f9fa;
173
  border-radius: 10px;
174
  padding: 15px;
175
  margin-bottom: 20px;
176
  }
177
+ /* 移除消息背景的白色遮盖,优化对话样式 */
178
+ .chatbot > div {
179
+ background: transparent !important;
180
+ }
181
+ /* 用户消息样式 */
182
+ .chatbot .user-message {
183
+ background-color: #fce4ec !important;
184
+ border-radius: 15px 15px 2px 15px !important;
185
+ padding: 12px 18px !important;
186
+ margin: 8px 0 !important;
187
+ max-width: 85% !important;
188
+ float: right !important;
189
+ clear: both !important;
190
+ border: 1px solid #f48fb1 !important;
191
+ color: #1a1a1a !important;
192
+ font-size: 15px !important;
193
+ }
194
  /* AI响应消息样式 */
195
  .chatbot .bot-message {
196
+ background-color: #e8f5e9 !important;
197
  border-radius: 15px 15px 15px 2px !important;
198
+ padding: 12px 18px !important;
199
+ margin: 8px 0 !important;
200
  max-width: 85% !important;
201
  float: left !important;
202
  clear: both !important;
203
+ border: 1px solid #a5d6a7 !important;
204
+ color: #1a1a1a !important;
 
 
205
  font-size: 15px !important;
206
+ }
207
+ /* 消息容器样式 */
208
+ .chatbot > div > div {
209
+ padding: 0 !important;
210
+ gap: 2rem !important;
211
+ }
212
+ /* 头像样式 */
213
+ .chatbot span.avatar {
214
+ padding: 8px !important;
215
+ margin: 8px !important;
216
+ }
217
+ /* 确保消息之间有适当的间距 */
218
+ .chatbot > div > div:not(:last-child) {
219
+ margin-bottom: 15px !important;
220
  }
221
  """
222
  ) as interface:
 
269
  api_name="chat"
270
  )
271
 
 
272
  message.submit(
273
  fastgpt_chat.chat,
274
  inputs=[message, chatbot],
275
  outputs=[message, chatbot]
276
  )
277
 
 
278
  clear.click(lambda: None, None, chatbot, queue=False)
279
 
280
  return interface
281
 
 
282
  if __name__ == "__main__":
283
  demo = create_chat_interface()
284
  demo.launch(debug=True)