Skip to content

Commit 368bb75

Browse files
Update model.py
CSV Upload: Allows users to upload CSV files for conversation retrieval.
1 parent 0ad3aec commit 368bb75

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

model.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import streamlit as st
2+
import os
23
from langchain.document_loaders.csv_loader import CSVLoader
34
from langchain.text_splitter import RecursiveCharacterTextSplitter
45
from langchain.embeddings import HuggingFaceEmbeddings
56
from langchain.vectorstores import FAISS
67
from langchain.llms import CTransformers
7-
from langchain.memory import ConversationBufferMemory
88
from 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

Comments
 (0)