Spaces:
Running
Running
admin
commited on
Commit
·
c758752
1
Parent(s):
45a7258
refine txts
Browse files
README.md
CHANGED
|
@@ -7,6 +7,6 @@ sdk: gradio
|
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
short_description: Clean
|
| 11 |
license: apache-2.0
|
| 12 |
---
|
|
|
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
short_description: Clean image EXIF
|
| 11 |
license: apache-2.0
|
| 12 |
---
|
app.py
CHANGED
|
@@ -8,17 +8,16 @@ from PIL import Image
|
|
| 8 |
from utils import clean_dir, compress, mk_dir, unzip, TMP_DIR, EN_US
|
| 9 |
|
| 10 |
ZH2EN = {
|
| 11 |
-
"
|
| 12 |
-
"
|
|
|
|
|
|
|
| 13 |
"导出原格式": "Export original format",
|
| 14 |
-
"
|
| 15 |
"批量处理": "Batch processor",
|
| 16 |
-
"
|
| 17 |
-
"导出原格式": "Export original format",
|
| 18 |
-
"下载清理 EXIF 后的多图片压缩包": "Download cleaned pictures",
|
| 19 |
"EXIF 列表": "EXIF list",
|
| 20 |
"状态栏": "Status",
|
| 21 |
-
"# 图片 EXIF 清理": "# Image EXIF Cleaner",
|
| 22 |
}
|
| 23 |
|
| 24 |
|
|
@@ -89,7 +88,7 @@ def batch_infer(imgs_zip: str, keep_ext: bool, cache=f"{TMP_DIR}/exif"):
|
|
| 89 |
out_images = out_exifs = None
|
| 90 |
try:
|
| 91 |
if not imgs_zip:
|
| 92 |
-
raise ValueError("Please upload
|
| 93 |
|
| 94 |
clean_dir(cache)
|
| 95 |
mk_dir(f"{cache}/outputs")
|
|
@@ -103,7 +102,7 @@ def batch_infer(imgs_zip: str, keep_ext: bool, cache=f"{TMP_DIR}/exif"):
|
|
| 103 |
exifs.append({"filename": os.path.basename(img), "exif": get_exif(img)})
|
| 104 |
|
| 105 |
if not exifs:
|
| 106 |
-
raise ValueError("No
|
| 107 |
|
| 108 |
out_images = f"{cache}/outputs.zip"
|
| 109 |
compress(f"{cache}/outputs", out_images)
|
|
|
|
| 8 |
from utils import clean_dir, compress, mk_dir, unzip, TMP_DIR, EN_US
|
| 9 |
|
| 10 |
ZH2EN = {
|
| 11 |
+
"上传包含多图片的压缩包 (请确保上传完全后再提交)": "Upload compressed package with images (please ensure the package is completely uploaded before clicking submit)",
|
| 12 |
+
"下载清理 EXIF 后的多图片压缩包": "Download cleaned images",
|
| 13 |
+
"下载清理 EXIF 后的图片": "Download cleaned image",
|
| 14 |
+
"# 图片 EXIF 清理": "# Image EXIF Cleaner",
|
| 15 |
"导出原格式": "Export original format",
|
| 16 |
+
"单图片处理": "Process single image",
|
| 17 |
"批量处理": "Batch processor",
|
| 18 |
+
"上传图片": "Upload image",
|
|
|
|
|
|
|
| 19 |
"EXIF 列表": "EXIF list",
|
| 20 |
"状态栏": "Status",
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
|
|
|
|
| 88 |
out_images = out_exifs = None
|
| 89 |
try:
|
| 90 |
if not imgs_zip:
|
| 91 |
+
raise ValueError("Please upload image archive!")
|
| 92 |
|
| 93 |
clean_dir(cache)
|
| 94 |
mk_dir(f"{cache}/outputs")
|
|
|
|
| 102 |
exifs.append({"filename": os.path.basename(img), "exif": get_exif(img)})
|
| 103 |
|
| 104 |
if not exifs:
|
| 105 |
+
raise ValueError("No image in the zip")
|
| 106 |
|
| 107 |
out_images = f"{cache}/outputs.zip"
|
| 108 |
compress(f"{cache}/outputs", out_images)
|
utils.py
CHANGED
|
@@ -40,16 +40,13 @@ def unzip(archive: str, extract_to: str):
|
|
| 40 |
|
| 41 |
|
| 42 |
def compress(folder_path: str, zip_file: str):
|
| 43 |
-
# 确保文件夹存在
|
| 44 |
-
if not os.path.exists(folder_path):
|
| 45 |
raise ValueError(f"错误: 文件夹 '{folder_path}' 不存在")
|
| 46 |
# 打开 ZIP 文件,使用 'w' 模式表示写入
|
| 47 |
with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 48 |
-
# 遍历文件夹中的文件和子文件夹
|
| 49 |
-
for root, _, files in os.walk(folder_path):
|
| 50 |
for file in files:
|
| 51 |
-
file_path = os.path.join(root, file)
|
| 52 |
-
# 计算相对路径,保留文件夹的根目录
|
| 53 |
relative_path = os.path.relpath(file_path, folder_path)
|
| 54 |
zipf.write(
|
| 55 |
file_path,
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
def compress(folder_path: str, zip_file: str):
|
| 43 |
+
if not os.path.exists(folder_path): # 确保文件夹存在
|
|
|
|
| 44 |
raise ValueError(f"错误: 文件夹 '{folder_path}' 不存在")
|
| 45 |
# 打开 ZIP 文件,使用 'w' 模式表示写入
|
| 46 |
with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 47 |
+
for root, _, files in os.walk(folder_path): # 遍历文件夹中的文件和子文件夹
|
|
|
|
| 48 |
for file in files:
|
| 49 |
+
file_path = os.path.join(root, file) # 计算相对路径,保留文件夹的根目录
|
|
|
|
| 50 |
relative_path = os.path.relpath(file_path, folder_path)
|
| 51 |
zipf.write(
|
| 52 |
file_path,
|