Spaces:
No application file
No application file
Update user.py
Browse files
user.py
CHANGED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from utils.qa import chain
|
2 |
+
import streamlit as st
|
3 |
+
from langchain.memory import ConversationBufferWindowMemory
|
4 |
+
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
|
5 |
+
|
6 |
+
path = "mm_vdb2"
|
7 |
+
client = chromadb.PersistentClient(path=path)
|
8 |
+
image_collection = client.get_collection(name="image")
|
9 |
+
video_collection = client.get_collection(name='video_collection')
|
10 |
+
|
11 |
+
|
12 |
+
memory_storage = StreamlitChatMessageHistory(key="chat_messages")
|
13 |
+
memory = ConversationBufferWindowMemory(memory_key="chat_history", human_prefix="User", chat_memory=memory_storage, k=3)
|
14 |
+
|
15 |
+
def get_answer(query):
|
16 |
+
response = chain.invoke(query)
|
17 |
+
#return response["result"]
|
18 |
+
return response
|
19 |
+
|
20 |
+
def home():
|
21 |
+
st.header("Welcome")
|
22 |
+
#st.set_page_config(layout='wide', page_title="Virtual Tutor")
|
23 |
+
st.markdown("""
|
24 |
+
<svg width="600" height="100">
|
25 |
+
<text x="50%" y="50%" font-family="San serif" font-size="42px" fill="Black" text-anchor="middle" stroke="white"
|
26 |
+
stroke-width="0.3" stroke-linejoin="round">Virtual Tutor - CHAT
|
27 |
+
</text>
|
28 |
+
</svg>
|
29 |
+
""", unsafe_allow_html=True)
|
30 |
+
|
31 |
+
if "messages" not in st.session_state:
|
32 |
+
st.session_state.messages = [
|
33 |
+
{"role": "assistant", "content": "Hi! How may I assist you today?"}
|
34 |
+
]
|
35 |
+
|
36 |
+
st.markdown("""
|
37 |
+
<style>
|
38 |
+
.stChatInputContainer > div {
|
39 |
+
background-color: #000000;
|
40 |
+
}
|
41 |
+
</style>
|
42 |
+
""", unsafe_allow_html=True)
|
43 |
+
|
44 |
+
for message in st.session_state.messages: # Display the prior chat messages
|
45 |
+
with st.chat_message(message["role"]):
|
46 |
+
st.write(message["content"])
|
47 |
+
|
48 |
+
for i, msg in enumerate(memory_storage.messages):
|
49 |
+
name = "user" if i % 2 == 0 else "assistant"
|
50 |
+
st.chat_message(name).markdown(msg.content)
|
51 |
+
|
52 |
+
if user_input := st.chat_input("User Input"):
|
53 |
+
with st.chat_message("user"):
|
54 |
+
st.markdown(user_input)
|
55 |
+
|
56 |
+
with st.spinner("Generating Response..."):
|
57 |
+
with st.chat_message("assistant"):
|
58 |
+
response = get_answer(user_input)
|
59 |
+
answer = response['result']
|
60 |
+
st.markdown(answer)
|
61 |
+
message = {"role": "assistant", "content": answer}
|
62 |
+
message_u = {"role": "user", "content": user_input}
|
63 |
+
st.session_state.messages.append(message_u)
|
64 |
+
st.session_state.messages.append(message)
|
65 |
+
|