elia-waefler commited on
Commit
f91d70b
·
1 Parent(s): 7d56215

added mock functionality

Browse files
Files changed (1) hide show
  1. app.py +32 -31
app.py CHANGED
@@ -118,7 +118,6 @@ def handle_userinput(user_question):
118
  st.write(f"Source Document: {message.source}", unsafe_allow_html=True)
119
 
120
 
121
-
122
  def safe_vec_store():
123
  # USE VECTARA INSTEAD
124
  os.makedirs('vectorstore', exist_ok=True)
@@ -135,40 +134,42 @@ def main():
135
  load_dotenv()
136
  st.set_page_config(page_title="Doc Verify RAG", page_icon=":hospital:")
137
  st.write(css, unsafe_allow_html=True)
138
- st.session_state.classify = False
 
139
  st.subheader("Your documents")
140
- pdf_docs = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=not st.session_state.classify)
141
- filenames = [file.name for file in pdf_docs if file is not None]
142
-
 
 
143
  if st.button("Process"):
144
  with st.spinner("Processing"):
145
  if st.session_state.classify:
146
  # THE CLASSIFICATION APP
147
- plain_text_doc = ingest(pdf_docs)
148
-
149
- # NORMAL RAG
150
- loaded_vec_store = None
151
- for filename in filenames:
152
- if ".pkl" in filename:
153
- file_path = os.path.join('vectorstore', filename)
154
- with open(file_path, 'rb') as f:
155
- loaded_vec_store = pickle.load(f)
156
- raw_text = get_pdf_text(pdf_docs)
157
- text_chunks = get_text_chunks(raw_text)
158
- vec = get_vectorstore(text_chunks)
159
- if loaded_vec_store:
160
- vec.merge_from(loaded_vec_store)
161
- st.warning("loaded vectorstore")
162
- if "vectorstore" in st.session_state:
163
- vec.merge_from(st.session_state.vectorstore)
164
- st.warning("merged to existing")
165
- st.session_state.vectorstore = vec
166
- st.session_state.conversation = get_conversation_chain(vec)
 
 
 
167
  st.success("data loaded")
168
- if st.session_state.classify:
169
- # THE CLASSIFICATION APP
170
- classification_result = extract_metadata(plain_text_doc)
171
- st.write(classification_result)
172
 
173
 
174
  if "conversation" not in st.session_state:
@@ -180,7 +181,6 @@ def main():
180
  user_question = st.text_input("Ask a question about your documents:")
181
  if user_question:
182
  handle_userinput(user_question)
183
-
184
  with st.sidebar:
185
 
186
  st.subheader("Classification Instrucitons")
@@ -188,8 +188,9 @@ def main():
188
  filenames = [file.name for file in classifier_docs if file is not None]
189
 
190
  if st.button("Process Classification"):
 
191
  with st.spinner("Processing"):
192
- st.session_state.classify = True
193
  time.sleep(3)
194
 
195
 
 
118
  st.write(f"Source Document: {message.source}", unsafe_allow_html=True)
119
 
120
 
 
121
  def safe_vec_store():
122
  # USE VECTARA INSTEAD
123
  os.makedirs('vectorstore', exist_ok=True)
 
134
  load_dotenv()
135
  st.set_page_config(page_title="Doc Verify RAG", page_icon=":hospital:")
136
  st.write(css, unsafe_allow_html=True)
137
+ if not "classify" in st.session_state:
138
+ st.session_state.classify = False
139
  st.subheader("Your documents")
140
+ if st.session_state.classify:
141
+ pdf_doc = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=False)
142
+ else:
143
+ pdf_docs = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
144
+ filenames = [file.name for file in pdf_docs if file is not None]
145
  if st.button("Process"):
146
  with st.spinner("Processing"):
147
  if st.session_state.classify:
148
  # THE CLASSIFICATION APP
149
+ st.write("Classifying")
150
+ plain_text_doc = ingest(pdf_doc.name)
151
+ classification_result = extract_metadata(plain_text_doc)
152
+ st.write(classification_result)
153
+ else:
154
+ # NORMAL RAG
155
+ loaded_vec_store = None
156
+ for filename in filenames:
157
+ if ".pkl" in filename:
158
+ file_path = os.path.join('vectorstore', filename)
159
+ with open(file_path, 'rb') as f:
160
+ loaded_vec_store = pickle.load(f)
161
+ raw_text = get_pdf_text(pdf_docs)
162
+ text_chunks = get_text_chunks(raw_text)
163
+ vec = get_vectorstore(text_chunks)
164
+ if loaded_vec_store:
165
+ vec.merge_from(loaded_vec_store)
166
+ st.warning("loaded vectorstore")
167
+ if "vectorstore" in st.session_state:
168
+ vec.merge_from(st.session_state.vectorstore)
169
+ st.warning("merged to existing")
170
+ st.session_state.vectorstore = vec
171
+ st.session_state.conversation = get_conversation_chain(vec)
172
  st.success("data loaded")
 
 
 
 
173
 
174
 
175
  if "conversation" not in st.session_state:
 
181
  user_question = st.text_input("Ask a question about your documents:")
182
  if user_question:
183
  handle_userinput(user_question)
 
184
  with st.sidebar:
185
 
186
  st.subheader("Classification Instrucitons")
 
188
  filenames = [file.name for file in classifier_docs if file is not None]
189
 
190
  if st.button("Process Classification"):
191
+ st.session_state.classify = True
192
  with st.spinner("Processing"):
193
+ st.warning("set classify")
194
  time.sleep(3)
195
 
196