-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (35 loc) · 1.49 KB
/
main.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
import streamlit as st
from graph import stream_graph_updates
import uuid
from document_handler import parse_document, vectorize_document
if "client_id" not in st.session_state:
st.session_state.client_id = uuid.uuid4().hex
st.title("🤖 Agentic RAG Chatbot 💬")
uploaded_file = st.file_uploader("Upload your files", type=("txt","pdf"))
if uploaded_file is not None:
docs = parse_document(uploaded_file,st.session_state.client_id)
vectorize_document(docs)
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "assistant", "content":
"How can I assist you today?"
}
]
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input
if prompt := st.chat_input("Say something..."):
# Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Display assistant response in chat message container
with st.chat_message("assistant"):
stream = stream_graph_updates(prompt,thread_id=st.session_state.client_id)
response = st.write_stream(stream)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})