farhananis005 commited on
Commit
88faaa1
1 Parent(s): 655eb44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -10,10 +10,10 @@ def save_docs(docs):
10
  import shutil
11
  import os
12
 
13
- destination_dir = "/kaggle/working/docs/"
14
  os.makedirs(destination_dir, exist_ok=True)
15
 
16
- output_dir="/kaggle/working/docs/"
17
 
18
  for doc in docs:
19
  shutil.copy(doc.name, output_dir)
@@ -30,13 +30,13 @@ def process_docs():
30
  from langchain.embeddings.openai import OpenAIEmbeddings
31
  from langchain.text_splitter import RecursiveCharacterTextSplitter
32
 
33
- loader1 = DirectoryLoader('/kaggle/working/docs/', glob="./*.pdf", loader_cls=PyPDFLoader)
34
  document1 = loader1.load()
35
 
36
- loader2 = DirectoryLoader('/kaggle/working/docs/', glob="./*.txt", loader_cls=TextLoader)
37
  document2 = loader2.load()
38
 
39
- loader3 = DirectoryLoader('/kaggle/working/docs/', glob="./*.docx", loader_cls=Docx2txtLoader)
40
  document3 = loader3.load()
41
 
42
  document1.extend(document2)
@@ -52,7 +52,7 @@ def process_docs():
52
  embeddings = OpenAIEmbeddings()
53
 
54
  docs_db = FAISS.from_documents(docs, embeddings)
55
- docs_db.save_local("/kaggle/working/docs_db/")
56
 
57
  return "File(s) processed successfully!"
58
 
@@ -82,7 +82,7 @@ def search_docs(question):
82
  from langchain.chat_models import ChatOpenAI
83
 
84
  embeddings = OpenAIEmbeddings()
85
- docs_db = FAISS.load_local("/kaggle/working/docs_db/", embeddings)
86
  docs = docs_db.similarity_search(question)
87
 
88
  llm = ChatOpenAI(model_name='gpt-3.5-turbo')
@@ -98,8 +98,8 @@ def delete_docs():
98
 
99
  import shutil
100
 
101
- path1 = "/kaggle/working/docs/"
102
- path2 = "/kaggle/working/docs_db/"
103
 
104
  try:
105
  shutil.rmtree(path1)
 
10
  import shutil
11
  import os
12
 
13
+ destination_dir = "/home/user/app/docs/"
14
  os.makedirs(destination_dir, exist_ok=True)
15
 
16
+ output_dir="/home/user/app/docs/"
17
 
18
  for doc in docs:
19
  shutil.copy(doc.name, output_dir)
 
30
  from langchain.embeddings.openai import OpenAIEmbeddings
31
  from langchain.text_splitter import RecursiveCharacterTextSplitter
32
 
33
+ loader1 = DirectoryLoader('/home/user/app/docs/', glob="./*.pdf", loader_cls=PyPDFLoader)
34
  document1 = loader1.load()
35
 
36
+ loader2 = DirectoryLoader('/home/user/app/docs/', glob="./*.txt", loader_cls=TextLoader)
37
  document2 = loader2.load()
38
 
39
+ loader3 = DirectoryLoader('/home/user/app/docs/', glob="./*.docx", loader_cls=Docx2txtLoader)
40
  document3 = loader3.load()
41
 
42
  document1.extend(document2)
 
52
  embeddings = OpenAIEmbeddings()
53
 
54
  docs_db = FAISS.from_documents(docs, embeddings)
55
+ docs_db.save_local("/home/user/app/docs_db/")
56
 
57
  return "File(s) processed successfully!"
58
 
 
82
  from langchain.chat_models import ChatOpenAI
83
 
84
  embeddings = OpenAIEmbeddings()
85
+ docs_db = FAISS.load_local("/home/user/app/docs_db/", embeddings)
86
  docs = docs_db.similarity_search(question)
87
 
88
  llm = ChatOpenAI(model_name='gpt-3.5-turbo')
 
98
 
99
  import shutil
100
 
101
+ path1 = "/home/user/app/docs/"
102
+ path2 = "/home/user/app/docs_db/"
103
 
104
  try:
105
  shutil.rmtree(path1)