nikhmr1235 commited on
Commit
78d7b7f
·
verified ·
1 Parent(s): d64bbb5

additional print statements

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -34,14 +34,21 @@ class PDFChatbot:
34
  return
35
 
36
  self.state = SessionState()
37
- doc = fitz.open(pdf_file.name)
38
- text = ""
39
- for page in doc:
40
- text += page.get_text()
 
 
41
  doc.close()
 
 
 
42
 
 
43
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
44
  docs = text_splitter.create_documents([text])
 
45
 
46
  embeddings = GoogleGenerativeAIEmbeddings(model=EMBEDDING_MODEL)
47
  self.state.db = Chroma.from_documents(
@@ -55,9 +62,12 @@ class PDFChatbot:
55
  shutil.rmtree(self.state.vector_store_path)
56
  print(f"An error occurred: {str(e)}")
57
 
 
 
 
58
  def chat_with_pdf(self, message, history):
59
  print("Chat interface called. Checking if database is ready...")
60
- if not self.state.is_db_ready():
61
  print("Database is not ready.")
62
  yield "Error: Database not ready."
63
  return
@@ -85,12 +95,11 @@ class PDFChatbot:
85
  | StrOutputParser()
86
  )
87
 
88
- response = rag_chain.invoke(message)
 
 
89
  yield response
90
 
91
- def is_db_ready(self):
92
- return self.state.db is not None
93
-
94
  class SessionState:
95
  def __init__(self):
96
  self.session_id = str(uuid.uuid4())
 
34
  return
35
 
36
  self.state = SessionState()
37
+ print("Opening PDF file...")
38
+ try:
39
+ doc = fitz.open(pdf_file.name)
40
+ text = ""
41
+ for page in doc:
42
+ text += page.get_text()
43
  doc.close()
44
+ except Exception as e:
45
+ print(f"Error processing PDF document: {str(e)}")
46
+ return
47
 
48
+ print("PDF file opened successfully. Splitting text into chunks...")
49
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
50
  docs = text_splitter.create_documents([text])
51
+ print("Text split into chunks successfully.")
52
 
53
  embeddings = GoogleGenerativeAIEmbeddings(model=EMBEDDING_MODEL)
54
  self.state.db = Chroma.from_documents(
 
62
  shutil.rmtree(self.state.vector_store_path)
63
  print(f"An error occurred: {str(e)}")
64
 
65
+ def is_db_ready(self):
66
+ return self.state.db is not None
67
+
68
  def chat_with_pdf(self, message, history):
69
  print("Chat interface called. Checking if database is ready...")
70
+ if not self.is_db_ready():
71
  print("Database is not ready.")
72
  yield "Error: Database not ready."
73
  return
 
95
  | StrOutputParser()
96
  )
97
 
98
+ response = rag_chain.invoke(
99
+ message
100
+ )
101
  yield response
102
 
 
 
 
103
  class SessionState:
104
  def __init__(self):
105
  self.session_id = str(uuid.uuid4())