akash015 commited on
Commit
b9d8fb8
·
verified ·
1 Parent(s): 663478a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -201,8 +201,8 @@ from langchain_nomic.embeddings import NomicEmbeddings
201
  import os
202
 
203
  llm_groq = ChatGroq(
204
- model_name='llama3-70b-8192'
205
- )
206
 
207
  # Initialize anonymizer
208
  anonymizer = PresidioReversibleAnonymizer(analyzed_fields=['PERSON', 'EMAIL_ADDRESS', 'PHONE_NUMBER', 'IBAN_CODE', 'CREDIT_CARD', 'CRYPTO', 'IP_ADDRESS', 'LOCATION', 'DATE_TIME', 'NRP', 'MEDICAL_LICENSE', 'URL'], faker_seed=18)
@@ -285,7 +285,6 @@ async def on_chat_start():
285
  while files is None:
286
  files = await cl.AskFileMessage(
287
  content="Please upload a pdf file to begin!",
288
- # accept=["application/pdf"],
289
  accept=["application/pdf", "image/jpeg", "image/png", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
290
  max_size_mb=100,
291
  timeout=180,
@@ -313,7 +312,6 @@ async def on_chat_start():
313
  docsearch = await cl.make_async(Chroma.from_texts)(
314
  [anonymized_text], embeddings, metadatas=[{"source": "0-pl"}]
315
  )
316
- # }
317
 
318
  # Initialize message history for conversation
319
  message_history = ChatMessageHistory()
@@ -340,6 +338,7 @@ async def on_chat_start():
340
  await msg.update()
341
  # Store the chain in user session
342
  cl.user_session.set("chain", chain)
 
343
  cl.user_session.set("file_path", file.path) # Store the file path in session
344
 
345
 
@@ -363,12 +362,12 @@ async def main(message: cl.Message):
363
 
364
  @cl.on_chat_end
365
  async def on_chat_end():
366
- chain = cl.user_session.get("chain")
367
  file_path = cl.user_session.get("file_path")
368
 
369
- if chain:
370
  # Clear the vector store
371
- chain.retriever.store.clear()
372
 
373
  if file_path and os.path.exists(file_path):
374
  # Remove the uploaded file
@@ -378,4 +377,3 @@ async def on_chat_end():
378
  cl.user_session.clear()
379
 
380
  logging.info("User session ended, data cleared.")
381
-
 
201
  import os
202
 
203
  llm_groq = ChatGroq(
204
+ model_name='llama3-70b-8192'
205
+ )
206
 
207
  # Initialize anonymizer
208
  anonymizer = PresidioReversibleAnonymizer(analyzed_fields=['PERSON', 'EMAIL_ADDRESS', 'PHONE_NUMBER', 'IBAN_CODE', 'CREDIT_CARD', 'CRYPTO', 'IP_ADDRESS', 'LOCATION', 'DATE_TIME', 'NRP', 'MEDICAL_LICENSE', 'URL'], faker_seed=18)
 
285
  while files is None:
286
  files = await cl.AskFileMessage(
287
  content="Please upload a pdf file to begin!",
 
288
  accept=["application/pdf", "image/jpeg", "image/png", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
289
  max_size_mb=100,
290
  timeout=180,
 
312
  docsearch = await cl.make_async(Chroma.from_texts)(
313
  [anonymized_text], embeddings, metadatas=[{"source": "0-pl"}]
314
  )
 
315
 
316
  # Initialize message history for conversation
317
  message_history = ChatMessageHistory()
 
338
  await msg.update()
339
  # Store the chain in user session
340
  cl.user_session.set("chain", chain)
341
+ cl.user_session.set("docsearch", docsearch) # Store the docsearch in session
342
  cl.user_session.set("file_path", file.path) # Store the file path in session
343
 
344
 
 
362
 
363
  @cl.on_chat_end
364
  async def on_chat_end():
365
+ docsearch = cl.user_session.get("docsearch")
366
  file_path = cl.user_session.get("file_path")
367
 
368
+ if docsearch:
369
  # Clear the vector store
370
+ docsearch.delete()
371
 
372
  if file_path and os.path.exists(file_path):
373
  # Remove the uploaded file
 
377
  cl.user_session.clear()
378
 
379
  logging.info("User session ended, data cleared.")