m96tkmok commited on
Commit
25481ca
·
verified ·
1 Parent(s): b6a5096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -70,7 +70,20 @@ def generate_response(rag_chain, input_text):
70
 
71
  return response
72
 
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
  def main() -> None:
@@ -86,13 +99,9 @@ def main() -> None:
86
 
87
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
88
 
89
- ### Ken 12/11/2024 START
90
-
91
- loader = PyPDFLoader(docs)
92
- ldocs = loader.load()
93
-
94
- raw_text = get_pdf(ldocs)
95
- ### Ken 12/11/2024 END
96
 
97
  #chunks = text_splitter.split_documents(docs)
98
  chunks = text_splitter.split_documents(raw_text)
 
70
 
71
  return response
72
 
73
+ ### Ken 12/11/2024 ADD START
74
+ def get_pdf(uploaded_file):
75
+ if uploaded_file :
76
+ temp_file = "./temp.pdf"
77
+ # Delete the existing temp.pdf file if it exists
78
+ if os.path.exists(temp_file):
79
+ os.remove(temp_file)
80
+ with open(temp_file, "wb") as file:
81
+ file.write(uploaded_file.getvalue())
82
+ file_name = uploaded_file.name
83
+ loader = PyPDFLoader(temp_file)
84
+ docs = loader.load()
85
+ return docs
86
+ ### Ken 12/11/2024 ADD END
87
 
88
 
89
  def main() -> None:
 
99
 
100
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
101
 
102
+ ### Ken 12/11/2024 ADD START
103
+ raw_text = get_pdf(docs)
104
+ ### Ken 12/11/2024 ADD END
 
 
 
 
105
 
106
  #chunks = text_splitter.split_documents(docs)
107
  chunks = text_splitter.split_documents(raw_text)