-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_ui.py
More file actions
36 lines (28 loc) · 1.03 KB
/
chat_ui.py
File metadata and controls
36 lines (28 loc) · 1.03 KB
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
36
import streamlit as st
import requests
# Set up the Streamlit app
st.title("💬 FAQ Chatbot")
st.write("Ask a question and continue the conversation!")
# Initialize chat history in session state
if "messages" not in st.session_state:
st.session_state.messages = []
# Display previous chat messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.write(message["content"])
# User input field
user_input = st.chat_input("Type your question right here...")
if user_input:
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": user_input})
# Send request to Flask API
response = requests.post(
"http://127.0.0.1:5000/chat",
json={"question": user_input}
)
if response.status_code == 200:
bot_response = response.json().get("response", "No response available.")
else:
bot_response = " Error: Could not get a response."
st.session_state.messages.append({"role": "assistant", "content": bot_response})
st.rerun()