Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from langchain.text_splitter import CharacterTextSplitter
|
|
7 |
from langchain.embeddings import OpenAIEmbeddings
|
8 |
from langchain.vectorstores import FAISS
|
9 |
from langchain.memory import ConversationBufferMemory
|
|
|
|
|
|
|
10 |
import re
|
11 |
def main():
|
12 |
# Initialize the Streamlit app
|
@@ -22,9 +25,14 @@ def main():
|
|
22 |
uploaded_file = st.file_uploader("Upload your document", type=['txt'])
|
23 |
if uploaded_file is not None:
|
24 |
# Read and process the document
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
27 |
-
data = text_splitter.split_documents(
|
28 |
|
29 |
# Create vector store
|
30 |
embeddings = OpenAIEmbeddings()
|
|
|
7 |
from langchain.embeddings import OpenAIEmbeddings
|
8 |
from langchain.vectorstores import FAISS
|
9 |
from langchain.memory import ConversationBufferMemory
|
10 |
+
from langchain.document_loaders import TextLoader
|
11 |
+
from tempfile import NamedTemporaryFile
|
12 |
+
|
13 |
import re
|
14 |
def main():
|
15 |
# Initialize the Streamlit app
|
|
|
25 |
uploaded_file = st.file_uploader("Upload your document", type=['txt'])
|
26 |
if uploaded_file is not None:
|
27 |
# Read and process the document
|
28 |
+
with NamedTemporaryFile(delete=False) as f:
|
29 |
+
f.write(uploaded_file.getbuffer())
|
30 |
+
loader = TextLoader(f.name, encoding="utf-8")
|
31 |
+
data = loader.load()
|
32 |
+
|
33 |
+
|
34 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
35 |
+
data = text_splitter.split_documents(data)
|
36 |
|
37 |
# Create vector store
|
38 |
embeddings = OpenAIEmbeddings()
|