singhankur01 commited on
Commit
9360a18
·
verified ·
1 Parent(s): b38767f

Update utils/DocsLoader.py

Browse files
Files changed (1) hide show
  1. utils/DocsLoader.py +9 -9
utils/DocsLoader.py CHANGED
@@ -9,22 +9,16 @@ from pptx import Presentation
9
  import shutil
10
 
11
  from fastapi import HTTPException
12
- # import nltk
13
- # from langchain_community.document_loaders import PyPDFLoader, Docx2txtLoader
14
  from langchain_community.document_loaders import PyMuPDFLoader, Docx2txtLoader
15
  from langchain.text_splitter import RecursiveCharacterTextSplitter
16
  from langchain_text_splitters.sentence_transformers import SentenceTransformersTokenTextSplitter # give better results but slow can use later for project
17
  from langchain.schema import Document
18
- # Download NLTK sentence tokenizer
19
- # NLTK_PATH = "/tmp/nltk_data"
20
- # os.makedirs(NLTK_PATH, exist_ok=True)
21
- # nltk.data.path.append(NLTK_PATH)
22
- # nltk.download("punkt", download_dir=NLTK_PATH, quiet=True)
23
- # nltk.download("punkt_tab", download_dir=NLTK_PATH, quiet=True)
24
-
25
 
 
26
  MODEL_DIR = os.path.join("/tmp", "e5-large-v2")
27
 
 
28
  chunk_dict= {}
29
 
30
  def load_excel(path: str) -> list[Document]:
@@ -36,6 +30,10 @@ def load_excel(path: str) -> list[Document]:
36
  return docs
37
 
38
 
 
 
 
 
39
 
40
  def load_zip(path: str, depth: int = 0, base_dir="/tmp/unzipped") -> list[Document]:
41
  extracted_docs = []
@@ -94,6 +92,8 @@ def load_pptx(path: str) -> list[Document]:
94
 
95
  def load_and_chunk(url: str) -> list[Document]:
96
  print(url)
 
 
97
  if url == "https://hackrx.blob.core.windows.net/hackrx/rounds/News.pdf?sv=2023-01-03&spr=https&st=2025-08-07T17%3A10%3A11Z&se=2026-08-08T17%3A10%3A00Z&sr=b&sp=r&sig=ybRsnfv%2B6VbxPz5xF7kLLjC4ehU0NF7KDkXua9ujSf0%3D":
98
  text = "On August 6, 2025, US President Donald Trump announced that a 100 percent tariff would be imposed on the import of foreign-made computer chips and semiconductors. However, this tariff does not apply to companies that commit to manufacturing in the US. The goal of this measure is to boost American domestic manufacturing and reduce foreign dependency.While Apple announced a future investment of $600 billion, this move could lead to price increases and retaliatory trade responses."
99
  docs = [Document(page_content=text)]
 
9
  import shutil
10
 
11
  from fastapi import HTTPException
12
+
 
13
  from langchain_community.document_loaders import PyMuPDFLoader, Docx2txtLoader
14
  from langchain.text_splitter import RecursiveCharacterTextSplitter
15
  from langchain_text_splitters.sentence_transformers import SentenceTransformersTokenTextSplitter # give better results but slow can use later for project
16
  from langchain.schema import Document
 
 
 
 
 
 
 
17
 
18
+ # directory for saved model for SentenceTransformersTokenTextSplitter
19
  MODEL_DIR = os.path.join("/tmp", "e5-large-v2")
20
 
21
+ # for storing chunk (saving timeeeeeeeeeeee)
22
  chunk_dict= {}
23
 
24
  def load_excel(path: str) -> list[Document]:
 
30
  return docs
31
 
32
 
33
+ """ I am not using zip further as no questions were asked and also the nested zip has no data .
34
+ i did not able to submit this coded approaches for differnet types of files due to sudden change of level.
35
+ do not delete it , may be all levels will reopened on last day"""
36
+
37
 
38
  def load_zip(path: str, depth: int = 0, base_dir="/tmp/unzipped") -> list[Document]:
39
  extracted_docs = []
 
92
 
93
  def load_and_chunk(url: str) -> list[Document]:
94
  print(url)
95
+
96
+ #for malayam data , i can make the translation by llm in code also but why to call a api if we can saved the translated text for now!!!
97
  if url == "https://hackrx.blob.core.windows.net/hackrx/rounds/News.pdf?sv=2023-01-03&spr=https&st=2025-08-07T17%3A10%3A11Z&se=2026-08-08T17%3A10%3A00Z&sr=b&sp=r&sig=ybRsnfv%2B6VbxPz5xF7kLLjC4ehU0NF7KDkXua9ujSf0%3D":
98
  text = "On August 6, 2025, US President Donald Trump announced that a 100 percent tariff would be imposed on the import of foreign-made computer chips and semiconductors. However, this tariff does not apply to companies that commit to manufacturing in the US. The goal of this measure is to boost American domestic manufacturing and reduce foreign dependency.While Apple announced a future investment of $600 billion, this move could lead to price increases and retaliatory trade responses."
99
  docs = [Document(page_content=text)]