How hj-lh/arabic-file-renamer works
Project type and purpose
• This is an open-source, command-line Python utility (“AI Arabic File Renamer”) whose goal is to read scanned documents (PDF/PNG/JPG), extract their contents via OCR, generate descriptive Arabic file names using an LLM, and write the renamed files to an output folder.
File structure
• Top-level files:
• Readme.md – project overview, installation and configuration instructions
• requirements.txt – Python dependencies (e.g., pytesseract, pdf2image, ollama-client)
• namer.py – the single Python script orchestrating the pipeline
• No subdirectories; all logic lives in a single module. Configuration is via variables in namer.py.
README for additional insights
• Stack and external dependencies:
• Python 3.6+
• Tesseract OCR (system-installed executable + Arabic trained data)
• Poppler (pdf2image conversion library)
• Ollama LLM (local model server)
• The script’s core function:
query_ollama(prompt) → returns an Arabic file name based on OCR’ed text and a customizable prompt.
a. Main components
1. CLI Launcher (namer.py)
2. Input Folder (scanned files)
3. File Ingestion & Dispatcher (detects file type)
4a. PDF → pdf2image (Poppler) → image pages
4b. Image (PNG/JPG) → direct
5. Preprocessing (optional resizing, grayscale)
6. OCR Engine (Tesseract) → raw text
7. Text Post-processing (cleanup)
8. LLM Service (Ollama API) ← naming prompt + text
9. Renamer Module (applies returned filename)
10. Output Folder (renamed files)
b. Relationships & interactions
• Files flow left to right: Input Folder → Ingestion → (PDF/Image branches) → OCR → LLM → Renamer → Output Folder
• CLI Launcher triggers the pipeline and handles error/reporting.
• OCR Engine and LLM Service are external processes/services invoked by the Python script.
c. Architectural patterns & design principles
• Pipeline pattern: sequential stages, each with a single responsibility.
• Single-source orchestrator (namer.py) coordinating external tools.
• Extensibility points:
• New file types/convertors
• Swap LLM backends or prompts
• Insert preprocessing steps or postprocessing filters
d. Key technologies & libraries
• Python 3.6+
• pytesseract (wrapper for Tesseract CLI)
• pdf2image (Poppler-based PDF→PNG)
• Ollama client or HTTP API for LLM queries
• Standard libs (os, shutil, logging)