rdune71 commited on
Commit
b1aeb5a
·
1 Parent(s): 11ba014

Update Streamlit UI to send messages to FastAPI chat endpoint

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -40,6 +40,20 @@ else:
40
  if user_input.strip() == "":
41
  st.warning("Please enter a message.")
42
  else:
43
- # TODO: Send to backend and get response
44
  st.markdown(f"**You:** {user_input}")
45
- st.markdown(f"**AI Coach:** [Response will appear here after backend integration.]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")