NLPGenius commited on
Commit
62c9793
·
verified ·
1 Parent(s): ad58597

Update flask_app.py

Browse files
Files changed (1) hide show
  1. flask_app.py +15 -20
flask_app.py CHANGED
@@ -55,32 +55,19 @@ def create_faiss_index(docs):
55
  vector_store = FAISS.from_documents(texts, embedding_model)
56
  return vector_store
57
 
58
- # Function to extract files from .rar archive
59
- def extract_rar_files(rar_path, extract_to="extracted_files"):
60
- with rarfile.RarFile(rar_path) as rf:
61
- rf.extractall(extract_to)
62
- return extract_to
63
-
64
  # Function to fetch and process PDF files
65
- def fetch_and_process_pdfs(folder_path):
66
- pdf_files = [
67
- os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith(".pdf")
68
- ]
69
-
70
  all_documents = []
71
- for pdf_file in pdf_files:
72
  loader = PyPDFLoader(pdf_file)
73
  documents = loader.load()
74
  all_documents.extend(documents)
75
  return all_documents
76
 
77
- # Function to create RAG pipeline
78
- def create_rag_pipeline(rar_path):
79
- # Extract .rar file
80
- extracted_folder = extract_rar_files(rar_path)
81
-
82
  # Fetch and process PDF files
83
- documents = fetch_and_process_pdfs(extracted_folder)
84
 
85
  # Create vector store
86
  vector_store = create_faiss_index(documents)
@@ -88,9 +75,17 @@ def create_rag_pipeline(rar_path):
88
 
89
  return retriever
90
 
 
 
 
 
 
 
 
 
91
  # Usage example
92
- rar_path = "Rules folder.rar"
93
- retriever = create_rag_pipeline(rar_path)
94
 
95
 
96
 
 
55
  vector_store = FAISS.from_documents(texts, embedding_model)
56
  return vector_store
57
 
 
 
 
 
 
 
58
  # Function to fetch and process PDF files
59
+ def fetch_and_process_pdfs(pdf_paths):
 
 
 
 
60
  all_documents = []
61
+ for pdf_file in pdf_paths:
62
  loader = PyPDFLoader(pdf_file)
63
  documents = loader.load()
64
  all_documents.extend(documents)
65
  return all_documents
66
 
67
+ # Function to create RAG pipeline with provided PDF paths
68
+ def create_rag_pipeline(pdf_paths):
 
 
 
69
  # Fetch and process PDF files
70
+ documents = fetch_and_process_pdfs(pdf_paths)
71
 
72
  # Create vector store
73
  vector_store = create_faiss_index(documents)
 
75
 
76
  return retriever
77
 
78
+ # Specify the PDF paths
79
+ pdfs_paths = [
80
+ "Esta_Code_2024_.pdf",
81
+ "KP_Policy_Agriculture1.pdf",
82
+ "THE_KHYBER_PAKHTUNKHWA_SALES_TAX_ON_SERVICES_ACT_2022.pdf",
83
+ "The-Khyber-Pakhtunkhwa-Police-Amendment-Act-2024.pdf"
84
+ ]
85
+
86
  # Usage example
87
+ retriever = create_rag_pipeline(pdfs_paths)
88
+
89
 
90
 
91