Spaces:
Sleeping
Sleeping
Commit
·
351c7d2
1
Parent(s):
216cf90
Update app.py
Browse files
app.py
CHANGED
@@ -48,30 +48,30 @@ if "directory_path" not in st.session_state:
|
|
48 |
with st.sidebar:
|
49 |
st.subheader("Upload your Documents Here: ")
|
50 |
if "pdf_files" not in st.session_state:
|
51 |
-
st.session_state.pdf_files = st.file_uploader("Choose your PDF Files and Press OK", type=['pdf'], accept_multiple_files=True)
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
|
76 |
# Load documents from a directory
|
77 |
#documents = SimpleDirectoryReader('data').load_data()
|
|
|
48 |
with st.sidebar:
|
49 |
st.subheader("Upload your Documents Here: ")
|
50 |
if "pdf_files" not in st.session_state:
|
51 |
+
st.session_state.pdf_files = st.file_uploader("Choose your PDF Files and Press OK", type=['pdf'], accept_multiple_files=True)
|
52 |
+
if not st.session_state.pdf_files: #如果没有上传文件,则程序停止执行,就不会出现documents为空的错误情况、
|
53 |
+
st.warning("请上传文档文件")
|
54 |
+
st.stop()
|
55 |
+
else: #如果已经上传文件,则装载文件SimpleDirectoryReader.load_data()
|
56 |
+
st.session_state.pdf_files=pdf_files
|
57 |
+
if not os.path.exists(st.session_state.directory_path):
|
58 |
+
os.makedirs(st.session_state.directory_path)
|
59 |
+
for pdf_file in st.session_state.pdf_files:
|
60 |
+
#for pdf_file in pdf_files:
|
61 |
+
file_path = os.path.join(st.session_state.directory_path, pdf_file.name)
|
62 |
+
with open(file_path, 'wb') as f:
|
63 |
+
f.write(pdf_file.read())
|
64 |
+
st.success(f"File '{pdf_file.name}' saved successfully.")
|
65 |
+
try:
|
66 |
+
start_1 = timeit.default_timer() # Start timer
|
67 |
+
st.write(f"QA文档加载开始:{start_1}")
|
68 |
+
if "documents" not in st.session_state:
|
69 |
+
st.session_state.documents = SimpleDirectoryReader(st.session_state.directory_path).load_data()
|
70 |
+
end_1 = timeit.default_timer() # Start timer
|
71 |
+
st.write(f"QA文档加载结束:{end_1}")
|
72 |
+
st.write(f"QA文档加载耗时:{end_1 - start_1}")
|
73 |
+
except Exception as e:
|
74 |
+
print("文档加载出现问题/Waiting for path creation.")
|
75 |
|
76 |
# Load documents from a directory
|
77 |
#documents = SimpleDirectoryReader('data').load_data()
|