Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
3 |
from langchain.document_loaders import PyPDFLoader
|
4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
@@ -23,9 +24,18 @@ if api_key:
|
|
23 |
if uploaded_file:
|
24 |
# Load and process the document
|
25 |
with st.spinner("Processing document..."):
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
documents = loader.load()
|
28 |
|
|
|
|
|
|
|
29 |
# Split the document into chunks
|
30 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
31 |
chunks = text_splitter.split_documents(documents)
|
|
|
1 |
import os
|
2 |
+
import tempfile
|
3 |
import streamlit as st
|
4 |
from langchain.document_loaders import PyPDFLoader
|
5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
24 |
if uploaded_file:
|
25 |
# Load and process the document
|
26 |
with st.spinner("Processing document..."):
|
27 |
+
# Save the uploaded file temporarily
|
28 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
|
29 |
+
tmp_file.write(uploaded_file.getvalue())
|
30 |
+
tmp_file_path = tmp_file.name
|
31 |
+
|
32 |
+
# Use the temporary file path with PyPDFLoader
|
33 |
+
loader = PyPDFLoader(tmp_file_path)
|
34 |
documents = loader.load()
|
35 |
|
36 |
+
# Remove the temporary file
|
37 |
+
os.unlink(tmp_file_path)
|
38 |
+
|
39 |
# Split the document into chunks
|
40 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
41 |
chunks = text_splitter.split_documents(documents)
|