-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (26 loc) · 1.12 KB
/
app.py
File metadata and controls
35 lines (26 loc) · 1.12 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
import streamlit as st
from chatbot_model import get_response, pred_class, words, classes, intents_json
# My Streamlit app
st.title("Chat with Our Adaptica AI")
# For Initializing the chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Displaying the chat history
for message in st.session_state.messages:
if message["role"] == "user":
st.write(f"**You:** {message['content']}")
else:
st.write(f"**Bot:** {message['content']}")
# User input
user_input = st.text_input("You:", "")
# Handling the user input
if st.button("Send"):
if user_input:
# Appending the user message
st.session_state.messages.append({"role": "user", "content": user_input})
# Getting the bot response
intents_list = pred_class(user_input, words, classes) # Ensure this returns a list
bot_response = get_response(intents_list, intents_json) # Pass intents_list and intents_json
# Appending the bot response
st.session_state.messages.append({"role": "bot", "content": bot_response})
st.session_state.text_input = ""