QuantAdminUser commited on
Commit
981946b
·
verified ·
1 Parent(s): 9977c3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -5,7 +5,7 @@ from langchain_openai import ChatOpenAI
5
  from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, AIMessagePromptTemplate
6
  from langchain_core.output_parsers import StrOutputParser
7
  from langchain_core.runnables import RunnablePassthrough
8
- from langchain_community.document_loaders import TextLoader, UnstructuredWordDocumentLoader
9
 
10
  # Configuration
11
  SECRET_KEY = "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" # Replace with your actual API key
@@ -23,14 +23,28 @@ def load_runbooks():
23
  runbooks = {}
24
  for file in os.listdir(RUNBOOK_DIR):
25
  path = os.path.join(RUNBOOK_DIR, file)
26
- if file.endswith(".txt"):
27
- loader = TextLoader(path)
28
- elif file.endswith(".docx"):
29
- loader = UnstructuredWordDocumentLoader(path)
30
- else:
31
- continue
32
- docs = loader.load()
33
- runbooks[file] = "\n".join([doc.page_content for doc in docs])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  return runbooks
35
 
36
  RUNBOOKS = load_runbooks()
 
5
  from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, AIMessagePromptTemplate
6
  from langchain_core.output_parsers import StrOutputParser
7
  from langchain_core.runnables import RunnablePassthrough
8
+ from langchain_community.document_loaders import TextLoader
9
 
10
  # Configuration
11
  SECRET_KEY = "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" # Replace with your actual API key
 
23
  runbooks = {}
24
  for file in os.listdir(RUNBOOK_DIR):
25
  path = os.path.join(RUNBOOK_DIR, file)
26
+ try:
27
+ if file.endswith(".txt"):
28
+ # Load text files using TextLoader
29
+ loader = TextLoader(path)
30
+ docs = loader.load()
31
+ content = "\n".join([doc.page_content for doc in docs])
32
+
33
+ elif file.endswith(".docx"):
34
+ # Load .docx files using python-docx
35
+ doc = DocxDocument(path)
36
+ content = "\n".join([para.text for para in doc.paragraphs])
37
+
38
+ else:
39
+ # Skip unsupported file types
40
+ continue
41
+
42
+ # Add the file's content to the runbooks dictionary
43
+ runbooks[file] = content
44
+
45
+ except Exception as e:
46
+ print(f"Error loading file {file}: {e}")
47
+
48
  return runbooks
49
 
50
  RUNBOOKS = load_runbooks()