farhananis005 commited on
Commit
3b90d90
1 Parent(s): 4daf8f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -10,7 +10,7 @@ def save_docs(docs):
10
  import shutil
11
  import os
12
 
13
- output_dir="/content/docs/"
14
 
15
  if os.path.exists(output_dir):
16
  shutil.rmtree(output_dir)
@@ -35,19 +35,19 @@ def process_docs():
35
  from langchain.embeddings.openai import OpenAIEmbeddings
36
  from langchain.text_splitter import RecursiveCharacterTextSplitter
37
 
38
- loader1 = DirectoryLoader('/content/docs/', glob="./*.pdf", loader_cls=PyPDFLoader)
39
  document1 = loader1.load()
40
 
41
- loader2 = DirectoryLoader('/content/docs/', glob="./*.txt", loader_cls=TextLoader)
42
  document2 = loader2.load()
43
 
44
- loader3 = DirectoryLoader('/content/docs/', glob="./*.docx", loader_cls=Docx2txtLoader)
45
  document3 = loader3.load()
46
 
47
- loader4 = DirectoryLoader('/content/docs/', glob="./*.csv", loader_cls=CSVLoader)
48
  document4 = loader4.load()
49
 
50
- loader5 = DirectoryLoader('/content/docs/', glob="./*.xlsx", loader_cls=UnstructuredExcelLoader)
51
  document5 = loader5.load()
52
 
53
  document1.extend(document2)
@@ -65,7 +65,7 @@ def process_docs():
65
  embeddings = OpenAIEmbeddings()
66
 
67
  docs_db = FAISS.from_documents(docs, embeddings)
68
- docs_db.save_local("/content/docs_db/")
69
 
70
  return "Successful!"
71
 
@@ -113,7 +113,7 @@ def search_docs(prompt, question, state):
113
  state = state or []
114
 
115
  embeddings = OpenAIEmbeddings()
116
- docs_db = FAISS.load_local("/content/docs_db/", embeddings)
117
  docs = docs_db.similarity_search(question)
118
 
119
  prompt += "\n\n"
 
10
  import shutil
11
  import os
12
 
13
+ output_dir="/home/user/app/docs/"
14
 
15
  if os.path.exists(output_dir):
16
  shutil.rmtree(output_dir)
 
35
  from langchain.embeddings.openai import OpenAIEmbeddings
36
  from langchain.text_splitter import RecursiveCharacterTextSplitter
37
 
38
+ loader1 = DirectoryLoader('/home/user/app/docs/', glob="./*.pdf", loader_cls=PyPDFLoader)
39
  document1 = loader1.load()
40
 
41
+ loader2 = DirectoryLoader('/home/user/app/docs/', glob="./*.txt", loader_cls=TextLoader)
42
  document2 = loader2.load()
43
 
44
+ loader3 = DirectoryLoader('/home/user/app/docs/', glob="./*.docx", loader_cls=Docx2txtLoader)
45
  document3 = loader3.load()
46
 
47
+ loader4 = DirectoryLoader('/home/user/app/docs/', glob="./*.csv", loader_cls=CSVLoader)
48
  document4 = loader4.load()
49
 
50
+ loader5 = DirectoryLoader('/home/user/app/docs/', glob="./*.xlsx", loader_cls=UnstructuredExcelLoader)
51
  document5 = loader5.load()
52
 
53
  document1.extend(document2)
 
65
  embeddings = OpenAIEmbeddings()
66
 
67
  docs_db = FAISS.from_documents(docs, embeddings)
68
+ docs_db.save_local("/home/user/app/docs_db/")
69
 
70
  return "Successful!"
71
 
 
113
  state = state or []
114
 
115
  embeddings = OpenAIEmbeddings()
116
+ docs_db = FAISS.load_local("/home/user/app/docs_db/", embeddings)
117
  docs = docs_db.similarity_search(question)
118
 
119
  prompt += "\n\n"