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