binqiangliu's picture
Update app.py
5e092ec
raw
history blame
1.25 kB
import streamlit as st
import requests
st.set_page_config(page_title="AI Chat Client", layout="wide")
st.title("AI Chat Client")
# FastAPI 服务器的 URL
fastapi_server_url = "https://binqiangliu-wechatarticleloaderfastapi.hf.space/get_ai_response"
# 用户输入
url = st.text_input("Enter the URL to chat with:")
question = st.text_input("Enter your question:")
# 当用户点击按钮时
if st.button('Get AI Response'):
if url and question:
with st.spinner('Fetching AI response...'):
# 构造请求
data = {"url": url, "question": question}
# 发送请求到 FastAPI 服务器
response = requests.post(fastapi_server_url, json=data)
if response.status_code == 200:
# 显示 AI 的回答
#ai_response = response.json().get("AI Response", "No response received.")
ai_response = response.json()
ai_response_output=ai_response['AIResponse']
st.write("AI Response:", ai_response)
else:
# 显示错误信息
st.error("Error in fetching response from AI server.")
else:
st.warning("Please enter both URL and a question.")