binqiangliu commited on
Commit
f8b49ee
·
1 Parent(s): c06de5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -6,37 +6,51 @@ import datetime
6
  st.set_page_config(page_title="AI Chat Client", layout="wide")
7
  st.title("AI Chat Client")
8
 
 
 
 
 
9
  # FastAPI 服务器的 URL
10
  fastapi_server_url = "https://binqiangliu-wechatarticleloaderfastapi.hf.space/get_ai_response"
11
 
12
  # 用户输入
13
  url = st.text_input("Enter the URL to chat with:")
 
 
14
  question = st.text_input("Enter your question:")
 
 
15
 
16
  # 当用户点击按钮时
17
  if st.button('Get AI Response'):
18
  if url and question:
 
 
19
  with st.spinner('Fetching AI response...'):
20
  # 构造请求
21
  data = {"url": url, "question": question}
22
  # 发送请求到 FastAPI 服务器
23
  current_datetime_0 = datetime.datetime.now()
24
- print(f'API调用请求发送开始 @ {current_datetime_0}')
 
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
  current_datetime_1 = datetime.datetime.now()
34
  print(f'获取API调用结果开始 @ {current_datetime_1}')
 
35
  start_2 = timeit.default_timer() # Start timer
36
  ai_response = response.json()
37
  ai_response_output=ai_response['AIResponse']
38
  end_2 = timeit.default_timer() # Start timer
39
  print(f'获取API调用结果完毕,共耗时: @ {end_2 - start_2}')
 
40
  st.write("AI Response:", ai_response)
41
  st.write("AI Response:", ai_response_output)
42
  else:
 
6
  st.set_page_config(page_title="AI Chat Client", layout="wide")
7
  st.title("AI Chat Client")
8
 
9
+ current_datetime_0= datetime.datetime.now()
10
+ print(f"Anything happens, this ST app will execute from top down. @ {current_datetime_0}")
11
+ print()
12
+
13
  # FastAPI 服务器的 URL
14
  fastapi_server_url = "https://binqiangliu-wechatarticleloaderfastapi.hf.space/get_ai_response"
15
 
16
  # 用户输入
17
  url = st.text_input("Enter the URL to chat with:")
18
+ print(f"URL Entered")
19
+ print()
20
  question = st.text_input("Enter your question:")
21
+ print(f"Question Entered")
22
+ print()
23
 
24
  # 当用户点击按钮时
25
  if st.button('Get AI Response'):
26
  if url and question:
27
+ print(f"URL & Question Entered & Button clicked.")
28
+ print()
29
  with st.spinner('Fetching AI response...'):
30
  # 构造请求
31
  data = {"url": url, "question": question}
32
  # 发送请求到 FastAPI 服务器
33
  current_datetime_0 = datetime.datetime.now()
34
+ print(f'API调用请求发送开始 @ {current_datetime_0}')
35
+ print()
36
  start_1 = timeit.default_timer() # Start timer
37
  response = requests.post(fastapi_server_url, json=data)
38
  end_1 = timeit.default_timer() # Start timer
39
  print(f'API调用请求发送结束,共耗时: @ {end_1 - start_1}')
40
+ print()
41
 
42
  if response.status_code == 200:
43
  # 显示 AI 的回答
44
  #ai_response = response.json().get("AI Response", "No response received.")
45
  current_datetime_1 = datetime.datetime.now()
46
  print(f'获取API调用结果开始 @ {current_datetime_1}')
47
+ print()
48
  start_2 = timeit.default_timer() # Start timer
49
  ai_response = response.json()
50
  ai_response_output=ai_response['AIResponse']
51
  end_2 = timeit.default_timer() # Start timer
52
  print(f'获取API调用结果完毕,共耗时: @ {end_2 - start_2}')
53
+ print()
54
  st.write("AI Response:", ai_response)
55
  st.write("AI Response:", ai_response_output)
56
  else: