Spaces:
Sleeping
Sleeping
File size: 1,058 Bytes
f9b7370 5c52716 f9b7370 bb9e1d8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import streamlit as st
import requests
from requests.exceptions import RequestException
BACKEND_URL = "http://localhost:8000"
st.title("AgentAI")
# Use a different variable name to avoid shadowing the built-in `input()`
prompt = st.text_input("Enter your prompt:")
if st.button("Send"):
if not prompt:
st.warning("Please enter a prompt before sending.")
else:
try:
with st.spinner("Sending to backend..."):
resp = requests.post(
f"{BACKEND_URL}/chat",
json={"input": prompt},
timeout=15,
)
if resp.status_code == 200:
# use resp.json() to parse JSON body
data = resp.json()
st.success("Response received")
st.write(data.get("response"))
else:
st.error(f"Backend returned status {resp.status_code}: {resp.text}")
except RequestException as e:
st.error(f"Error sending request to backend: {e}")
# yoyo |