Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_chat import message
|
| 3 |
|
|
@@ -9,27 +11,35 @@ from langchain.chains import ConversationalRetrievalChain
|
|
| 9 |
from langchain_openai import ChatOpenAI
|
| 10 |
from langchain_community.vectorstores import Chroma
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
st.sidebar.title("Introduction")
|
| 14 |
st.sidebar.markdown("""
|
| 15 |
-
|
| 16 |
|
| 17 |
<ul style='text-align: left;'>
|
| 18 |
-
<li><strong>
|
| 19 |
-
|
| 20 |
-
<li><strong>
|
| 21 |
-
|
| 22 |
-
<li><strong>Secure Interaction</strong>: Streamlit's session state management is used for secure API key handling and user input retention across sessions.</li>
|
| 23 |
</ul>
|
| 24 |
|
| 25 |
ChatMate is developed by Lorentz Yeung
|
| 26 |
""", unsafe_allow_html=True)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
#if 'API_Key' not in st.session_state:
|
| 29 |
# st.session_state['API_Key'] =''
|
| 30 |
#st.session_state['API_Key']= st.text_input("First, to get it work, put your OpenAI API Key here please, the system will enter for you automatically.",type="password")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
# uploaded_file = st.sidebar.file_uploader("upload", type="csv")
|
| 34 |
|
| 35 |
persist_directory = "chroma/db"
|
|
@@ -56,10 +66,10 @@ if persist_directory :
|
|
| 56 |
st.session_state['history'] = []
|
| 57 |
|
| 58 |
if 'ai_history' not in st.session_state:
|
| 59 |
-
st.session_state['ai_history'] = ["
|
| 60 |
|
| 61 |
if 'user_history' not in st.session_state:
|
| 62 |
-
st.session_state['user_history'] = ["I would like to know more about the KaggleX
|
| 63 |
|
| 64 |
#container for the chat history
|
| 65 |
response_container = st.container()
|
|
@@ -69,7 +79,7 @@ if persist_directory :
|
|
| 69 |
with container:
|
| 70 |
with st.form(key='my_form', clear_on_submit=True):
|
| 71 |
|
| 72 |
-
user_input = st.text_input("
|
| 73 |
submit_button = st.form_submit_button(label='Ask')
|
| 74 |
|
| 75 |
if submit_button and user_input:
|
|
@@ -82,6 +92,6 @@ if persist_directory :
|
|
| 82 |
if st.session_state['ai_history']:
|
| 83 |
with response_container:
|
| 84 |
for i in range(len(st.session_state['ai_history'])):
|
| 85 |
-
message(st.session_state["user_history"][i], is_user=True, key=str(i) + '_user', avatar_style="
|
| 86 |
-
message(st.session_state["ai_history"][i], key=str(i), avatar_style="
|
| 87 |
|
|
|
|
| 1 |
+
# https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps#build-a-chatgpt-like-app
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
from streamlit_chat import message
|
| 5 |
|
|
|
|
| 11 |
from langchain_openai import ChatOpenAI
|
| 12 |
from langchain_community.vectorstores import Chroma
|
| 13 |
|
| 14 |
+
#####################################################
|
| 15 |
+
##################### Sidebar #######################
|
| 16 |
st.sidebar.title("Introduction")
|
| 17 |
st.sidebar.markdown("""
|
| 18 |
+
KaggleX AI Course Coordinator is an advanced conversational AI interface, expertly crafted to solve the data scientist learners' problems.
|
| 19 |
|
| 20 |
<ul style='text-align: left;'>
|
| 21 |
+
<li><strong>What is the Learning Path Index Project?</strong>: To consolidate a data base of a collection of byte-sized courses/material for Data Science and Machine Learning so that it is
|
| 22 |
+
easy to search, filter</li>
|
| 23 |
+
<li><strong>Why Do We Need It?</strong>: Addresses problems like long course durations, difficulty in finding specific topics, and the absence of a centralized index.</li>
|
| 24 |
+
|
|
|
|
| 25 |
</ul>
|
| 26 |
|
| 27 |
ChatMate is developed by Lorentz Yeung
|
| 28 |
""", unsafe_allow_html=True)
|
| 29 |
|
| 30 |
+
#####################################################
|
| 31 |
+
##################### UI ############################
|
| 32 |
+
# Setting page title and header
|
| 33 |
+
st.set_page_config(page_title="KaggleX AI Course Coordinator", page_icon=":robot_face:")
|
| 34 |
+
st.markdown("<h1 style='text-align: center; color: navy;'>KaggleX AI Course Coordinator</h1>", unsafe_allow_html=True)
|
| 35 |
+
# st.markdown("<h4 style='text-align: center;'>A cutting-edge language model</h4>", unsafe_allow_html=True)
|
| 36 |
+
st.markdown("<p style='text-align: right'>By <a href='https://entzyeung.github.io/portfolio/index.html'>Lorentz Yeung</a></p>", unsafe_allow_html=True)
|
| 37 |
+
# st.session_state['API_Key']= st.text_input("First, to get it work, put your OpenAI API Key here please, the system will enter for you automatically.",type="password")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
#if 'API_Key' not in st.session_state:
|
| 41 |
# st.session_state['API_Key'] =''
|
| 42 |
#st.session_state['API_Key']= st.text_input("First, to get it work, put your OpenAI API Key here please, the system will enter for you automatically.",type="password")
|
|
|
|
|
|
|
| 43 |
# uploaded_file = st.sidebar.file_uploader("upload", type="csv")
|
| 44 |
|
| 45 |
persist_directory = "chroma/db"
|
|
|
|
| 66 |
st.session_state['history'] = []
|
| 67 |
|
| 68 |
if 'ai_history' not in st.session_state:
|
| 69 |
+
st.session_state['ai_history'] = ["Hi!"]
|
| 70 |
|
| 71 |
if 'user_history' not in st.session_state:
|
| 72 |
+
st.session_state['user_history'] = ["Hi, I would like to know more about the courses in KaggleX!"]
|
| 73 |
|
| 74 |
#container for the chat history
|
| 75 |
response_container = st.container()
|
|
|
|
| 79 |
with container:
|
| 80 |
with st.form(key='my_form', clear_on_submit=True):
|
| 81 |
|
| 82 |
+
user_input = st.text_input("Your question:", placeholder="Learn more about the courses in KaggleX:", key='input')
|
| 83 |
submit_button = st.form_submit_button(label='Ask')
|
| 84 |
|
| 85 |
if submit_button and user_input:
|
|
|
|
| 92 |
if st.session_state['ai_history']:
|
| 93 |
with response_container:
|
| 94 |
for i in range(len(st.session_state['ai_history'])):
|
| 95 |
+
message(st.session_state["user_history"][i], is_user=True, key=str(i) + '_user', avatar_style="user")
|
| 96 |
+
message(st.session_state["ai_history"][i], key=str(i), avatar_style="KaggleX.jpg")
|
| 97 |
|