testcolab2 commited on
Commit
4cfa3e0
·
verified ·
1 Parent(s): 8884a50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -4
app.py CHANGED
@@ -125,12 +125,52 @@ def handle_user_input(question):
125
  else:
126
  st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  def main():
129
  st.set_page_config(page_title='Chat with Your own PDFs', page_icon=':books:')
130
 
131
  st.write(css, unsafe_allow_html=True)
132
 
133
- if "conversation" not in st.session_state:
 
134
  st.session_state.conversation = None
135
 
136
  if "chat_history" not in st.session_state:
@@ -140,6 +180,9 @@ def main():
140
  question = st.text_input("Ask anything to your PDF: ")
141
 
142
  if question:
 
 
 
143
  handle_user_input(question)
144
 
145
  with st.sidebar:
@@ -148,7 +191,6 @@ def main():
148
 
149
  if st.button("OK"):
150
  with st.spinner("Processing your PDFs..."):
151
-
152
  # Get PDF Text
153
  raw_text = get_pdf_text(pdf_files)
154
 
@@ -156,12 +198,18 @@ def main():
156
  text_chunks = get_chunk_text(raw_text)
157
 
158
  # Create Vector Store
159
-
160
  vector_store = get_vector_store(text_chunks)
161
  st.write("DONE")
162
 
163
  # Create conversation chain
 
 
 
 
 
 
 
 
164
 
165
- st.session_state.conversation = get_conversation_chain(vector_store)
166
 
167
  main()
 
125
  else:
126
  st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
127
 
128
+ # def main():
129
+ # st.set_page_config(page_title='Chat with Your own PDFs', page_icon=':books:')
130
+
131
+ # st.write(css, unsafe_allow_html=True)
132
+
133
+ # if "conversation" not in st.session_state:
134
+ # st.session_state.conversation = None
135
+
136
+ # if "chat_history" not in st.session_state:
137
+ # st.session_state.chat_history = None
138
+
139
+ # st.header('Chat with Your own PDFs :books:')
140
+ # question = st.text_input("Ask anything to your PDF: ")
141
+
142
+ # if question:
143
+ # handle_user_input(question)
144
+
145
+ # with st.sidebar:
146
+ # st.subheader("Upload your Documents Here: ")
147
+ # pdf_files = st.file_uploader("Choose your PDF Files and Press OK", type=['pdf'], accept_multiple_files=True)
148
+
149
+ # if st.button("OK"):
150
+ # with st.spinner("Processing your PDFs..."):
151
+
152
+ # # Get PDF Text
153
+ # raw_text = get_pdf_text(pdf_files)
154
+
155
+ # # Get Text Chunks
156
+ # text_chunks = get_chunk_text(raw_text)
157
+
158
+ # # Create Vector Store
159
+
160
+ # vector_store = get_vector_store(text_chunks)
161
+ # st.write("DONE")
162
+
163
+ # # Create conversation chain
164
+
165
+ # st.session_state.conversation = get_conversation_chain(vector_store)
166
+
167
  def main():
168
  st.set_page_config(page_title='Chat with Your own PDFs', page_icon=':books:')
169
 
170
  st.write(css, unsafe_allow_html=True)
171
 
172
+ if "conversation" not in st.session_state or st.session_state.conversation is None:
173
+ # Initialize conversation only if it's not already present in session state
174
  st.session_state.conversation = None
175
 
176
  if "chat_history" not in st.session_state:
 
180
  question = st.text_input("Ask anything to your PDF: ")
181
 
182
  if question:
183
+ # Check if conversation is still None (not properly initialized)
184
+ if st.session_state.conversation is None:
185
+ st.session_state.conversation = initialize_conversation_chain()
186
  handle_user_input(question)
187
 
188
  with st.sidebar:
 
191
 
192
  if st.button("OK"):
193
  with st.spinner("Processing your PDFs..."):
 
194
  # Get PDF Text
195
  raw_text = get_pdf_text(pdf_files)
196
 
 
198
  text_chunks = get_chunk_text(raw_text)
199
 
200
  # Create Vector Store
 
201
  vector_store = get_vector_store(text_chunks)
202
  st.write("DONE")
203
 
204
  # Create conversation chain
205
+ st.session_state.conversation = get_conversation_chain(vector_store)
206
+
207
+
208
+ def initialize_conversation_chain():
209
+ return None # Replace with the actual initialization
210
+
211
+
212
+ main()
213
 
 
214
 
215
  main()