Commit
·
0c4b8aa
1
Parent(s):
78043f5
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
|
|
3 |
|
4 |
st.set_page_config(page_title="AI Chat Client", layout="wide")
|
5 |
st.title("AI Chat Client")
|
@@ -18,17 +20,26 @@ if st.button('Get AI Response'):
|
|
18 |
# 构造请求
|
19 |
data = {"url": url, "question": question}
|
20 |
# 发送请求到 FastAPI 服务器
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
if response.status_code == 200:
|
24 |
# 显示 AI 的回答
|
25 |
#ai_response = response.json().get("AI Response", "No response received.")
|
|
|
|
|
26 |
ai_response = response.json()
|
27 |
ai_response_output=ai_response['AIResponse']
|
|
|
|
|
28 |
st.write("AI Response:", ai_response)
|
29 |
st.write("AI Response:", ai_response_output)
|
30 |
else:
|
31 |
# 显示错误信息
|
32 |
st.error("Error in fetching response from AI server.")
|
33 |
else:
|
34 |
-
st.warning("Please enter both URL and a question.")
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
import timeit
|
4 |
+
import datetime
|
5 |
|
6 |
st.set_page_config(page_title="AI Chat Client", layout="wide")
|
7 |
st.title("AI Chat Client")
|
|
|
20 |
# 构造请求
|
21 |
data = {"url": url, "question": question}
|
22 |
# 发送请求到 FastAPI 服务器
|
23 |
+
current_datetime_0 = datetime.datetime.now()
|
24 |
+
print(f'API调用请求发送开始 @ {current_datetime}')
|
25 |
+
start_1 = timeit.default_timer() # Start timer
|
26 |
+
response = requests.post(fastapi_server_url, json=data)
|
27 |
+
end_1 = timeit.default_timer() # Start timer
|
28 |
+
print(f'API调用请求发送结束,共耗时: @ {end_1 - start_1}')
|
29 |
|
30 |
if response.status_code == 200:
|
31 |
# 显示 AI 的回答
|
32 |
#ai_response = response.json().get("AI Response", "No response received.")
|
33 |
+
print(f'获取API调用结果开始 @ {current_datetime}')
|
34 |
+
start_2 = timeit.default_timer() # Start timer
|
35 |
ai_response = response.json()
|
36 |
ai_response_output=ai_response['AIResponse']
|
37 |
+
end_2 = timeit.default_timer() # Start timer
|
38 |
+
print(f'获取API调用结果完毕,共耗时: @ {end_2 - start_2}')
|
39 |
st.write("AI Response:", ai_response)
|
40 |
st.write("AI Response:", ai_response_output)
|
41 |
else:
|
42 |
# 显示错误信息
|
43 |
st.error("Error in fetching response from AI server.")
|
44 |
else:
|
45 |
+
st.warning("Please enter both URL and a question.")
|