Spaces:
Sleeping
Sleeping
robertselvam
commited on
Commit
•
40488ca
1
Parent(s):
fadc3b5
Update app.py
Browse files
app.py
CHANGED
@@ -130,13 +130,7 @@ class ChatDocumentQA:
|
|
130 |
file_path = file_paths[0].name
|
131 |
file_extension = os.path.splitext(file_path)[1]
|
132 |
|
133 |
-
if file_extension == '.
|
134 |
-
pdf_docs = [file_path.name for file_path in file_paths]
|
135 |
-
raw_text = self._extract_text_from_pdfs(pdf_docs)
|
136 |
-
text_chunks = self._split_text_into_chunks(raw_text)
|
137 |
-
vectorstore = self._create_vector_store_from_text_chunks(text_chunks)
|
138 |
-
return "file uploaded", {"knowledge_base": vectorstore}
|
139 |
-
elif file_extension == '.csv':
|
140 |
# agent = self.create_agent(file_path)
|
141 |
# tools = self.get_agent_tools(agent)
|
142 |
# memory,tools,prompt = self.create_memory_for_csv_qa(tools)
|
@@ -150,7 +144,12 @@ class ChatDocumentQA:
|
|
150 |
return "file uploaded", {"knowledge_base": agent_chain}
|
151 |
|
152 |
else:
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
def _get_urls_knowledge_base(self, urls: str) -> Tuple[str, Dict[str, FAISS]]:
|
156 |
"""Build knowledge base from URLs.
|
@@ -232,24 +231,15 @@ class ChatDocumentQA:
|
|
232 |
file_path = file_paths[0].name
|
233 |
file_extension = os.path.splitext(file_path)[1]
|
234 |
|
235 |
-
if file_extension ==
|
236 |
-
vectorstore = state["knowledge_base"]
|
237 |
-
chat = self._create_conversation_chain(vectorstore)
|
238 |
-
# user_ques = {"question": message}
|
239 |
-
print("chat_history",chat_history)
|
240 |
-
response = chat({"question": message,"chat_history": chat_history})
|
241 |
-
chat_history.append((message, response["answer"]))
|
242 |
-
return "", chat_history
|
243 |
-
|
244 |
-
elif file_extension == '.csv':
|
245 |
agent_chain = state["knowledge_base"]
|
246 |
response = agent_chain.run(input = message)
|
247 |
chat_history.append((message, response))
|
248 |
return "", chat_history
|
|
|
249 |
else:
|
250 |
vectorstore = state["knowledge_base"]
|
251 |
chat = self._create_conversation_chain(vectorstore)
|
252 |
-
# user_ques = {"question": message}
|
253 |
print("chat_history",chat_history)
|
254 |
response = chat({"question": message,"chat_history": chat_history})
|
255 |
chat_history.append((message, response["answer"]))
|
|
|
130 |
file_path = file_paths[0].name
|
131 |
file_extension = os.path.splitext(file_path)[1]
|
132 |
|
133 |
+
if file_extension == '.csv':
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
# agent = self.create_agent(file_path)
|
135 |
# tools = self.get_agent_tools(agent)
|
136 |
# memory,tools,prompt = self.create_memory_for_csv_qa(tools)
|
|
|
144 |
return "file uploaded", {"knowledge_base": agent_chain}
|
145 |
|
146 |
else:
|
147 |
+
pdf_docs = [file_path.name for file_path in file_paths]
|
148 |
+
raw_text = self._extract_text_from_pdfs(pdf_docs)
|
149 |
+
text_chunks = self._split_text_into_chunks(raw_text)
|
150 |
+
vectorstore = self._create_vector_store_from_text_chunks(text_chunks)
|
151 |
+
return "file uploaded", {"knowledge_base": vectorstore}
|
152 |
+
|
153 |
|
154 |
def _get_urls_knowledge_base(self, urls: str) -> Tuple[str, Dict[str, FAISS]]:
|
155 |
"""Build knowledge base from URLs.
|
|
|
231 |
file_path = file_paths[0].name
|
232 |
file_extension = os.path.splitext(file_path)[1]
|
233 |
|
234 |
+
if file_extension == '.csv':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
agent_chain = state["knowledge_base"]
|
236 |
response = agent_chain.run(input = message)
|
237 |
chat_history.append((message, response))
|
238 |
return "", chat_history
|
239 |
+
|
240 |
else:
|
241 |
vectorstore = state["knowledge_base"]
|
242 |
chat = self._create_conversation_chain(vectorstore)
|
|
|
243 |
print("chat_history",chat_history)
|
244 |
response = chat({"question": message,"chat_history": chat_history})
|
245 |
chat_history.append((message, response["answer"]))
|