Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import os
|
2 |
-
import pickle
|
3 |
import streamlit as st
|
4 |
from langchain.chat_models import ChatOpenAI
|
5 |
from langchain.chains import ConversationalRetrievalChain
|
@@ -68,25 +67,60 @@ qa_chain = ConversationalRetrievalChain.from_llm(
|
|
68 |
)
|
69 |
|
70 |
# Streamlit app
|
|
|
71 |
st.title("AI Course Recommendation Chatbot")
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
if 'chat_history' not in st.session_state:
|
74 |
st.session_state.chat_history = []
|
75 |
|
|
|
76 |
user_query = st.text_input("What are you looking to learn?", "")
|
77 |
|
|
|
78 |
if st.button("Get Recommendation"):
|
79 |
if user_query:
|
80 |
response = qa_chain({"question": user_query})
|
81 |
recommendation = response["answer"]
|
82 |
|
83 |
-
# Update chat history
|
84 |
st.session_state.chat_history.append({"user": user_query, "bot": recommendation})
|
85 |
|
86 |
-
# Display chat history
|
87 |
-
|
88 |
-
st.
|
89 |
-
st.
|
|
|
|
|
|
|
90 |
|
91 |
# Optional: Add a button to clear the chat history
|
92 |
if st.button("Clear Chat History"):
|
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
3 |
from langchain.chat_models import ChatOpenAI
|
4 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
67 |
)
|
68 |
|
69 |
# Streamlit app
|
70 |
+
st.set_page_config(page_title="AI Course Recommendation Chatbot", page_icon=":book:")
|
71 |
st.title("AI Course Recommendation Chatbot")
|
72 |
|
73 |
+
# Custom CSS for styling
|
74 |
+
st.markdown("""
|
75 |
+
<style>
|
76 |
+
.chat-container {
|
77 |
+
max-width: 800px;
|
78 |
+
margin: auto;
|
79 |
+
padding: 20px;
|
80 |
+
border-radius: 10px;
|
81 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
82 |
+
background-color: #f9f9f9;
|
83 |
+
}
|
84 |
+
.user-message {
|
85 |
+
background-color: #d1e7dd;
|
86 |
+
border-radius: 10px;
|
87 |
+
padding: 10px;
|
88 |
+
margin: 5px 0;
|
89 |
+
text-align: left;
|
90 |
+
}
|
91 |
+
.bot-message {
|
92 |
+
background-color: #e2e3e5;
|
93 |
+
border-radius: 10px;
|
94 |
+
padding: 10px;
|
95 |
+
margin: 5px 0;
|
96 |
+
text-align: left;
|
97 |
+
}
|
98 |
+
</style>
|
99 |
+
""", unsafe_allow_html=True)
|
100 |
+
|
101 |
+
# Initialize chat history in session state
|
102 |
if 'chat_history' not in st.session_state:
|
103 |
st.session_state.chat_history = []
|
104 |
|
105 |
+
# User input for course interests
|
106 |
user_query = st.text_input("What are you looking to learn?", "")
|
107 |
|
108 |
+
# Button to get course recommendations
|
109 |
if st.button("Get Recommendation"):
|
110 |
if user_query:
|
111 |
response = qa_chain({"question": user_query})
|
112 |
recommendation = response["answer"]
|
113 |
|
114 |
+
# Update chat history with user's query and recommendation
|
115 |
st.session_state.chat_history.append({"user": user_query, "bot": recommendation})
|
116 |
|
117 |
+
# Display chat history in a styled format
|
118 |
+
with st.container():
|
119 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
120 |
+
for chat in st.session_state.chat_history:
|
121 |
+
st.markdown(f'<div class="user-message"><strong>You:</strong> {chat["user"]}</div>', unsafe_allow_html=True)
|
122 |
+
st.markdown(f'<div class="bot-message"><strong>AI Recommendation:</strong> {chat["bot"]}</div>', unsafe_allow_html=True)
|
123 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
124 |
|
125 |
# Optional: Add a button to clear the chat history
|
126 |
if st.button("Clear Chat History"):
|