An AI-powered document organizer for local files.
Project description
Document Organizer using Hugging Face
This Python script helps you organize your documents into categorized folders using a pre-trained Hugging Face zero-shot classification model. It can classify documents based on their filenames and move them into relevant categories, or flag them for manual review if confidence is low.
Features
-
Zero-Shot Classification: Categorizes documents without needing prior training on your specific data, leveraging the
facebook/bart-large-mnlimodel. -
Customizable Categories: Easily define your own list of categories relevant to your document collection.
-
Filename-based Classification: Extracts a clean title from the filename for classification, removing noise like file extensions and ISBNs.
-
Confidence Thresholding: Documents with low classification confidence are moved to a special "Needs Manual Review" folder.
-
Dry Run Mode: Preview the organization structure and proposed actions before any files are moved or folders are created.
-
Optional Filename Filtering: Use regular expressions to process only specific types of files (e.g., only PDF documents).
-
GPU Acceleration (Optional): Automatically attempts to use a CUDA-enabled GPU for faster classification if PyTorch and a compatible GPU are detected.
Getting Started
Prerequisites
Before running the script, ensure you have Python 3.8+ installed. You'll also need to install the necessary Python libraries.
-
Create a Virtual Environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate -
Install Dependencies:
pip install -r requirements.txtrequirements.txtcontent:transformers torch # Or tensorflow, depending on your preference and GPU setup- For GPU support: If you have an NVIDIA GPU, ensure you install PyTorch with CUDA support. Visit PyTorch's official website to get the exact
pipcommand for your system and CUDA version (e.g.,pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118).
- For GPU support: If you have an NVIDIA GPU, ensure you install PyTorch with CUDA support. Visit PyTorch's official website to get the exact
Usage
-
Place your documents: Put all the documents you want to organize into a single folder.
-
Run the script: Navigate to the
srcdirectory (or the directory containingmain_organizer.py) in your terminal and run the script.python main_organizer.py <path_to_your_documents_folder> [OPTIONS]Example (Dry Run):
python main_organizer.py /path/to/my/documents --dry-runThis will show you a tree-like structure of how your files would be organized without making any changes.
Example (Live Run with PDF filter):
python main_organizer.py /path/to/my/documents --filter-regex ".*\.pdf$"This will classify and move only
.pdffiles.
Command-Line Arguments
-
<target_folder>(positional argument): The full path to the folder containing your documents. This is a mandatory argument. -
--dry-run: (Optional flag) If present, the script will only print the proposed organization structure and not move any files or create any folders. This is highly recommended for a first run. -
--filter-regex <pattern>: (Optional argument) Provide a regular expression pattern to filter the filenames. Only files matching this regex will be processed. For example,".*\\.txt$"to process only text files.
Configuration
You can customize the behavior of the organizer by modifying the following constants at the top of main_organizer.py:
-
CANDIDATE_LABELS: A list of strings representing the categories you want your documents to be organized into. Be as specific or general as needed for your collection. -
MODEL_NAME: The name of the Hugging Face model used for zero-shot classification.facebook/bart-large-mnliis a good general-purpose model. -
MIN_CONFIDENCE_THRESHOLD: A float between 0.0 and 1.0. If the model's confidence for the top predicted category is below this threshold, the document will be moved to the_Needs Manual Review_folder. -
NEEDS_REVIEW_FOLDER_NAME: The name of the folder where documents with low confidence or processing errors will be placed. -
HYPOTHESIS_TEMPLATE: The template string used to frame the classification query to the model. Changing this (e.g., to "This book is about {}." or "The subject of this paper is {}." ) might influence classification accuracy.
How it Works
-
Initialization: Loads the specified Hugging Face zero-shot classification model. It attempts to detect and utilize a CUDA-enabled GPU for faster processing.
-
Planning Phase (
plan_book_organization):-
Scans the
target_folderfor files (optionally filtered by a regex). -
For each file, it extracts a cleaned title (removing extensions, ISBNs, etc.).
-
It then uses the zero-shot classification model to determine the most likely category from your
CANDIDATE_LABELSbased on the cleaned title. -
If the confidence score for the top category is below
MIN_CONFIDENCE_THRESHOLD, the file is assigned to the_Needs Manual Review_category. -
This phase builds an in-memory dictionary representing the proposed final organization (
{category: [filenames]}).
-
-
Execution Phase (
_execute_dry_run_organizationor_execute_live_run_organization):-
Dry Run: Prints the
planned_organizationdictionary in a clear, tree-like format, showing where each file would go. No file system changes are made. -
Live Run: Creates the necessary category folders (if they don't exist) and then moves each file to its designated category folder. It includes checks to prevent overwriting existing files.
-
Contributing
Feel free to fork this repository, open issues, or submit pull requests to improve the script.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_document_organizer-0.0.1.tar.gz.
File metadata
- Download URL: ai_document_organizer-0.0.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85a420529a54f514919c29b397a443bef3f5cc1db36887ff30248bf456166e7d
|
|
| MD5 |
df64a8f95c3fc61b1aa895c639357b72
|
|
| BLAKE2b-256 |
194b0619e7812e504a537a46e99b8a375686c95b82ccf7e9c15f516dd5a08d31
|
Provenance
The following attestation bundles were made for ai_document_organizer-0.0.1.tar.gz:
Publisher:
python-publish.yml on vyaslav/ai-document-organizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_document_organizer-0.0.1.tar.gz -
Subject digest:
85a420529a54f514919c29b397a443bef3f5cc1db36887ff30248bf456166e7d - Sigstore transparency entry: 219766530
- Sigstore integration time:
-
Permalink:
vyaslav/ai-document-organizer@fe4416250f91a85c4e1e495598b807147b823479 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/vyaslav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fe4416250f91a85c4e1e495598b807147b823479 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ai_document_organizer-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ai_document_organizer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f45ec71976c2c3bd234756b5294f914147de4ecb9a18b49c7bd75d5353156c4d
|
|
| MD5 |
dd51ca62d9e00d37e4037549e533f144
|
|
| BLAKE2b-256 |
d42a82bb2b94912fa2058bedb4ca61db94d36b756442efe887e1135c35a2b662
|
Provenance
The following attestation bundles were made for ai_document_organizer-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on vyaslav/ai-document-organizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_document_organizer-0.0.1-py3-none-any.whl -
Subject digest:
f45ec71976c2c3bd234756b5294f914147de4ecb9a18b49c7bd75d5353156c4d - Sigstore transparency entry: 219766531
- Sigstore integration time:
-
Permalink:
vyaslav/ai-document-organizer@fe4416250f91a85c4e1e495598b807147b823479 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/vyaslav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fe4416250f91a85c4e1e495598b807147b823479 -
Trigger Event:
release
-
Statement type: