Update app.py
Browse files
app.py
CHANGED
|
@@ -16,35 +16,42 @@ from utills import load_txt_documents, split_docs, load_uploaded_documents, retr
|
|
| 16 |
from langchain.text_splitter import TokenTextSplitter, RecursiveCharacterTextSplitter
|
| 17 |
from langchain_community.document_loaders.directory import DirectoryLoader
|
| 18 |
|
| 19 |
-
|
| 20 |
-
st.set_page_config(page_title="Conversational RAG Chatbot", page_icon=":robot:")
|
| 21 |
-
st.title("Conversational RAG Chatbot")
|
| 22 |
-
|
| 23 |
-
if "documents" not in st.session_state:
|
| 24 |
-
st.session_state.documents = []
|
| 25 |
-
|
| 26 |
-
if "conversation_chain" not in st.session_state:
|
| 27 |
-
st.session_state.conversation_chain = None
|
| 28 |
-
|
| 29 |
-
data_path = "data"
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
|
| 46 |
docs = split_docs(documents, 350, 40)
|
| 47 |
vectorstore = get_vectorstore(docs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
if "conversation_chain" not in st.session_state:
|
| 49 |
st.session_state.conversation_chain = create_conversational_rag_chain(vectorstore)
|
| 50 |
|
|
|
|
| 16 |
from langchain.text_splitter import TokenTextSplitter, RecursiveCharacterTextSplitter
|
| 17 |
from langchain_community.document_loaders.directory import DirectoryLoader
|
| 18 |
|
| 19 |
+
data_path = "data"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
+
documents = []
|
| 24 |
|
| 25 |
+
for filename in os.listdir(data_path):
|
| 26 |
|
| 27 |
+
if filename.endswith('.txt'):
|
| 28 |
|
| 29 |
+
file_path = os.path.join(data_path, filename)
|
| 30 |
|
| 31 |
+
documents = TextLoader(file_path).load()
|
| 32 |
|
| 33 |
+
documents.extend(documents)
|
| 34 |
|
| 35 |
|
| 36 |
docs = split_docs(documents, 350, 40)
|
| 37 |
vectorstore = get_vectorstore(docs)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main(vectorstore):
|
| 45 |
+
st.set_page_config(page_title="Conversational RAG Chatbot", page_icon=":robot:")
|
| 46 |
+
st.title("Conversational RAG Chatbot")
|
| 47 |
+
|
| 48 |
+
if "documents" not in st.session_state:
|
| 49 |
+
st.session_state.documents = []
|
| 50 |
+
|
| 51 |
+
if "conversation_chain" not in st.session_state:
|
| 52 |
+
st.session_state.conversation_chain = None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
if "conversation_chain" not in st.session_state:
|
| 56 |
st.session_state.conversation_chain = create_conversational_rag_chain(vectorstore)
|
| 57 |
|