-
Notifications
You must be signed in to change notification settings - Fork 0
/
front.py
68 lines (52 loc) · 2 KB
/
front.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import streamlit as st
from src import utils
# Define your username and password
USERNAME = "admin"
PASSWORD = "admin"
def authenticate(username, password):
return username == USERNAME and password == PASSWORD
# Authentication form
def login():
st.title("Login")
username = st.text_input("Username")
password = st.text_input("Password", type="password")
if st.button("Login"):
if authenticate(username, password):
st.session_state["authenticated"] = True
st.rerun()
else:
st.error("Invalid username or password")
# Check if the user is authenticated
if "authenticated" not in st.session_state:
st.session_state["authenticated"] = False
if not st.session_state["authenticated"]:
login()
else:
st.title("Merger Agreement chatbot")
# Initialize chat history
def reinit_session_state():
pass # Your existing code here
# Initialize chat history
def reinit_session_state():
if "messages" not in st.session_state:
st.session_state.messages = []
def display_history(N=50):
# Display chat messages from history on app rerun
for message in st.session_state.messages[:N]:
with st.chat_message(message["role"]):
st.markdown(message["content"])
reinit_session_state()
display_history()
# React to user input
if st.session_state["authenticated"]:
if prompt := st.chat_input("What is up?"):
# Display user message in chat message container
st.chat_message("user").markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
response = utils.send_request('chat_response', {"user_prompt": prompt},method='POST')['response']
# Display assistant response in chat message container
with st.chat_message("assistant"):
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})