testcolab2 commited on
Commit
39f86fb
·
verified ·
1 Parent(s): bdc0c5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -21
app.py CHANGED
@@ -115,57 +115,105 @@ def handle_userinput(user_question):
115
  "{{MSG}}", message.content), unsafe_allow_html=True)
116
 
117
 
 
 
 
118
 
119
  def main():
120
-
121
- st.set_page_config(page_title="Chat with multiple PDFs",
122
- page_icon="logo1.png" )
123
  st.write(css, unsafe_allow_html=True)
124
 
125
- if "conversation" not in st.session_state:
126
  st.session_state.conversation = None
 
127
  if "chat_history" not in st.session_state:
128
  st.session_state.chat_history = None
129
 
130
  st.header("Chat with multiple PDFs :books:")
131
  user_question = st.text_input("Ask a question about your documents:")
 
132
  if user_question:
133
  handle_userinput(user_question)
134
 
135
  with st.sidebar:
136
  st.subheader("Your documents")
137
- pdf_docs = st.file_uploader(
138
- "Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
139
-
140
 
141
  if st.button("Process"):
142
  with st.spinner("Processing"):
143
- # get pdf text
144
  raw_text = get_pdf_text(pdf_docs)
145
 
146
- # get the text chunks
147
  text_chunks = get_text_chunks(raw_text)
148
 
149
- # create vector store
150
- vectorstore = get_vectorstore(text_chunks)
151
-
152
- # create conversation chain
153
- st.session_state.conversation = get_conversation_chain(
154
- vectorstore)
155
-
156
-
157
-
158
  # Clear chat history
159
  st.session_state.chat_history = None
160
-
 
 
 
161
  if st.session_state.conversation is not None:
162
  if st.session_state.chat_history is None:
163
  # Greet the user
164
  greeting = "Hello! How can I assist you with your documents?"
165
  st.write(bot_template.replace("{{MSG}}", greeting), unsafe_allow_html=True)
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
 
169
 
170
- if __name__ == '__main__':
171
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  "{{MSG}}", message.content), unsafe_allow_html=True)
116
 
117
 
118
+ def initialize_conversation_chain(text_chunks):
119
+ vectorstore = get_vectorstore(text_chunks)
120
+ return get_conversation_chain(vectorstore)
121
 
122
  def main():
123
+ st.set_page_config(page_title="Chat with multiple PDFs", page_icon="logo1.png")
 
 
124
  st.write(css, unsafe_allow_html=True)
125
 
126
+ if "conversation" not in st.session_state or st.session_state.conversation is None:
127
  st.session_state.conversation = None
128
+
129
  if "chat_history" not in st.session_state:
130
  st.session_state.chat_history = None
131
 
132
  st.header("Chat with multiple PDFs :books:")
133
  user_question = st.text_input("Ask a question about your documents:")
134
+
135
  if user_question:
136
  handle_userinput(user_question)
137
 
138
  with st.sidebar:
139
  st.subheader("Your documents")
140
+ pdf_docs = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
 
 
141
 
142
  if st.button("Process"):
143
  with st.spinner("Processing"):
144
+ # Get PDF text
145
  raw_text = get_pdf_text(pdf_docs)
146
 
147
+ # Get the text chunks
148
  text_chunks = get_text_chunks(raw_text)
149
 
 
 
 
 
 
 
 
 
 
150
  # Clear chat history
151
  st.session_state.chat_history = None
152
+
153
+ # Initialize conversation chain
154
+ st.session_state.conversation = initialize_conversation_chain(text_chunks)
155
+
156
  if st.session_state.conversation is not None:
157
  if st.session_state.chat_history is None:
158
  # Greet the user
159
  greeting = "Hello! How can I assist you with your documents?"
160
  st.write(bot_template.replace("{{MSG}}", greeting), unsafe_allow_html=True)
161
 
162
+ if __name__ == '__main__':
163
+ main()
164
+
165
+
166
+
167
+ # def main():
168
+
169
+ # st.set_page_config(page_title="Chat with multiple PDFs",
170
+ # page_icon="logo1.png" )
171
+ # st.write(css, unsafe_allow_html=True)
172
+
173
+ # if "conversation" not in st.session_state:
174
+ # st.session_state.conversation = None
175
+ # if "chat_history" not in st.session_state:
176
+ # st.session_state.chat_history = None
177
+
178
+ # st.header("Chat with multiple PDFs :books:")
179
+ # user_question = st.text_input("Ask a question about your documents:")
180
+ # if user_question:
181
+ # handle_userinput(user_question)
182
+
183
+ # with st.sidebar:
184
+ # st.subheader("Your documents")
185
+ # pdf_docs = st.file_uploader(
186
+ # "Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
187
+
188
+
189
+ # if st.button("Process"):
190
+ # with st.spinner("Processing"):
191
+ # # get pdf text
192
+ # raw_text = get_pdf_text(pdf_docs)
193
+
194
+ # # get the text chunks
195
+ # text_chunks = get_text_chunks(raw_text)
196
+
197
+ # # create vector store
198
+ # vectorstore = get_vectorstore(text_chunks)
199
+
200
+ # # create conversation chain
201
+ # st.session_state.conversation = get_conversation_chain(
202
+ # vectorstore)
203
 
204
 
205
 
206
+ # # Clear chat history
207
+ # st.session_state.chat_history = None
208
+
209
+ # if st.session_state.conversation is not None:
210
+ # if st.session_state.chat_history is None:
211
+ # # Greet the user
212
+ # greeting = "Hello! How can I assist you with your documents?"
213
+ # st.write(bot_template.replace("{{MSG}}", greeting), unsafe_allow_html=True)
214
+
215
+
216
+
217
+
218
+ # if __name__ == '__main__':
219
+ # main()