Upload 2 files
Browse files- app.py +22 -5
- doc_process.py +4 -1
app.py
CHANGED
|
@@ -9,6 +9,14 @@ from doc_process import doc_process
|
|
| 9 |
|
| 10 |
extract_folder = 'documents'
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def recode(raw: str) -> str:
|
| 13 |
'''
|
| 14 |
编码修正
|
|
@@ -56,9 +64,7 @@ def zip_extract_all(src_zip_file: ZipFile, target_path: str) -> None:
|
|
| 56 |
# 这里基于Zipfile.open()提取文件内容时需要使用原始的乱码文件名
|
| 57 |
shutil.copyfileobj(src_zip_file.open(file_or_path), z)
|
| 58 |
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
st.markdown('#### 请上传ZIP压缩文件:')
|
| 62 |
|
| 63 |
# 添加一个文件上传组件
|
| 64 |
uploaded_file = st.file_uploader("选择要上传的文件", type=["zip"])
|
|
@@ -86,8 +92,19 @@ if uploaded_file:
|
|
| 86 |
# 删除临时文件
|
| 87 |
os.remove("temp.zip")
|
| 88 |
|
| 89 |
-
if st.button('自动处理并
|
| 90 |
input_path = os.path.join(extract_folder, input_folder)
|
| 91 |
output_path = os.path.join(extract_folder, 'output')
|
| 92 |
result = doc_process(input_path=input_path, output_path=output_path)
|
| 93 |
-
st.markdown(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
extract_folder = 'documents'
|
| 11 |
|
| 12 |
+
# 压缩目录到zip文件
|
| 13 |
+
def compress_directory(directory_path, output_zip):
|
| 14 |
+
try:
|
| 15 |
+
shutil.make_archive(output_zip, 'zip', directory_path)
|
| 16 |
+
return True
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return str(e)
|
| 19 |
+
|
| 20 |
def recode(raw: str) -> str:
|
| 21 |
'''
|
| 22 |
编码修正
|
|
|
|
| 64 |
# 这里基于Zipfile.open()提取文件内容时需要使用原始的乱码文件名
|
| 65 |
shutil.copyfileobj(src_zip_file.open(file_or_path), z)
|
| 66 |
|
| 67 |
+
st.header('起诉书 & 委托书 - 自动处理程序')
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# 添加一个文件上传组件
|
| 70 |
uploaded_file = st.file_uploader("选择要上传的文件", type=["zip"])
|
|
|
|
| 92 |
# 删除临时文件
|
| 93 |
os.remove("temp.zip")
|
| 94 |
|
| 95 |
+
if st.button('自动处理并生成ZIP文件'):
|
| 96 |
input_path = os.path.join(extract_folder, input_folder)
|
| 97 |
output_path = os.path.join(extract_folder, 'output')
|
| 98 |
result = doc_process(input_path=input_path, output_path=output_path)
|
| 99 |
+
st.markdown(result)
|
| 100 |
+
|
| 101 |
+
# 在Streamlit中压缩目录
|
| 102 |
+
compressed_file_name = "output"
|
| 103 |
+
if compress_directory(os.path.join(extract_folder, 'output'), compressed_file_name):
|
| 104 |
+
st.success("导出目录已成功压缩为ZIP文件")
|
| 105 |
+
|
| 106 |
+
# 创建下载链接
|
| 107 |
+
with open(f"{compressed_file_name}.zip", "rb") as file:
|
| 108 |
+
st.download_button("点击此处下载压缩文件", file.read(), f"{compressed_file_name}.zip")
|
| 109 |
+
else:
|
| 110 |
+
st.error("目录压缩失败。")
|
doc_process.py
CHANGED
|
@@ -51,6 +51,7 @@ def doc_process(input_path, output_path):
|
|
| 51 |
num_shex = 0
|
| 52 |
num_fjzy = 0
|
| 53 |
num_hnsx = 0
|
|
|
|
| 54 |
|
| 55 |
# 改管辖法院,并存到对应融担公司的目录中
|
| 56 |
for qsz_file in qsz_file_list:
|
|
@@ -110,6 +111,7 @@ def doc_process(input_path, output_path):
|
|
| 110 |
|
| 111 |
# 替换律师和电话
|
| 112 |
if lawyer != '王磊':
|
|
|
|
| 113 |
for p in doc.paragraphs:
|
| 114 |
if '王磊' in p.text and user not in p.text:
|
| 115 |
text_new_name = p.text.replace('王磊', '张立人')
|
|
@@ -172,7 +174,8 @@ def doc_process(input_path, output_path):
|
|
| 172 |
|
| 173 |
total_have = len(qsz_file_list)
|
| 174 |
total_done = num_shex+num_fjzy+num_hnsx
|
| 175 |
-
result = f'共 {total_have} 条\n完成 {total_done} 条\n\n上海耳序:共 {num_shex} 条
|
|
|
|
| 176 |
|
| 177 |
return result
|
| 178 |
|
|
|
|
| 51 |
num_shex = 0
|
| 52 |
num_fjzy = 0
|
| 53 |
num_hnsx = 0
|
| 54 |
+
num_other_lawyer = 0
|
| 55 |
|
| 56 |
# 改管辖法院,并存到对应融担公司的目录中
|
| 57 |
for qsz_file in qsz_file_list:
|
|
|
|
| 111 |
|
| 112 |
# 替换律师和电话
|
| 113 |
if lawyer != '王磊':
|
| 114 |
+
num_other_lawyer += 1
|
| 115 |
for p in doc.paragraphs:
|
| 116 |
if '王磊' in p.text and user not in p.text:
|
| 117 |
text_new_name = p.text.replace('王磊', '张立人')
|
|
|
|
| 174 |
|
| 175 |
total_have = len(qsz_file_list)
|
| 176 |
total_done = num_shex+num_fjzy+num_hnsx
|
| 177 |
+
result = f'共 {total_have} 条\n完成 {total_done} 条\n\n上海耳序:共 {num_shex} 条 | 福建智云:共 {num_fjzy} 条 | 海南申信:共 {num_hnsx} 条\n\n \
|
| 178 |
+
需要修改律师的委托书数量:共 {num_other_lawyer} 条\n\n所有文档已完成自动编辑!'
|
| 179 |
|
| 180 |
return result
|
| 181 |
|