yvannn commited on
Commit
1b72b3a
·
1 Parent(s): 44f30ad

delete async function because its confusing

Browse files
src/chatbot_csv.py CHANGED
@@ -13,8 +13,7 @@ def init():
13
  load_dotenv()
14
  st.set_page_config(layout="wide", page_icon="💬", page_title="ChatBot-CSV")
15
 
16
-
17
- async def main():
18
 
19
  init()
20
  layout, sidebar, utils = Layout(), Sidebar(), Utilities()
@@ -34,7 +33,7 @@ async def main():
34
 
35
 
36
  try:
37
- chatbot = await utils.setup_chatbot(
38
  uploaded_file, st.session_state["model"], st.session_state["temperature"]
39
  )
40
  st.session_state["chatbot"] = chatbot
@@ -51,7 +50,7 @@ async def main():
51
 
52
  if is_ready:
53
  history.append("user", user_input)
54
- output = await st.session_state["chatbot"].conversational_chat(user_input)
55
  history.append("assistant", output)
56
 
57
  history.generate_messages(response_container)
@@ -66,6 +65,4 @@ async def main():
66
  sidebar.about()
67
 
68
  if __name__ == "__main__":
69
- if "page" not in st.session_state:
70
- st.session_state.page = "main"
71
- asyncio.run(main())
 
13
  load_dotenv()
14
  st.set_page_config(layout="wide", page_icon="💬", page_title="ChatBot-CSV")
15
 
16
+ def main():
 
17
 
18
  init()
19
  layout, sidebar, utils = Layout(), Sidebar(), Utilities()
 
33
 
34
 
35
  try:
36
+ chatbot = utils.setup_chatbot(
37
  uploaded_file, st.session_state["model"], st.session_state["temperature"]
38
  )
39
  st.session_state["chatbot"] = chatbot
 
50
 
51
  if is_ready:
52
  history.append("user", user_input)
53
+ output = st.session_state["chatbot"].conversational_chat(user_input)
54
  history.append("assistant", output)
55
 
56
  history.generate_messages(response_container)
 
65
  sidebar.about()
66
 
67
  if __name__ == "__main__":
68
+ main()
 
 
src/csv_agent.py CHANGED
@@ -13,7 +13,5 @@ def extra_chatbot_page():
13
  if agent :
14
  st.write(agent.run(query))
15
 
16
- if __name__ == "__main__":
17
- extra_chatbot_page()
18
 
19
 
 
13
  if agent :
14
  st.write(agent.run(query))
15
 
 
 
16
 
17
 
src/modules/chatbot.py CHANGED
@@ -29,7 +29,7 @@ class Chatbot:
29
  self.temperature = temperature
30
  self.vectors = vectors
31
 
32
- async def conversational_chat(self, query):
33
  """
34
  Starts a conversational chat with a model via Langchain
35
  """
 
29
  self.temperature = temperature
30
  self.vectors = vectors
31
 
32
+ def conversational_chat(self, query):
33
  """
34
  Starts a conversational chat with a model via Langchain
35
  """
src/modules/embedder.py CHANGED
@@ -18,7 +18,7 @@ class Embedder:
18
  if not os.path.exists(self.PATH):
19
  os.mkdir(self.PATH)
20
 
21
- async def storeDocEmbeds(self, file, filename):
22
  """
23
  Stores document embeddings using Langchain and FAISS
24
  """
@@ -42,14 +42,14 @@ class Embedder:
42
  with open(f"{self.PATH}/{filename}.pkl", "wb") as f:
43
  pickle.dump(vectors, f)
44
 
45
- async def getDocEmbeds(self, file, filename):
46
  """
47
  Retrieves document embeddings
48
  """
49
  # Check if embeddings vectors have already been stored in a pickle file
50
  if not os.path.isfile(f"{self.PATH}/{filename}.pkl"):
51
  # If not, store the vectors using the storeDocEmbeds function
52
- await self.storeDocEmbeds(file, filename)
53
 
54
  # Load the vectors from the pickle file
55
  with open(f"{self.PATH}/{filename}.pkl", "rb") as f:
 
18
  if not os.path.exists(self.PATH):
19
  os.mkdir(self.PATH)
20
 
21
+ def storeDocEmbeds(self, file, filename):
22
  """
23
  Stores document embeddings using Langchain and FAISS
24
  """
 
42
  with open(f"{self.PATH}/{filename}.pkl", "wb") as f:
43
  pickle.dump(vectors, f)
44
 
45
+ def getDocEmbeds(self, file, filename):
46
  """
47
  Retrieves document embeddings
48
  """
49
  # Check if embeddings vectors have already been stored in a pickle file
50
  if not os.path.isfile(f"{self.PATH}/{filename}.pkl"):
51
  # If not, store the vectors using the storeDocEmbeds function
52
+ self.storeDocEmbeds(file, filename)
53
 
54
  # Load the vectors from the pickle file
55
  with open(f"{self.PATH}/{filename}.pkl", "rb") as f:
src/modules/utils.py CHANGED
@@ -48,7 +48,7 @@ class Utilities:
48
  return uploaded_file
49
 
50
  @staticmethod
51
- async def setup_chatbot(uploaded_file, model, temperature):
52
  """
53
  Sets up the chatbot with the uploaded file, model, and temperature
54
  """
@@ -56,7 +56,7 @@ class Utilities:
56
  with st.spinner("Processing..."):
57
  uploaded_file.seek(0)
58
  file = uploaded_file.read()
59
- vectors = await embeds.getDocEmbeds(file, uploaded_file.name)
60
  chatbot = Chatbot(model, temperature, vectors)
61
  st.session_state["ready"] = True
62
  return chatbot
 
48
  return uploaded_file
49
 
50
  @staticmethod
51
+ def setup_chatbot(uploaded_file, model, temperature):
52
  """
53
  Sets up the chatbot with the uploaded file, model, and temperature
54
  """
 
56
  with st.spinner("Processing..."):
57
  uploaded_file.seek(0)
58
  file = uploaded_file.read()
59
+ vectors = embeds.getDocEmbeds(file, uploaded_file.name)
60
  chatbot = Chatbot(model, temperature, vectors)
61
  st.session_state["ready"] = True
62
  return chatbot