fix file upload on windows (#45)

* defer marking temp file for deletion

closes #38

* manually delete file
This commit is contained in:
NateVolt 2023-05-17 14:32:09 -04:00 committed by GitHub
parent b0e62b08d6
commit 5463bb3185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import tempfile
import time
import os
from utils import compute_sha1_from_file
from langchain.schema import Document
import streamlit as st
@ -16,13 +17,14 @@ def process_file(vector_store, file, loader_class, file_suffix, stats_db=None):
st.error("File size is too large. Please upload a file smaller than 1MB or self host.")
return
dateshort = time.strftime("%Y%m%d")
with tempfile.NamedTemporaryFile(delete=True, suffix=file_suffix) as tmp_file:
with tempfile.NamedTemporaryFile(delete=False, suffix=file_suffix) as tmp_file:
tmp_file.write(file.getvalue())
tmp_file.flush()
loader = loader_class(tmp_file.name)
documents = loader.load()
file_sha1 = compute_sha1_from_file(tmp_file.name)
os.remove(tmp_file.name)
chunk_size = st.session_state['chunk_size']
chunk_overlap = st.session_state['chunk_overlap']