leonsimon23 commited on
Commit
6bab5b6
·
verified ·
1 Parent(s): 54029fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -56
app.py CHANGED
@@ -104,128 +104,131 @@ def create_chat_interface():
104
  css="""
105
  /* 整体容器样式 */
106
  .container {
107
- width: 80%;
 
108
  margin: auto;
109
- padding: 2rem;
110
  box-sizing: border-box;
 
 
111
  }
112
-
113
  /* 标题区域样式 */
114
  .title-container {
115
  text-align: center;
116
- margin-bottom: 2rem;
117
  }
118
-
119
  .title-container h1 {
120
  color: #2C3E50;
121
- font-size: 2.5rem;
122
  margin-bottom: 0.5rem;
123
  }
124
-
125
  .title-container h3 {
126
  color: #7F8C8D;
127
- font-size: 1.2rem;
128
  font-weight: normal;
129
  }
130
-
131
  /* 聊天容器样式 */
132
  .chat-container {
133
  background-color: #FFFFFF;
134
  border-radius: 20px;
135
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
136
- padding: 2rem;
137
- margin-bottom: 2rem;
 
 
 
138
  }
139
-
140
  /* 聊天框样式 */
141
  .chatbot {
142
  background-color: #F8F9FA;
143
  border-radius: 15px;
144
- padding: 1.5rem;
145
- margin-bottom: 1.5rem;
146
- height: 400px !important;
147
  overflow-y: auto;
148
  }
149
-
150
  /* 消息样式 */
 
 
 
 
151
  .chatbot .user-message {
152
  background: linear-gradient(135deg, #6366F1, #4F46E5);
153
  color: white !important;
154
  border-radius: 18px 18px 4px 18px !important;
155
- padding: 1rem 1.5rem !important;
156
- margin: 1rem 0 !important;
157
- max-width: 80% !important;
158
  float: right !important;
159
  clear: both !important;
160
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2) !important;
161
  }
162
-
 
 
163
  .chatbot .bot-message {
164
  background: white !important;
165
  border: 1px solid #E5E7EB !important;
166
  color: #1F2937 !important;
167
  border-radius: 18px 18px 18px 4px !important;
168
- padding: 1rem 1.5rem !important;
169
- margin: 1rem 0 !important;
170
- max-width: 80% !important;
171
  float: left !important;
172
  clear: both !important;
173
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
174
  }
175
-
 
 
176
  /* 输入区域样式 */
177
  .input-container {
178
  background: white;
179
- padding: 1.5rem;
180
  border-radius: 15px;
181
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
 
 
 
182
  }
183
-
184
  .message-box {
185
  border: 2px solid #E5E7EB !important;
186
  border-radius: 12px !important;
187
- padding: 1rem !important;
188
- font-size: 1rem !important;
189
  transition: all 0.3s ease !important;
190
  background: white !important;
 
191
  }
192
-
193
  .message-box:focus {
194
  border-color: #6366F1 !important;
195
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2) !important;
196
  }
197
-
198
  /* 按钮样式 */
199
  .button-container {
200
  display: flex;
201
- gap: 1rem;
202
- margin-top: 1rem;
203
  }
204
-
205
  .submit-btn {
206
  background: linear-gradient(135deg, #6366F1, #4F46E5) !important;
207
  color: white !important;
208
- padding: 0.75rem 1.5rem !important;
209
  border-radius: 12px !important;
210
  font-weight: 600 !important;
211
  transition: all 0.3s ease !important;
212
- flex: 1;
213
  }
214
-
215
  .submit-btn:hover {
216
  transform: translateY(-2px);
217
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
218
  }
219
-
220
  .clear-btn {
221
  background: #EF4444 !important;
222
  color: white !important;
223
- padding: 0.75rem 1.5rem !important;
224
  border-radius: 12px !important;
225
  font-weight: 600 !important;
226
  transition: all 0.3s ease !important;
227
  }
228
-
229
  .clear-btn:hover {
230
  transform: translateY(-2px);
231
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
@@ -243,34 +246,36 @@ def create_chat_interface():
243
 
244
  with gr.Column(elem_classes="chat-container"):
245
  chatbot = gr.Chatbot(
246
- height=600,
247
- container=False,
248
- elem_classes="chatbot",
249
  show_label=False,
250
  bubble_full_width=False,
 
 
251
  avatar_images=("👤", "🤖")
252
  )
253
 
254
- with gr.Column(elem_classes="input-container"):
255
  message = gr.Textbox(
256
  show_label=False,
257
  placeholder="请输入您的用药问题...",
258
  container=False,
259
  elem_classes="message-box",
260
- lines=3
 
261
  )
262
-
263
- with gr.Row(elem_classes="button-container"):
264
- submit = gr.Button(
265
- "发送 💊",
266
- variant="primary",
267
- elem_classes="submit-btn"
268
- )
269
- clear = gr.Button(
270
- "清空对话 🗑️",
271
- variant="secondary",
272
- elem_classes="clear-btn"
273
- )
 
274
 
275
  # 设置事件处理
276
  submit_click = submit.click(
 
104
  css="""
105
  /* 整体容器样式 */
106
  .container {
107
+ width: 95vw;
108
+ height: 95vh;
109
  margin: auto;
110
+ padding: 1rem;
111
  box-sizing: border-box;
112
+ display: flex;
113
+ flex-direction: column;
114
  }
 
115
  /* 标题区域样式 */
116
  .title-container {
117
  text-align: center;
118
+ margin-bottom: 1rem;
119
  }
 
120
  .title-container h1 {
121
  color: #2C3E50;
122
+ font-size: 2rem;
123
  margin-bottom: 0.5rem;
124
  }
 
125
  .title-container h3 {
126
  color: #7F8C8D;
127
+ font-size: 1rem;
128
  font-weight: normal;
129
  }
 
130
  /* 聊天容器样式 */
131
  .chat-container {
132
  background-color: #FFFFFF;
133
  border-radius: 20px;
134
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
135
+ padding: 1rem;
136
+ margin-bottom: 1rem;
137
+ flex-grow: 1;
138
+ display: flex;
139
+ flex-direction: column;
140
  }
 
141
  /* 聊天框样式 */
142
  .chatbot {
143
  background-color: #F8F9FA;
144
  border-radius: 15px;
145
+ padding: 1rem;
146
+ margin-bottom: 0.5rem;
147
+ height: 100%;
148
  overflow-y: auto;
149
  }
 
150
  /* 消息样式 */
151
+ .chatbot .gr-box {
152
+ border: none !important;
153
+ box-shadow: none !important;
154
+ }
155
  .chatbot .user-message {
156
  background: linear-gradient(135deg, #6366F1, #4F46E5);
157
  color: white !important;
158
  border-radius: 18px 18px 4px 18px !important;
159
+ padding: 0.8rem 1.2rem !important;
160
+ margin: 0.5rem 0 !important;
161
+ max-width: 70% !important;
162
  float: right !important;
163
  clear: both !important;
164
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2) !important;
165
  }
166
+ .chatbot .user-message p {
167
+ color: white !important;
168
+ }
169
  .chatbot .bot-message {
170
  background: white !important;
171
  border: 1px solid #E5E7EB !important;
172
  color: #1F2937 !important;
173
  border-radius: 18px 18px 18px 4px !important;
174
+ padding: 0.8rem 1.2rem !important;
175
+ margin: 0.5rem 0 !important;
176
+ max-width: 70% !important;
177
  float: left !important;
178
  clear: both !important;
179
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
180
  }
181
+ .chatbot .bot-message p {
182
+ color: #1F2937 !important;
183
+ }
184
  /* 输入区域样式 */
185
  .input-container {
186
  background: white;
187
+ padding: 1rem;
188
  border-radius: 15px;
189
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
190
+ display: flex;
191
+ gap: 0.5rem;
192
+ align-items: center;
193
  }
 
194
  .message-box {
195
  border: 2px solid #E5E7EB !important;
196
  border-radius: 12px !important;
197
+ padding: 0.8rem !important;
198
+ font-size: 0.9rem !important;
199
  transition: all 0.3s ease !important;
200
  background: white !important;
201
+ flex-grow: 1;
202
  }
 
203
  .message-box:focus {
204
  border-color: #6366F1 !important;
205
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2) !important;
206
  }
 
207
  /* 按钮样式 */
208
  .button-container {
209
  display: flex;
210
+ gap: 0.5rem;
 
211
  }
 
212
  .submit-btn {
213
  background: linear-gradient(135deg, #6366F1, #4F46E5) !important;
214
  color: white !important;
215
+ padding: 0.6rem 1.2rem !important;
216
  border-radius: 12px !important;
217
  font-weight: 600 !important;
218
  transition: all 0.3s ease !important;
 
219
  }
 
220
  .submit-btn:hover {
221
  transform: translateY(-2px);
222
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
223
  }
 
224
  .clear-btn {
225
  background: #EF4444 !important;
226
  color: white !important;
227
+ padding: 0.6rem 1.2rem !important;
228
  border-radius: 12px !important;
229
  font-weight: 600 !important;
230
  transition: all 0.3s ease !important;
231
  }
 
232
  .clear-btn:hover {
233
  transform: translateY(-2px);
234
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
 
246
 
247
  with gr.Column(elem_classes="chat-container"):
248
  chatbot = gr.Chatbot(
249
+ label="",
 
 
250
  show_label=False,
251
  bubble_full_width=False,
252
+ container=False,
253
+ elem_classes="chatbot",
254
  avatar_images=("👤", "🤖")
255
  )
256
 
257
+ with gr.Row(elem_classes="input-container"):
258
  message = gr.Textbox(
259
  show_label=False,
260
  placeholder="请输入您的用药问题...",
261
  container=False,
262
  elem_classes="message-box",
263
+ lines=1,
264
+ scale=7
265
  )
266
+ submit = gr.Button(
267
+ "发送 💊",
268
+ variant="primary",
269
+ elem_classes="submit-btn",
270
+ scale=1
271
+ )
272
+ clear = gr.Button(
273
+ "清空对话 🗑️",
274
+ variant="secondary",
275
+ elem_classes="clear-btn",
276
+ scale=1
277
+ )
278
+
279
 
280
  # 设置事件处理
281
  submit_click = submit.click(