AI-Powered Document Translation with GUI and Local LLMs – Python, PySide6, LangChain, Olama

Automated, accurate, and user-friendly document translation is a key requirement for individuals and organizations working with multilingual content. This project delivers a desktop AI translation tool with a graphical user interface, built for reliability, transparency, and efficiency. Leveraging modern Python technologies, PySide6, and local LLMs via LangChain, the software provides high-quality translations of documents while giving users full control over the process.

Modern Python Architecture and GUI

The tool is implemented in Python 3, with a clean separation between the UI, worker logic, models, and utility modules to ensure maintainability. PySide6 (Qt for Python) handles all GUI components, including windows, dialogs, and widgets. Threading is managed with QThread/QObject and Signal/Slot, allowing safe communication between background translation processes and the interface. QSettings ensures user preferences and application settings persist between sessions.

Document Translation Workflow

At the core of the application is an LLM-powered translation engine:

  • Supported Formats: PDF, TXT, and FB2 (FictionBook 2.0 XML).
  • Chunked Processing: Large documents are split into token-sized chunks using tiktoken, translated individually, and then reassembled.
  • Local LLM Backend: Integrates Ollama LLMs via LangChain, providing fast, private, and cost-effective translations.
  • Language Detection & Validation: Uses langid and langcodes to ensure translations match the target language and maintain quality.
  • Translation Caching: SQLite with SQLAlchemy stores translation progress and results, allowing interrupted sessions to resume without loss.

User Interface and Interaction

The GUI provides:

  • File Selection & Configuration: Choose input/output files and translation settings.
  • Real-Time Progress & Logging: Displays color-coded logs with timestamps, including status updates for each document chunk.
  • Safe Abort & Cleanup: Users can pause or terminate translations safely, with automatic cache management and resource cleanup.
  • Settings Persistence: All user preferences, including LLM configuration, target language, and output format, are remembered between sessions.

Output Capabilities

Translated documents can be saved in multiple formats:

  • Plain Text – simple and portable.
  • PDF – Unicode-compatible, leveraging ReportLab for font management and formatting.
  • FB2 – retains FictionBook 2.0 structure for eBooks.

Performance and Reliability Enhancements

  • xxhash ensures fast hashing of input files for cache management.
  • Modular codebase with custom text extraction modules for PDFs and FB2 ensures accurate parsing.
  • Threaded background processing keeps the UI responsive during long translation tasks.

Conclusion

This AI-powered document translation tool combines modern Python architecture, local LLM integration, and a user-friendly GUI to provide automated, high-quality translations for various document types. With chunked processing, real-time progress tracking, translation caching, and robust error handling, it offers a reliable solution for users needing efficient multilingual document management.