-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapp.py
44 lines (34 loc) · 1.22 KB
/
app.py
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
37
38
39
40
41
42
43
import chat
import streamlit as st
from streamlit_chat import message
#Creating the chatbot interface
st.title("LLM-Powered Chatbot for Intelligent Conversations")
st.subheader("AVA-Abonia Virtual Assistant")
# Storing the chat
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
# Define a function to clear the input text
def clear_input_text():
global input_text
input_text = ""
# We will get the user's input by calling the get_text function
def get_text():
global input_text
input_text = st.text_input("Ask your Question", key="input", on_change=clear_input_text)
return input_text
def main():
user_input = get_text()
if user_input:
output = chat.answer(user_input)
# store the output
st.session_state.past.append(user_input)
st.session_state.generated.append(output)
if st.session_state['generated']:
for i in range(len(st.session_state['generated'])-1, -1, -1):
message(st.session_state["generated"][i], key=str(i))
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
# Run the app
if __name__ == "__main__":
main()