Commit
·
f236a9e
1
Parent(s):
3d71864
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
6 |
+
|
7 |
+
# FastAPI 服务器的 URL
|
8 |
+
fastapi_server_url = "http://127.0.0.1:8000/get_ai_response/"
|
9 |
+
|
10 |
+
# 用户输入
|
11 |
+
url = st.text_input("Enter the URL to chat with:")
|
12 |
+
question = st.text_input("Enter your question:")
|
13 |
+
|
14 |
+
# 当用户点击按钮时
|
15 |
+
if st.button('Get AI Response'):
|
16 |
+
if url and question:
|
17 |
+
with st.spinner('Fetching AI response...'):
|
18 |
+
# 构造请求
|
19 |
+
data = {"url": url, "question": question}
|
20 |
+
# 发送请求到 FastAPI 服务器
|
21 |
+
response = requests.post(fastapi_server_url, json=data)
|
22 |
+
|
23 |
+
if response.status_code == 200:
|
24 |
+
# 显示 AI 的回答
|
25 |
+
ai_response = response.json().get("AI Response", "No response received.")
|
26 |
+
st.write("AI Response:", ai_response)
|
27 |
+
else:
|
28 |
+
# 显示错误信息
|
29 |
+
st.error("Error in fetching response from AI server.")
|
30 |
+
else:
|
31 |
+
st.warning("Please enter both URL and a question.")
|