Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,47 +8,35 @@ import time
|
|
8 |
|
9 |
|
10 |
# 设置 FastGPT API 的基本信息
|
11 |
-
API_URL = "https://api.fastgpt.com/generate" # 请根据您的实际部署地址修改
|
|
|
|
|
|
|
|
|
|
|
12 |
API_KEY = "fastgpt-aleL83PzPiul9lZDJQFD4NHYfVIxP7mDIWFCyin2FuMhYgwlRC3NMkV2K5lxc8gF" # 请替换为您的实际 API 密钥
|
13 |
|
14 |
-
|
15 |
-
|
|
|
16 |
headers = {
|
17 |
"Authorization": f"Bearer {API_KEY}",
|
18 |
"Content-Type": "application/json"
|
19 |
}
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
def user(user_input, chat_history):
|
38 |
-
chat_history.append([user_input, None])
|
39 |
-
return "", chat_history
|
40 |
-
|
41 |
-
# 创建 Gradio 界面
|
42 |
-
with gr.Blocks() as demo:
|
43 |
-
chatbot = gr.Chatbot()
|
44 |
-
msg = gr.Textbox(placeholder="请输入您的消息...")
|
45 |
-
clear = gr.Button("清除")
|
46 |
-
submit = gr.Button("发送")
|
47 |
-
|
48 |
-
submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
49 |
-
chat_with_fastgpt, [msg, chatbot], [msg, chatbot]
|
50 |
-
)
|
51 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
52 |
-
|
53 |
-
# 启动 Gradio 界面
|
54 |
-
demo.launch()
|
|
|
8 |
|
9 |
|
10 |
# 设置 FastGPT API 的基本信息
|
11 |
+
#API_URL = "https://api.fastgpt.com/generate" # 请根据您的实际部署地址修改
|
12 |
+
#API_KEY = "fastgpt-aleL83PzPiul9lZDJQFD4NHYfVIxP7mDIWFCyin2FuMhYgwlRC3NMkV2K5lxc8gF" # 请替换为您的实际 API 密钥
|
13 |
+
|
14 |
+
#import gradio as gr
|
15 |
+
#import requests
|
16 |
+
|
17 |
API_KEY = "fastgpt-aleL83PzPiul9lZDJQFD4NHYfVIxP7mDIWFCyin2FuMhYgwlRC3NMkV2K5lxc8gF" # 请替换为您的实际 API 密钥
|
18 |
|
19 |
+
API_URL = "https://api.fastgpt.com/v1/chat"
|
20 |
+
|
21 |
+
def chat_with_fastgpt(prompt):
|
22 |
headers = {
|
23 |
"Authorization": f"Bearer {API_KEY}",
|
24 |
"Content-Type": "application/json"
|
25 |
}
|
26 |
+
payload = {
|
27 |
+
"model": "fastgpt",
|
28 |
+
"prompt": prompt
|
29 |
+
}
|
30 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
31 |
+
if response.status_code == 200:
|
32 |
+
return response.json().get("response", "I didn't get that.")
|
33 |
+
else:
|
34 |
+
return "Failed to get a response from the API."
|
35 |
+
|
36 |
+
iface = gr.Interface(fn=chat_with_fastgpt,
|
37 |
+
inputs="text",
|
38 |
+
outputs="text",
|
39 |
+
title="Chat with FastGPT")
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|