Abc123Harsh commited on
Commit
8d41fde
·
verified ·
1 Parent(s): 1fe6e66

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -65
app.py DELETED
@@ -1,65 +0,0 @@
1
-
2
- pip install -r requirements.txt -q
3
- import box
4
- import yaml
5
- from langchain.vectorstores import FAISS
6
- from langchain.text_splitter import RecursiveCharacterTextSplitter
7
- from langchain.document_loaders import PyPDFLoader, DirectoryLoader
8
- from langchain.embeddings import HuggingFaceEmbeddings
9
-
10
-
11
- # Import config vars
12
- with open('config.yml', 'r', encoding='utf8') as ymlfile:
13
- cfg = box.Box(yaml.safe_load(ymlfile))
14
-
15
-
16
- # def run_ingest():
17
- loader = DirectoryLoader(cfg.DATA_PATH,
18
- glob='*.pdf',
19
- loader_cls=PyPDFLoader)
20
-
21
- documents = loader.load()
22
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=cfg.CHUNK_SIZE,
23
- chunk_overlap=cfg.CHUNK_OVERLAP)
24
- texts = text_splitter.split_documents(documents)
25
-
26
- embeddings = HuggingFaceEmbeddings(model_name=cfg.EMBEDDINGS,
27
- model_kwargs={'device': 'cpu'})
28
-
29
- vectorstore = FAISS.from_documents(texts, embeddings)
30
- vectorstore.save_local(cfg.DB_FAISS_PATH)
31
-
32
- # if __name__ == "__main__":
33
- # run_ingest()
34
-
35
- import timeit
36
- import argparse
37
- from llm.wrapper import setup_qa_chain
38
- from llm.wrapper import query_embeddings
39
-
40
-
41
- if __name__ == "__main__":
42
- parser = argparse.ArgumentParser()
43
- parser.add_argument('input',
44
- type=str,
45
- default='What is the invoice number value?',
46
- help='Enter the query to pass into the LLM')
47
- parser.add_argument('--semantic_search',
48
- type=bool,
49
- default=False,
50
- help='Enter True if you want to run semantic search, else False')
51
- args = parser.parse_args()
52
-
53
- start = timeit.default_timer()
54
- if args.semantic_search:
55
- semantic_search = query_embeddings(args.input)
56
- print(f'Semantic search: {semantic_search}')
57
- print('='*50)
58
- else:
59
- qa_chain = setup_qa_chain()
60
- response = qa_chain({'query': args.input})
61
- print(f'\nAnswer: {response["result"]}')
62
- print('=' * 50)
63
- end = timeit.default_timer()
64
-
65
- # print(f"Time to retrieve answer: {end - start}")