11import streamlit as st
2+ import os
23from langchain .document_loaders .csv_loader import CSVLoader
34from langchain .text_splitter import RecursiveCharacterTextSplitter
45from langchain .embeddings import HuggingFaceEmbeddings
56from langchain .vectorstores import FAISS
67from langchain .llms import CTransformers
7- from langchain .memory import ConversationBufferMemory
88from langchain .chains import ConversationalRetrievalChain
9- import sys
109
11- def main ():
12- st .title ("Conversational Retrieval System" )
10+ st .title ("Conversational Retrieval System" )
11+
12+ DB_FAISS_PATH = "vectorstore/db_faiss"
13+ TEMP_DIR = "temp"
14+
15+ # Create temp directory if it doesn't exist
16+ if not os .path .exists (TEMP_DIR ):
17+ os .makedirs (TEMP_DIR )
18+
19+ # Sidebar for uploading CSV file
20+ uploaded_file = st .sidebar .file_uploader ("Upload CSV file" , type = ['csv' ])
21+
22+ if uploaded_file is not None :
23+ file_path = os .path .join (TEMP_DIR , uploaded_file .name )
24+ with open (file_path , "wb" ) as f :
25+ f .write (uploaded_file .getvalue ())
26+
27+ st .write (f"Uploaded file: { uploaded_file .name } " )
28+ st .write ("Processing CSV file..." )
1329
14- DB_FAISS_PATH = "vectorstore/db_faiss"
15- file_path = st .text_input ("Enter CSV file path:" , "data/heart.csv" )
1630 loader = CSVLoader (file_path = file_path , encoding = "utf-8" , csv_args = {'delimiter' : ',' })
1731 data = loader .load ()
1832
@@ -39,5 +53,4 @@ def main():
3953 result = qa ({"question" : query , "chat_history" : chat_history })
4054 st .write ("Response:" , result ['answer' ])
4155
42- if __name__ == "__main__" :
43- main ()
56+ os .remove (file_path ) # Remove the temporary file after processing
0 commit comments