Spaces:
Runtime error
Runtime error
Update flask_app.py
Browse files- flask_app.py +14 -7
flask_app.py
CHANGED
|
@@ -50,10 +50,16 @@ from langchain_core.output_parsers import StrOutputParser
|
|
| 50 |
|
| 51 |
# Function to create FAISS index
|
| 52 |
def create_faiss_index(docs):
|
| 53 |
-
texts = text_splitter.split_documents(docs)
|
| 54 |
vector_store = FAISS.from_documents(texts, embedding_model)
|
| 55 |
return vector_store
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Function to fetch and process PDF files
|
| 58 |
def fetch_and_process_pdfs(folder_path):
|
| 59 |
pdf_files = [
|
|
@@ -65,14 +71,15 @@ def fetch_and_process_pdfs(folder_path):
|
|
| 65 |
loader = PyPDFLoader(pdf_file)
|
| 66 |
documents = loader.load()
|
| 67 |
all_documents.extend(documents)
|
| 68 |
-
#print(all_documents)
|
| 69 |
return all_documents
|
| 70 |
|
| 71 |
-
|
| 72 |
# Function to create RAG pipeline
|
| 73 |
-
def create_rag_pipeline(
|
|
|
|
|
|
|
|
|
|
| 74 |
# Fetch and process PDF files
|
| 75 |
-
documents = fetch_and_process_pdfs(
|
| 76 |
|
| 77 |
# Create vector store
|
| 78 |
vector_store = create_faiss_index(documents)
|
|
@@ -81,8 +88,8 @@ def create_rag_pipeline(folder_path):
|
|
| 81 |
return retriever
|
| 82 |
|
| 83 |
# Usage example
|
| 84 |
-
|
| 85 |
-
retriever = create_rag_pipeline(
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
| 50 |
|
| 51 |
# Function to create FAISS index
|
| 52 |
def create_faiss_index(docs):
|
| 53 |
+
texts = text_splitter.split_documents(docs) # Ensure `text_splitter` is defined in your script
|
| 54 |
vector_store = FAISS.from_documents(texts, embedding_model)
|
| 55 |
return vector_store
|
| 56 |
|
| 57 |
+
# Function to extract files from .rar archive
|
| 58 |
+
def extract_rar_files(rar_path, extract_to="extracted_files"):
|
| 59 |
+
with rarfile.RarFile(rar_path) as rf:
|
| 60 |
+
rf.extractall(extract_to)
|
| 61 |
+
return extract_to
|
| 62 |
+
|
| 63 |
# Function to fetch and process PDF files
|
| 64 |
def fetch_and_process_pdfs(folder_path):
|
| 65 |
pdf_files = [
|
|
|
|
| 71 |
loader = PyPDFLoader(pdf_file)
|
| 72 |
documents = loader.load()
|
| 73 |
all_documents.extend(documents)
|
|
|
|
| 74 |
return all_documents
|
| 75 |
|
|
|
|
| 76 |
# Function to create RAG pipeline
|
| 77 |
+
def create_rag_pipeline(rar_path):
|
| 78 |
+
# Extract .rar file
|
| 79 |
+
extracted_folder = extract_rar_files(rar_path)
|
| 80 |
+
|
| 81 |
# Fetch and process PDF files
|
| 82 |
+
documents = fetch_and_process_pdfs(extracted_folder)
|
| 83 |
|
| 84 |
# Create vector store
|
| 85 |
vector_store = create_faiss_index(documents)
|
|
|
|
| 88 |
return retriever
|
| 89 |
|
| 90 |
# Usage example
|
| 91 |
+
rar_path = "Rules folder.rar"
|
| 92 |
+
retriever = create_rag_pipeline(rar_path)
|
| 93 |
|
| 94 |
|
| 95 |
|