|
import streamlit as st |
|
from responses import generate_response |
|
|
|
|
|
|
|
if "disabled" not in st.session_state: |
|
st.session_state.disabled = False |
|
|
|
def disable(): |
|
st.session_state.disabled = True |
|
|
|
username = st.text_input( |
|
"participant id", |
|
disabled=st.session_state.disabled, |
|
on_change=disable |
|
).lower() |
|
|
|
|
|
|
|
user_list = ['1', '2', '3'] |
|
user_name_list = ['Paricipant 1', 'Paricipant 2', 'Paricipant 3'] |
|
|
|
|
|
|
|
if(username.lower() in user_list): |
|
conv_id = user_list.index(username) |
|
history = [] |
|
|
|
|
|
if "messages" not in st.session_state.keys(): |
|
st.session_state.messages = [{"role": "assistant", "content": "Welcome back, " + user_name_list[conv_id]}] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if prompt := st.chat_input("What's on your mind"): |
|
st.session_state.messages.append({"role": "user", "content": prompt}) |
|
with st.chat_message("user"): |
|
st.markdown(prompt) |
|
|
|
|
|
if st.session_state.messages[-1]["role"] != "assistant": |
|
with st.chat_message("assistant"): |
|
with st.spinner("Thinking..."): |
|
|
|
for i in range(len(st.session_state.messages)): |
|
if(st.session_state.messages[i]["role"] != "assistant"): |
|
history.append(st.session_state.messages[i]["content"]) |
|
gen_prompt = "List of my past requests: " + str(history[-6:-1]) + ". Based on my past requests, please answer me only this request: \"" + prompt + "\"" |
|
|
|
|
|
print(gen_prompt) |
|
response = generate_response(gen_prompt) |
|
st.markdown(response) |
|
message = {"role": "assistant", "content": response} |
|
st.session_state.messages.append(message) |
|
|
|
elif(username != ""): |
|
st.markdown("You are not in the user list") |