还在为日益被塞满的C盘而烦恼吗?看看这款开源工具

发布时间:2025-02-01 18:09

看到快递员满头大汗的样子,可以开玩笑说'你这是在为我送货上门做瑜伽吗?' #生活乐趣# #日常生活趣事# #轻松幽默的生活方式# #轻松幽默段落#

AI 赋能的智能文件清理工具

项目地址:github

概述:

这款 AI 驱动的文件清理工具超越了传统清理工具的局限,它不仅可以快速删除无用文件,还能智能识别重复文件、相似图片,并提供个性化的文件管理建议,从而释放更多存储空间,提升设备性能。

核心功能:

智能扫描与分类:

深度学习图像识别: 利用先进的卷积神经网络 (CNN) 技术,对图片进行深度分析,识别相似或重复的图片,即使它们的文件名或哈希值不同。文件类型识别: 准确识别各种文件类型(文档、视频、音频、安装包等),并将其智能分类,方便用户管理和清理。垃圾文件识别: 精准识别缓存文件、临时文件、日志文件等各种垃圾文件,确保清理的安全性。

AI 驱动的文件压缩与优化:

智能压缩: 基于 AI 算法,分析图片和视频的内容,在保证质量的前提下,智能选择最佳压缩比例,最大程度减小文件体积。格式转换建议: 根据文件类型和使用场景,智能推荐更优的文件格式,例如将大型图片转换为 WebP 格式,以节省空间。

个性化文件管理建议:

使用频率分析: AI 模型分析用户的文件访问历史,识别长期未使用的文件,并智能推荐删除或备份。文件重要性评估: 根据文件类型、大小、创建时间等因素,评估文件的重要性,为用户提供更合理的清理建议。云端备份建议: 对于重要的文件,智能推荐备份到云端,确保数据安全。

用户友好的交互界面:

可视化清理报告: 以图表形式清晰展示扫描结果,包括垃圾文件大小、重复文件数量、可释放空间等信息。自定义清理选项: 用户可以根据自身需求,自定义清理规则,例如选择要扫描的文件类型、设置压缩比例等。一键清理: 提供一键清理功能,快速释放存储空间。 AI 模块的集成示例(基于 Python) 1. 图像相似性检测

对于图片的相似性,可以使用卷积神经网络(CNN)或 pre-trained models 来比较图像特征。

这里使用 OpenCV 和 deep learning 提供的预训练模型,如 VGG16 或 ResNet,来提取图像特征,计算相似性。

import cv2 from keras.applications.vgg16 import VGG16, preprocess_input from keras.preprocessing import image import numpy as np from sklearn.metrics.pairwise import cosine_similarity # 加载 VGG16 预训练模型 model = VGG16(weights='imagenet', include_top=False) def extract_features(img_path): """提取图像的特征向量""" img = image.load_img(img_path, target_size=(224, 224)) img_data = image.img_to_array(img) img_data = np.expand_dims(img_data, axis=0) img_data = preprocess_input(img_data) # 通过模型提取特征 vgg16_feature = model.predict(img_data) return vgg16_feature.flatten() def are_images_similar(img_path1, img_path2): """比较两张图像的相似度""" features1 = extract_features(img_path1) features2 = extract_features(img_path2) # 计算余弦相似度 similarity = cosine_similarity([features1], [features2]) return similarity[0][0] if __name__ == "__main__": img1 = 'image1.jpg' img2 = 'image2.jpg' similarity_score = are_images_similar(img1, img2) print(f"Image similarity score: {similarity_score}") if similarity_score > 0.9: print("Images are similar") else: print("Images are not similar")

123456789101112131415161718192021222324252627282930313233343536373839 2. 智能压缩(AI 指导下的图像压缩)

这里我们可以基于图像的内容来智能选择压缩策略。例如,对于颜色较多的复杂图像,我们可能希望保留更多细节,而对于简单的图像,可以进行较大的压缩。

from PIL import Image import numpy as np import cv2 def compress_image_based_on_content(image_path, output_path, quality=85): """基于图像内容智能选择压缩策略""" # 读取图像 img = Image.open(image_path) img_np = np.array(img) # 使用 OpenCV 计算图像的边缘复杂度(作为内容复杂度的代理) gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 100, 200) edge_density = np.mean(edges) / 255 # 根据复杂度选择压缩质量 if edge_density > 0.1: # 如果边缘多,保留更多质量 final_quality = max(quality, 90) else: # 如果边缘少,可以进行更多压缩 final_quality = min(quality, 70) # 保存压缩后的图像 img.save(output_path, "JPEG", quality=final_quality) print(f"Image compressed with quality: {final_quality}") if __name__ == "__main__": compress_image_based_on_content("large_photo.jpg", "compressed_photo.jpg")

123456789101112131415161718192021222324252627 3. 智能文件删除推荐

可以基于机器学习模型来分析用户的文件使用情况,例如哪些文件长时间未被访问过,哪些文件占用大量空间但可能是重复文件,从而向用户推荐要清理的文件。

import os import time import numpy as np from sklearn.cluster import KMeans def file_size_and_age(file_path): """返回文件的大小和上次访问时间""" size = os.path.getsize(file_path) last_access_time = os.path.getatime(file_path) current_time = time.time() # 文件的存储时间差值(秒为单位) age = (current_time - last_access_time) / (60 * 60 * 24) # 转换为天 return size, age def recommend_files_for_deletion(directory): """智能推荐要删除的文件""" file_info = [] file_paths = [] for dirpath, _, filenames in os.walk(directory): for filename in filenames: file_path = os.path.join(dirpath, filename) size, age = file_size_and_age(file_path) file_info.append([size, age]) file_paths.append(file_path) # 采用聚类算法,将文件按大小和时间进行分类 kmeans = KMeans(n_clusters=3) clusters = kmeans.fit_predict(file_info) # 根据聚类结果推荐删除(如:最大尺寸和最长时间未访问的文件) delete_candidates = np.where(clusters == np.argmax(kmeans.cluster_centers_.sum(axis=1)))[0] print("Recommended files for deletion:") for idx in delete_candidates: print(file_paths[idx]) if __name__ == "__main__": recommend_files_for_deletion("/path/to/your/files")

12345678910111213141516171819202122232425262728293031323334353637383940 4. AI 驱动的文件保护

使用 AI 对文件类型进行分类,决定哪些文件需要加密保护。

import magic # 用于检测文件类型 from cryptography.fernet import Fernet def generate_key(): """生成加密密钥""" return Fernet.generate_key() def encrypt_file(file_path, key): """根据文件类型选择是否加密""" # 使用 magic 库检测文件类型 file_type = magic.from_file(file_path, mime=True) # 如果文件类型为敏感类型(如文档或图片),则加密 sensitive_types = ['application/pdf', 'image/jpeg', 'image/png'] if file_type in sensitive_types: fernet = Fernet(key) with open(file_path, 'rb') as f: file_data = f.read() encrypted_data = fernet.encrypt(file_data) with open(file_path + ".enc", 'wb') as f: f.write(encrypted_data) print(f"File encrypted: {file_path}") else: print(f"File {file_path} does not need encryption.") if __name__ == "__main__": key = generate_key() encrypt_file("important_file.pdf", key)

1234567891011121314151617181920212223242526272829 项目目录结构:

ai_cleaner_open_source/ │ ├── README.md ├── requirements.txt ├── main.py ├── ai_modules/ # AI 模块目录 │ ├── __init__.py │ ├── image_similarity.py # 图像相似性检测模块 │ ├── smart_compression.py # 智能压缩模块 │ ├── file_recommendation.py # 文件删除推荐模块 │ └── file_encryption.py # 文件加密保护模块 ├── cleaner/ │ ├── __init__.py │ ├── duplicate_finder.py │ ├── contact_cleaner.py │ ├── image_compressor.py │ └── cache_cleaner.py └── tests/ └── test_cleaner.py

12345678910111213141516171819

为了使用户能够方便地使用这个 AI 驱动的清理工具,各个功能模块进行了封装,并提供易用的界面和调用方式。
分别进行了以下的几种方式:

创建清晰的命令行界面 (CLI):使用户可以通过命令行参数来指定他们想要执行的操作。提供 API 接口:让开发者可以通过 Python API 调用你的工具。图形用户界面 (GUI):为非技术用户创建一个图形界面,用户可以通过点击按钮来执行操作。打包工具:将项目打包成一个易于安装和运行的工具。 1. 创建命令行界面(CLI)

使用 Python 的 argparse 模块,你可以为不同的清理功能创建命令行选项,这样用户可以直接在终端中运行不同的清理操作。

import argparse from cleaner import duplicate_finder, contact_cleaner, cache_cleaner, image_compressor from ai_modules import image_similarity, smart_compression, file_recommendation def main(): parser = argparse.ArgumentParser(description="AI Cleaner: 一个人工智能驱动的清理工具") # 添加命令行选项 parser.add_argument('--clean-duplicates', type=str, help="清理重复文件的目录路径") parser.add_argument('--clean-contacts', type=str, help="清理重复联系人的vCard文件路径") parser.add_argument('--compress-image', type=str, help="压缩图片的文件路径") parser.add_argument('--recommend-deletion', type=str, help="智能推荐要删除的文件的目录路径") parser.add_argument('--encrypt-file', type=str, help="加密保护文件的文件路径") args = parser.parse_args() # 根据用户的输入调用不同的功能 if args.clean_duplicates: duplicates = duplicate_finder.find_duplicate_files(args.clean_duplicates) if duplicates: print("Found duplicate files:") for dup in duplicates: print(f"Duplicate: {dup[0]} and {dup[1]}") else: print("No duplicate files found.") if args.clean_contacts: contacts = contact_cleaner.clean_contacts(args.clean_contacts) for contact in contacts: print(f"Unique contact: {contact.fn.value}") if args.compress_image: image_compressor.compress_image_based_on_content(args.compress_image, args.compress_image + '_compressed.jpg') if args.recommend_deletion: file_recommendation.recommend_files_for_deletion(args.recommend_deletion) if args.encrypt_file: from ai_modules.file_encryption import encrypt_file, generate_key key = generate_key() encrypt_file(args.encrypt_file, key) print(f"File {args.encrypt_file} encrypted successfully.") if __name__ == "__main__": main()

123456789101112131415161718192021222324252627282930313233343536373839404142434445 使用示例:

用户在终端中可以这样使用该工具:

python main.py --clean-duplicates /path/to/directory python main.py --clean-contacts contacts.vcf python main.py --compress-image large_image.jpg python main.py --recommend-deletion /path/to/directory python main.py --encrypt-file important_file.pdf 12345

这样可以方便用户通过命令行执行各种清理和压缩任务。

2. 提供 Python API 接口

对于开发者用户,提供了一个易于集成的 Python API,这样其他 Python 项目可以调用你的清理工具。

from cleaner import duplicate_finder, contact_cleaner, cache_cleaner, image_compressor from ai_modules import image_similarity, smart_compression, file_recommendation class AICleaner: @staticmethod def clean_duplicates(directory): """清理重复文件""" return duplicate_finder.find_duplicate_files(directory) @staticmethod def clean_contacts(vcard_path): """清理重复联系人""" return contact_cleaner.clean_contacts(vcard_path) @staticmethod def compress_image(image_path, output_path=None): """智能压缩图像""" if not output_path: output_path = image_path + '_compressed.jpg' image_compressor.compress_image_based_on_content(image_path, output_path) @staticmethod def recommend_files_for_deletion(directory): """智能推荐删除的文件""" file_recommendation.recommend_files_for_deletion(directory) @staticmethod def encrypt_file(file_path, key=None): """加密文件""" from ai_modules.file_encryption import encrypt_file, generate_key if not key: key = generate_key() encrypt_file(file_path, key) return key

12345678910111213141516171819202122232425262728293031323334 使用示例:

from ai_cleaner import AICleaner # 清理重复文件 duplicates = AICleaner.clean_duplicates("/path/to/directory") for dup in duplicates: print(f"Duplicate: {dup[0]} and {dup[1]}") # 压缩图像 AICleaner.compress_image("large_image.jpg") 123456789 3. 创建图形用户界面(GUI)

你可以为非技术用户设计一个简单的图形界面,让他们可以通过点击按钮来执行不同的清理操作。使用 Tkinter 是一个不错的选择,它是 Python 内置的 GUI 库,简单易用。

import tkinter as tk from tkinter import filedialog from ai_cleaner import AICleaner class AICleanerGUI: def __init__(self, master): self.master = master master.title("AI Cleaner") self.label = tk.Label(master, text="选择操作:") self.label.pack() self.clean_duplicates_button = tk.Button(master, text="清理重复文件", command=self.clean_duplicates) self.clean_duplicates_button.pack() self.compress_image_button = tk.Button(master, text="压缩图片", command=self.compress_image) self.compress_image_button.pack() def clean_duplicates(self): directory = filedialog.askdirectory() if directory: duplicates = AICleaner.clean_duplicates(directory) if duplicates: result = "\n".join([f"{dup[0]} 和 {dup[1]}" for dup in duplicates]) else: result = "没有找到重复文件" tk.messagebox.showinfo("结果", result) def compress_image(self): image_path = filedialog.askopenfilename() if image_path: AICleaner.compress_image(image_path) tk.messagebox.showinfo("结果", f"图片 {image_path} 压缩完成") if __name__ == "__main__": root = tk.Tk() gui = AICleanerGUI(root) root.mainloop()

1234567891011121314151617181920212223242526272829303132333435363738

通过这个简单的 GUI,用户可以:

选择要清理的文件夹点击按钮执行相应操作查看操作结果 4. 打包工具

使用 PyInstaller 或 cx_Freeze 将 Python 脚本打包为独立的可执行文件,方便非开发人员用户直接运行你的清理工具。

例如,使用 PyInstaller 打包:

pip install pyinstaller pyinstaller --onefile main.py 12

这样会生成一个独立的可执行文件,用户可以直接运行这个文件,无需安装 Python 环境或依赖库。

项目发布和分发 GitHub:项目已经上传到 GitHub,并提供源码和使用说明文档。PyPI:将 Python 包发布到 PyPI,用户可以通过 pip install ai-cleaner 进行安装。创建安装包:对于打包成可执行文件的版本,也提供了.exe 或 .dmg 文件直接给用户下载。(curl -L -O “https://plantree.us.kg/aicleaner.exe/dmg”)

老铁们多多支持!!!(ios-Alcleaner的同款,pc端免费开源可用,一行命令把windows清干净它不香吗!!!)

网址:还在为日益被塞满的C盘而烦恼吗?看看这款开源工具 https://www.yuejiaxmz.com/news/view/750760

相关内容

还在为家具清洁烦恼?清洁妙招看这里
还在为厕所不干净而烦恼吗?来看看这几种厕所清洁方法
你还在为清洁而烦恼吗?有这几样你就轻松多了!
还在为墙面装修而烦恼吗?
还在为家里如何选购餐桌而烦恼吗?这样解决,省地方又实用!
厨房储存的烦恼,你知道吗?
还在为厨房凌乱而烦恼吗,9个日式厨房收纳方案为您解决问题
家中总是乱糟糟?看这款神奇垃圾袋如何解决你的烦恼!
你还在为卫生间装修烦恼吗?看这里就行啦
还在为每天的早餐烦恼吗?清单都在这了~

随便看看