Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,8 @@ from sentence_transformers import CrossEncoder
|
|
17 |
import numpy as np
|
18 |
import random
|
19 |
import string
|
20 |
-
import
|
|
|
21 |
|
22 |
# User variables
|
23 |
uploaded_file = st.sidebar.file_uploader("Upload your PDF", type="pdf")
|
@@ -52,16 +53,15 @@ elif st.session_state.error_message:
|
|
52 |
st.sidebar.error(st.session_state.error_message)
|
53 |
|
54 |
if uploaded_file:
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
# Load the PDF using PyPDFLoader
|
61 |
docs = PyPDFLoader(temp_file_path).load()
|
62 |
|
63 |
-
#
|
64 |
-
os.remove(temp_file_path)
|
65 |
else:
|
66 |
st.warning("Please upload a PDF file.")
|
67 |
|
|
|
17 |
import numpy as np
|
18 |
import random
|
19 |
import string
|
20 |
+
import tempfile
|
21 |
+
|
22 |
|
23 |
# User variables
|
24 |
uploaded_file = st.sidebar.file_uploader("Upload your PDF", type="pdf")
|
|
|
53 |
st.sidebar.error(st.session_state.error_message)
|
54 |
|
55 |
if uploaded_file:
|
56 |
+
# Create a temporary file
|
57 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
|
58 |
+
temp_file.write(uploaded_file.getbuffer())
|
59 |
+
temp_file_path = temp_file.name
|
60 |
|
61 |
# Load the PDF using PyPDFLoader
|
62 |
docs = PyPDFLoader(temp_file_path).load()
|
63 |
|
64 |
+
# The temporary file will be automatically deleted when the application stops
|
|
|
65 |
else:
|
66 |
st.warning("Please upload a PDF file.")
|
67 |
|