-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
59 lines (40 loc) · 1.96 KB
/
Main.py
File metadata and controls
59 lines (40 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
from OpsLib.core_operations import ProcBase
import os
import pickle
from pathlib import Path
procbase = ProcBase()
def main():
st.set_page_config(page_title = 'Chat with multiple documents', page_icon = ':books:')
st.header("Chat with your PDF :books: ")
pdf_docs = st.file_uploader("Upload your PDF ", type = 'pdf', accept_multiple_files = True)
if pdf_docs is not None:
raw_text = procbase.get_PDF_text(pdf_docs = pdf_docs)
chunks = procbase.create_text_chunks(raw_text, 800, 150)
filename = ''
if pdf_docs:
for uploaded_file in pdf_docs:
filename = uploaded_file.name
st.write("Filename: ", filename)
if os.path.exists(f'C:\\Users\\aariz\codes\\LLMS\PDF_Chatting\\Llama\\OpsLib\\Vector_db\\{filename}.pkl'):
with open(f'C:\\Users\\aariz\\codes\LLMS\\PDF_Chatting\\Llama\OpsLib\\Vector_db\\{filename}.pkl', 'rb') as db:
vector_db = pickle.load(db)
st.write(f"Embeddings loaded from the disk for the file : {filename}")
else:
st.write(f"Embedding started for the new file : {filename}")
vector_db = procbase.vectorStore(chunks, filename)
st.write(f"Embedding completed for the new file : {filename}")
print(f"Embedding completed for the new file : {filename}")
# TAKING USER INPUT
query = st.text_input("Ask a question about your PDF file : ")
response = ''
# SIMILAR SEARCH
if query:
similar_search = vector_db.similarity_search(query=query, k=1)
st.write(similar_search)
# print(similar_search)
response = procbase.generate_answer(similar_search, query)
# print("The response generated : " ,response)
st.write(response)
if __name__ == "__main__":
main()