Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,18 @@ class FastGPTChat:
|
|
| 18 |
"Authorization": f"Bearer {api_key}",
|
| 19 |
"Content-Type": "application/json"
|
| 20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def chat(self, message, chat_history):
|
| 23 |
if not message.strip():
|
|
@@ -155,12 +167,42 @@ def create_chat_interface():
|
|
| 155 |
background-color: #ff6b81 !important;
|
| 156 |
transform: translateY(-2px);
|
| 157 |
}
|
|
|
|
| 158 |
.chatbot {
|
| 159 |
background-color: #f8f9fa;
|
| 160 |
border-radius: 10px;
|
| 161 |
-
padding:
|
| 162 |
margin-bottom: 20px;
|
| 163 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
"""
|
| 165 |
) as interface:
|
| 166 |
with gr.Column(elem_classes="container"):
|
|
@@ -176,7 +218,9 @@ def create_chat_interface():
|
|
| 176 |
height=500,
|
| 177 |
container=False,
|
| 178 |
elem_classes="chatbot",
|
| 179 |
-
show_label=False
|
|
|
|
|
|
|
| 180 |
)
|
| 181 |
|
| 182 |
with gr.Row(elem_id="input-container"):
|
|
|
|
| 18 |
"Authorization": f"Bearer {api_key}",
|
| 19 |
"Content-Type": "application/json"
|
| 20 |
}
|
| 21 |
+
|
| 22 |
+
def __init__(self, system_prompt="我是一名AI用药咨询顾问,请向我提问有关用药的问题"):
|
| 23 |
+
# 从环境变量获取API密钥和基础URL
|
| 24 |
+
self.api_key = os.environ.get('FASTGPT_API_KEY')
|
| 25 |
+
self.base_url = os.environ.get('FASTGPT_BASE_URL', 'https://api.fastgpt.in/api')
|
| 26 |
+
self.system_prompt = system_prompt
|
| 27 |
+
self.headers = {
|
| 28 |
+
"Authorization": f"Bearer {self.api_key}",
|
| 29 |
+
"Content-Type": "application/json"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
|
| 34 |
def chat(self, message, chat_history):
|
| 35 |
if not message.strip():
|
|
|
|
| 167 |
background-color: #ff6b81 !important;
|
| 168 |
transform: translateY(-2px);
|
| 169 |
}
|
| 170 |
+
/* 优化对话区域样式 */
|
| 171 |
.chatbot {
|
| 172 |
background-color: #f8f9fa;
|
| 173 |
border-radius: 10px;
|
| 174 |
+
padding: 15px;
|
| 175 |
margin-bottom: 20px;
|
| 176 |
}
|
| 177 |
+
/* 用户消息样式 */
|
| 178 |
+
.chatbot .user-message {
|
| 179 |
+
background-color: #e3f2fd !important;
|
| 180 |
+
border-radius: 15px 15px 2px 15px !important;
|
| 181 |
+
padding: 10px 15px !important;
|
| 182 |
+
margin: 5px 0 !important;
|
| 183 |
+
max-width: 85% !important;
|
| 184 |
+
float: right !important;
|
| 185 |
+
clear: both !important;
|
| 186 |
+
}
|
| 187 |
+
/* AI响应消息样式 */
|
| 188 |
+
.chatbot .bot-message {
|
| 189 |
+
background-color: #ffffff !important;
|
| 190 |
+
border-radius: 15px 15px 15px 2px !important;
|
| 191 |
+
padding: 10px 15px !important;
|
| 192 |
+
margin: 5px 0 !important;
|
| 193 |
+
max-width: 85% !important;
|
| 194 |
+
float: left !important;
|
| 195 |
+
clear: both !important;
|
| 196 |
+
border: 1px solid #e0e0e0 !important;
|
| 197 |
+
}
|
| 198 |
+
/* 消息文本样式 */
|
| 199 |
+
.chatbot .message-text {
|
| 200 |
+
font-size: 15px !important;
|
| 201 |
+
line-height: 1.5 !important;
|
| 202 |
+
color: #2c3e50 !important;
|
| 203 |
+
margin: 0 !important;
|
| 204 |
+
word-wrap: break-word !important;
|
| 205 |
+
}
|
| 206 |
"""
|
| 207 |
) as interface:
|
| 208 |
with gr.Column(elem_classes="container"):
|
|
|
|
| 218 |
height=500,
|
| 219 |
container=False,
|
| 220 |
elem_classes="chatbot",
|
| 221 |
+
show_label=False,
|
| 222 |
+
bubble_full_width=False,
|
| 223 |
+
avatar_images=("👤", "🤖")
|
| 224 |
)
|
| 225 |
|
| 226 |
with gr.Row(elem_id="input-container"):
|