Ryu-m0m commited on
Commit
529a843
1 Parent(s): 66c03ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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 os
 
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
- # Save the uploaded file temporarily
56
- temp_file_path = os.path.join("/tmp", uploaded_file.name)
57
- with open(temp_file_path, "wb") as f:
58
- f.write(uploaded_file.getbuffer())
59
 
60
  # Load the PDF using PyPDFLoader
61
  docs = PyPDFLoader(temp_file_path).load()
62
 
63
- # Clean up the temporary file after loading
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