Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,17 +23,16 @@ st.subheader("Upload a text file and ask questions. The app will maintain a conv
|
|
| 23 |
# File upload section
|
| 24 |
uploaded_file = st.file_uploader("Upload a text file", type=["txt"])
|
| 25 |
|
|
|
|
|
|
|
| 26 |
if uploaded_file:
|
| 27 |
-
# Read the file
|
| 28 |
file_content = uploaded_file.read().decode("utf-8")
|
| 29 |
|
| 30 |
-
# Convert the
|
| 31 |
-
|
| 32 |
-
from io import StringIO
|
| 33 |
-
|
| 34 |
-
text_loader = TextLoader(StringIO(file_content))
|
| 35 |
-
document = text_loader.load()
|
| 36 |
|
|
|
|
| 37 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
|
| 38 |
doc_splits = text_splitter.split_documents(document)
|
| 39 |
|
|
|
|
| 23 |
# File upload section
|
| 24 |
uploaded_file = st.file_uploader("Upload a text file", type=["txt"])
|
| 25 |
|
| 26 |
+
from langchain.docstore.document import Document
|
| 27 |
+
|
| 28 |
if uploaded_file:
|
| 29 |
+
# Read and decode the content of the uploaded file
|
| 30 |
file_content = uploaded_file.read().decode("utf-8")
|
| 31 |
|
| 32 |
+
# Convert the content into a LangChain document
|
| 33 |
+
document = [Document(page_content=file_content)]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Split the loaded document
|
| 36 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
|
| 37 |
doc_splits = text_splitter.split_documents(document)
|
| 38 |
|