Update Streamlit UI to send messages to FastAPI chat endpoint
Browse files
app.py
CHANGED
|
@@ -40,6 +40,20 @@ else:
|
|
| 40 |
if user_input.strip() == "":
|
| 41 |
st.warning("Please enter a message.")
|
| 42 |
else:
|
| 43 |
-
#
|
| 44 |
st.markdown(f"**You:** {user_input}")
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if user_input.strip() == "":
|
| 41 |
st.warning("Please enter a message.")
|
| 42 |
else:
|
| 43 |
+
# Display user message
|
| 44 |
st.markdown(f"**You:** {user_input}")
|
| 45 |
+
|
| 46 |
+
# Send to backend
|
| 47 |
+
with st.spinner("AI Coach is thinking..."):
|
| 48 |
+
try:
|
| 49 |
+
response = requests.post(
|
| 50 |
+
"http://localhost:8000/api/chat",
|
| 51 |
+
json={"user_id": user, "message": user_input}
|
| 52 |
+
)
|
| 53 |
+
if response.status_code == 200:
|
| 54 |
+
ai_response = response.text # Adjust based on actual response format
|
| 55 |
+
st.markdown(f"**AI Coach:** {ai_response}")
|
| 56 |
+
else:
|
| 57 |
+
st.error("Failed to get response from AI Coach.")
|
| 58 |
+
except Exception as e:
|
| 59 |
+
st.error(f"Connection error: {e}")
|