Cheselle commited on
Commit
30a4f31
·
verified ·
1 Parent(s): 3bfb998

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -19,6 +19,7 @@ from operator import itemgetter
19
  from langchain_core.runnables.passthrough import RunnablePassthrough
20
  import chainlit as cl
21
  from langchain_core.runnables.config import RunnableConfig
 
22
 
23
  load_dotenv()
24
 
@@ -68,6 +69,11 @@ def process_file(file: AskFileResponse):
68
  doc.metadata["source"] = f"source_{i}"
69
  return docs
70
 
 
 
 
 
 
71
 
72
 
73
  @cl.on_chat_start
@@ -76,8 +82,6 @@ async def on_chat_start():
76
  files = None
77
 
78
  while files == None:
79
- # Async method: This allows the function to pause execution while waiting for the user to upload a file,
80
- # without blocking the entire application. It improves responsiveness and scalability.
81
  files = await cl.AskFileMessage(
82
  content="Please upload a PDF file to begin!",
83
  accept=["application/pdf"],
@@ -122,7 +126,7 @@ async def on_chat_start():
122
  )
123
 
124
  # Let the user know that the system is ready
125
- msg.content = f"Processing `{file.name}` done. You can now ask questions!"
126
  await msg.update()
127
 
128
  cl.user_session.set("chain", retrieval_augmented_qa_chain)
 
19
  from langchain_core.runnables.passthrough import RunnablePassthrough
20
  import chainlit as cl
21
  from langchain_core.runnables.config import RunnableConfig
22
+ import time
23
 
24
  load_dotenv()
25
 
 
69
  doc.metadata["source"] = f"source_{i}"
70
  return docs
71
 
72
+ def measure_embedding_time(docs):
73
+ start_time = time.time()
74
+ vectorstore.add_documents(docs)
75
+ elapsed_time = time.time() - start_time
76
+ print(f"{str(docs)} took {elapsed_time:.2f} seconds")
77
 
78
 
79
  @cl.on_chat_start
 
82
  files = None
83
 
84
  while files == None:
 
 
85
  files = await cl.AskFileMessage(
86
  content="Please upload a PDF file to begin!",
87
  accept=["application/pdf"],
 
126
  )
127
 
128
  # Let the user know that the system is ready
129
+ msg.content = measure_embedding_time(docs)
130
  await msg.update()
131
 
132
  cl.user_session.set("chain", retrieval_augmented_qa_chain)