DrishtiSharma commited on
Commit
62ae48f
Β·
verified Β·
1 Parent(s): 8997d57

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +30 -7
app1.py CHANGED
@@ -145,16 +145,39 @@ if st.session_state.chunked and not st.session_state.vector_created:
145
  st.error(f"❌ Error creating vector store: {e}")
146
 
147
  # Debugging Logs
148
- st.write("πŸ“„ **PDF Loaded:**", st.session_state.pdf_loaded)
149
- st.write("πŸ”Ή **Chunked:**", st.session_state.chunked)
150
- st.write("πŸ“‚ **Vector Store Created:**", st.session_state.vector_created)
151
 
152
 
153
  # ----------------- Query Input -----------------
154
- query = st.text_input("πŸ” Ask a question about the document:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  if query:
156
  with st.spinner("πŸ”„ Retrieving relevant context..."):
157
- retriever = st.session_state.vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 5})
158
  contexts = retriever.invoke(query)
159
  # Debugging: Check what was retrieved
160
  st.write("Retrieved Contexts:", contexts)
@@ -227,7 +250,7 @@ if query:
227
  context_prompt = PromptTemplate(
228
  input_variables=["context_number"],
229
  template="""
230
- You main task is to analyze the json structure as a part of the Context Number Response and the list of Contexts provided in the 'Content List' and perform the following steps:-
231
  (1) Look at the output from the Relevant Context Picker Agent.
232
  (2) Analyze the 'content' key in the Json Structure format({{"content":<<content_number>>}}).
233
  (3) Retrieve the value of 'content' key and pick up the context corresponding to that element from the Content List provided.
@@ -247,7 +270,7 @@ if query:
247
  """
248
  )
249
 
250
- rag_prompt = """ You are ahelpful assistant very profiient in formulating clear and meaningful answers from the context provided.Based on the CONTEXT Provided ,Please formulate
251
  a clear concise and meaningful answer for the QUERY asked.Please refrain from making up your own answer in case the COTEXT provided is not sufficient to answer the QUERY.In such a situation please respond as 'I do not know'.
252
 
253
  QUERY:
 
145
  st.error(f"❌ Error creating vector store: {e}")
146
 
147
  # Debugging Logs
148
+ #st.write("πŸ“„ **PDF Loaded:**", st.session_state.pdf_loaded)
149
+ #st.write("πŸ”Ή **Chunked:**", st.session_state.chunked)
150
+ #st.write("πŸ“‚ **Vector Store Created:**", st.session_state.vector_created)
151
 
152
 
153
  # ----------------- Query Input -----------------
154
+ query = None
155
+
156
+ # Check if a valid PDF URL has been entered (but not processed yet)
157
+ pdf_url_entered = bool(st.session_state.get("pdf_url")) # Checks if text is in the input box
158
+
159
+ # No PDF Provided Yet
160
+ if not st.session_state.pdf_path and not pdf_url_entered:
161
+ st.info("πŸ“₯ **Please upload a PDF or enter a valid URL to proceed.**")
162
+
163
+ # PDF URL Exists but Not Processed Yet (Only show if URL exists but hasn't been downloaded)
164
+ elif pdf_url_entered and not st.session_state.pdf_loaded:
165
+ st.warning("⚠️ **PDF URL detected! Click 'Download and Process PDF' to proceed.**")
166
+
167
+ # Processing in Progress
168
+ elif st.session_state.get("trigger_download", False) and (
169
+ not st.session_state.pdf_loaded or not st.session_state.chunked or not st.session_state.vector_created
170
+ ):
171
+ st.info("⏳ **Processing your document... Please wait.**")
172
+
173
+ # βœ… Step 4: Processing Complete, Ready for Questions
174
+ elif st.session_state.pdf_loaded and st.session_state.chunked and st.session_state.vector_created:
175
+ st.success("πŸŽ‰ **Processing complete! You can now ask questions.**")
176
+ query = st.text_input("πŸ” **Ask a question about the document:**")
177
+
178
  if query:
179
  with st.spinner("πŸ”„ Retrieving relevant context..."):
180
+ retriever = st.session_state.vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 3})
181
  contexts = retriever.invoke(query)
182
  # Debugging: Check what was retrieved
183
  st.write("Retrieved Contexts:", contexts)
 
250
  context_prompt = PromptTemplate(
251
  input_variables=["context_number"],
252
  template="""
253
+ Your main task is to analyze the json structure as a part of the Context Number Response and the list of Contexts provided in the 'Content List' and perform the following steps:-
254
  (1) Look at the output from the Relevant Context Picker Agent.
255
  (2) Analyze the 'content' key in the Json Structure format({{"content":<<content_number>>}}).
256
  (3) Retrieve the value of 'content' key and pick up the context corresponding to that element from the Content List provided.
 
270
  """
271
  )
272
 
273
+ rag_prompt = """ You are a helpful assistant very profiient in formulating clear and meaningful answers from the context provided.Based on the CONTEXT Provided ,Please formulate
274
  a clear concise and meaningful answer for the QUERY asked.Please refrain from making up your own answer in case the COTEXT provided is not sufficient to answer the QUERY.In such a situation please respond as 'I do not know'.
275
 
276
  QUERY: