Spaces:
Sleeping
Sleeping
| 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 |