ArturG9 commited on
Commit
c4b7f37
1 Parent(s): 13a431e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -28,22 +28,23 @@ def main():
28
 
29
  data_path = "data"
30
 
31
- if not os.path.exists(data_path):
32
- st.error(f"Data path does not exist: {data_path}")
33
- return
34
-
35
- try:
36
- documents = load_txt_documents(data_path)
37
- if not documents:
38
- st.warning("No documents found in the data path.")
39
- else:
40
- st.session_state.documents = documents
41
- docs = split_docs(documents, 350, 40)
42
- vectorstore = retriever_from_chroma(docs, HuggingFaceEmbeddings(), "mmr", 7)
43
- st.session_state.conversation_chain = create_conversational_rag_chain(vectorstore)
44
- st.success("Documents loaded and processed successfully.")
45
- except Exception as e:
46
- st.error(f"An error occurred while loading documents: {e}")
 
47
 
48
  if prompt := st.text_input("Enter your question:"):
49
  msgs = st.session_state.get("chat_history", StreamlitChatMessageHistory(key="special_app_key"))
 
28
 
29
  data_path = "data"
30
 
31
+
32
+
33
+ documents = []
34
+
35
+ for filename in os.listdir(data_path):
36
+
37
+ if filename.endswith('.txt'):
38
+
39
+ file_path = os.path.join(data_path, filename)
40
+
41
+ documents = TextLoader(file_path).load()
42
+
43
+ documents.extend(documents)
44
+
45
+
46
+ docs = split_docs(documents, 350, 40)
47
+
48
 
49
  if prompt := st.text_input("Enter your question:"):
50
  msgs = st.session_state.get("chat_history", StreamlitChatMessageHistory(key="special_app_key"))