rocktranslate 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. rocktranslate-1.0.0/LICENSE +21 -0
  2. rocktranslate-1.0.0/PKG-INFO +328 -0
  3. rocktranslate-1.0.0/README.md +299 -0
  4. rocktranslate-1.0.0/pyproject.toml +44 -0
  5. rocktranslate-1.0.0/setup.cfg +4 -0
  6. rocktranslate-1.0.0/setup.py +54 -0
  7. rocktranslate-1.0.0/src/rocktranslate/__init__.py +15 -0
  8. rocktranslate-1.0.0/src/rocktranslate/api.py +286 -0
  9. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/browser_tests.py +107 -0
  10. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/old/test.py +24 -0
  11. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/test.py +128 -0
  12. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/test_local_browser.py +37 -0
  13. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/test_output.py +90 -0
  14. rocktranslate-1.0.0/src/rocktranslate/assets/pdf2htmlEX/test/test_remote_browser.py +138 -0
  15. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/browser_tests.py +107 -0
  16. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/old/test.py +24 -0
  17. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/test.py +128 -0
  18. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/test_local_browser.py +37 -0
  19. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/test_output.py +90 -0
  20. rocktranslate-1.0.0/src/rocktranslate/assets/pdfjs/test/test_remote_browser.py +138 -0
  21. rocktranslate-1.0.0/src/rocktranslate/cli.py +298 -0
  22. rocktranslate-1.0.0/src/rocktranslate/core/__init__.py +0 -0
  23. rocktranslate-1.0.0/src/rocktranslate/core/api/__init__.py +14 -0
  24. rocktranslate-1.0.0/src/rocktranslate/core/api/config_api.py +283 -0
  25. rocktranslate-1.0.0/src/rocktranslate/core/api/history_api.py +150 -0
  26. rocktranslate-1.0.0/src/rocktranslate/core/api/translation_api.py +788 -0
  27. rocktranslate-1.0.0/src/rocktranslate/core/chunker.py +213 -0
  28. rocktranslate-1.0.0/src/rocktranslate/core/config_manager.py +124 -0
  29. rocktranslate-1.0.0/src/rocktranslate/core/constants.py +419 -0
  30. rocktranslate-1.0.0/src/rocktranslate/core/downloader.py +322 -0
  31. rocktranslate-1.0.0/src/rocktranslate/core/html_transformer.py +821 -0
  32. rocktranslate-1.0.0/src/rocktranslate/core/llm_client.py +322 -0
  33. rocktranslate-1.0.0/src/rocktranslate/core/pdf_metadata.py +135 -0
  34. rocktranslate-1.0.0/src/rocktranslate/core/prompts.py +130 -0
  35. rocktranslate-1.0.0/src/rocktranslate/core/renderer.py +206 -0
  36. rocktranslate-1.0.0/src/rocktranslate/core/web_api.py +90 -0
  37. rocktranslate-1.0.0/src/rocktranslate/web_gui.py +283 -0
  38. rocktranslate-1.0.0/src/rocktranslate.egg-info/PKG-INFO +328 -0
  39. rocktranslate-1.0.0/src/rocktranslate.egg-info/SOURCES.txt +41 -0
  40. rocktranslate-1.0.0/src/rocktranslate.egg-info/dependency_links.txt +1 -0
  41. rocktranslate-1.0.0/src/rocktranslate.egg-info/entry_points.txt +2 -0
  42. rocktranslate-1.0.0/src/rocktranslate.egg-info/requires.txt +11 -0
  43. rocktranslate-1.0.0/src/rocktranslate.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RockTranslate Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,328 @@
1
+ Metadata-Version: 2.4
2
+ Name: rocktranslate
3
+ Version: 1.0.0
4
+ Summary: High-Fidelity AI Layout-Preserved PDF Translator
5
+ Home-page: https://github.com/PerfectWin7777/RockTranslate
6
+ Author: RockTranslate Contributors
7
+ Author-email: wintertony7777@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: beautifulsoup4
16
+ Requires-Dist: lxml
17
+ Requires-Dist: litellm
18
+ Requires-Dist: json-repair
19
+ Requires-Dist: pypdf
20
+ Requires-Dist: loguru
21
+ Requires-Dist: tiktoken
22
+ Provides-Extra: gui
23
+ Requires-Dist: PyQt6>=6.4.0; extra == "gui"
24
+ Requires-Dist: PyQt6-WebEngine>=6.4.0; extra == "gui"
25
+ Dynamic: author-email
26
+ Dynamic: home-page
27
+ Dynamic: license-file
28
+ Dynamic: requires-python
29
+
30
+
31
+ # <img src="src/rocktranslate/assets/rocktranslate_icon.png" width="48" align="center" alt="RockTranslate Icon" /> RockTranslate
32
+
33
+ <p align="center">
34
+ <img src="src/rocktranslate/assets/RockTranslate_logo.png" width="480" alt="RockTranslate Logo" />
35
+ </p>
36
+
37
+ <p align="center">
38
+ <strong>High-Fidelity AI Layout-Preserved PDF Translator</strong>
39
+ </p>
40
+
41
+ <p align="center">
42
+ <!-- High-visibility dynamic download badge -->
43
+ <a href="https://github.com/PerfectWin7777/RockTranslate/releases/download/v1.0.0/RockTranslate_Setup_v1.0.0.exe">
44
+ <img src="https://img.shields.io/badge/Download-Windows%20GUI%20Installer-blue?style=for-the-badge&logo=windows&logoColor=white" alt="Download Windows GUI Installer" />
45
+ </a>
46
+ </p>
47
+
48
+ <p align="center">
49
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License" />
50
+ <img src="https://img.shields.io/badge/Python-3.9+-green.svg" alt="Python 3.9+" />
51
+ <img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg" alt="Supported Platforms" />
52
+ </p>
53
+
54
+ ---
55
+
56
+ ### πŸ“₯ [Click here to download the standalone Windows Desktop GUI Installer (.exe)](https://github.com/PerfectWin7777/RockTranslate/releases/tag/v1.0.0-beta/RockTranslate_Setup_v1.0.0.exe)
57
+
58
+ ---
59
+
60
+ ## 1. Introduction & Origin Story
61
+
62
+ > *"RockTranslate breaks the limits of traditional PDF translation. By combining advanced LLMs with high-fidelity geometric DOM mapping, it reconstructs complex scientific papers from publishers like Elsevier and Springer into completely native, translated PDFs."*
63
+
64
+ ### Our Story: Bridging the Academic Inequality Gap
65
+
66
+ Scientific and academic research is a global endeavor, yet the vast majority of high-impact literature is published in English. For students and researchers in developing nations, particularly in Africa and Cameroon, accessing, translating, and fully understanding these highly complex documents poses a massive challenge [1].
67
+
68
+ Traditional translation tools are either:
69
+ 1. **Prohibitively expensive** or heavily restricted by paid subscription tiers (e.g., DeepL, Google Translate).
70
+ 2. **Lacking visual layout preservation** (e.g., standard text extractors, legacy translation proxies), rendering complex formulas, double-column structures, and tables completely unreadable [2].
71
+
72
+ **RockTranslate** was born out of academic necessity, created by students facing these exact barriers. It is designed to be a fully accessible, local-first, high-fidelity alternative that allows any researcher, anywhere, to translate academic PDFs without losing their original layoutβ€”empowering global education without financial borders [1].
73
+
74
+ ---
75
+
76
+ ## 2. Key Features
77
+
78
+ RockTranslate is a desktop application designed for translating scientific, technical, and academic PDF documents while preserving their original structure, formatting, figures, tables, and visual layout.
79
+
80
+ Built with a local-first architecture, RockTranslate prioritizes performance, reliability, and user control. The application combines advanced document analysis, intelligent translation workflows, and high-fidelity PDF reconstruction to deliver professional-quality results.
81
+
82
+ * **Layout-Preserved PDF Translation:** Retains the exact geometry, columns, margins, and alignment of the original document [2].
83
+ * **Scientific and Technical Document Support:** Specially designed to handle mathematical formulas, indices, equations, and proper academic nomenclature.
84
+ * **High-Fidelity PDF Reconstruction:** Preserves figures, images, and tables in their original spatial coordinates.
85
+ * **Fast Desktop Performance:** Employs parallel and asynchronous processing to deliver translations without blocking user interfaces [1].
86
+ * **Lightweight and Responsive User Experience:** Optimized loading speeds and visual feedback indicators.
87
+ * **Privacy-Conscious Workflow:** Supports offline and local-first execution via local LLMs (Ollama) to guarantee complete data privacy.
88
+ * **Open-Source and Community-Driven:** Built entirely on open-source foundations, giving control back to the scientific community.
89
+
90
+ ---
91
+
92
+
93
+ ## 3. Installation
94
+
95
+ Choose the installation method that best suits your requirements:
96
+
97
+ ### A. Package Installation (via pip)
98
+ Once published on PyPI, you can install the latest stable version of RockTranslate directly:
99
+ ```bash
100
+ pip install rocktranslate
101
+ ```
102
+
103
+ ### B. Development Installation (via Git)
104
+ For the most up-to-date features, or to run the application directly from source:
105
+ ```bash
106
+ # Clone the repository
107
+ git clone https://github.com/PerfectWin7777/RockTranslate.git
108
+ cd RockTranslate
109
+
110
+ # Install dependencies and the package in editable mode
111
+ pip install -e .
112
+ ```
113
+
114
+ ### C. Direct Remote Install
115
+ You can also install the development version directly from GitHub without cloning the repository manually:
116
+ ```bash
117
+ pip install git+https://github.com/PerfectWin7777/RockTranslate.git
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 4. Visual Demonstration (Before & After)
123
+
124
+ ### Real-Time Application Lifecycle
125
+ *The following animation demonstrates opening, rendering, and translating a multi-column paper dynamically:*
126
+
127
+ <p align="center">
128
+ <img src=".github/assets/readme_animation.gif" width="800" alt="RockTranslate Application Demo" />
129
+ </p>
130
+
131
+ ---
132
+
133
+ ### πŸ”¬ 1. English to Spanish (Elsevier Double-Column Layout)
134
+ *Demonstrating perfect preservation of multi-column text flow, publisher headers, and author blocks.*
135
+
136
+ ![English to Spanish Comparison](.github/assets/readme_comparison_en_to_spa.png)
137
+
138
+ *The original Elsevier double-column layout is fully retained with zero text-overlapping or margin drift.*
139
+
140
+ ---
141
+
142
+ ### 🧠 2. English to French (Attention Is All You Need β€” Abstract & Title)
143
+ *Demonstrating precise preservation of scientific structures, titles, and mathematical equations.*
144
+
145
+ ![English to French Comparison](.github/assets/readme_comparison_en_to_fr.png)
146
+
147
+ *Mathematical formulas, paragraph flows, and proper academic register remain completely intact.*
148
+
149
+ ---
150
+
151
+ ### 🌸 3. English to Japanese (Attention Is All You Need β€” Paragraph Flow)
152
+ *Demonstrating robust handling of double-byte CJK characters without vertical line collapses or overlapping.*
153
+
154
+ ![English to Japanese Comparison](.github/assets/readme_comparison_en_to_jn.png)
155
+
156
+ *Japanese Kanji and Kana characters are rendered cleanly with proportional horizontal scaling.*
157
+
158
+ ---
159
+
160
+ ### 🌸 4. English to German (Elsevier Double-Column Layoutβ€” Paragraph Flow and Table)
161
+ *Demonstrating robust preservation of tables and math formulas in a double-column layout..*
162
+
163
+ ![English to German Comparison](.github/assets/readme_comparison_en_to_ge.png)
164
+
165
+ *Clarity of paragraphs, tables and styles, preservation of mathematical formulas.*
166
+
167
+ ---
168
+
169
+ ## 5. The Three Versions
170
+
171
+ RockTranslate provides three entry points to support any workflow:
172
+
173
+ ### A. Graphical User Interface (GUI)
174
+ A responsive desktop application featuring:
175
+ * Synchronized dual-pane viewports (Original PDF vs. Live Translated HTML) [2].
176
+ * Real-time zoom sliders and page navigation.
177
+ * Visual shimmer skeleton loaders and real-time status bars [1, 2].
178
+
179
+ ### πŸ“₯ [Click here to download the standalone Windows Desktop GUI Installer (.exe)](https://github.com/PerfectWin7777/RockTranslate/releases/tag/v1.0.0-beta/RockTranslate_Setup_v1.0.0.exe)
180
+
181
+ ### B. Command-Line Interface (CLI)
182
+ A lightweight execution engine that can be run globally from the terminal once installed [3].
183
+
184
+ #### Usage Examples:
185
+ 1. **Translate to French (default) using the default Gemini model:**
186
+ ```bash
187
+ rocktranslate article_scientifique.pdf -l French
188
+ ```
189
+ 2. **Translate to Spanish and save to a custom output file:**
190
+ ```bash
191
+ rocktranslate paper.pdf -l Spanish -o report_es.pdf
192
+ ```
193
+ 3. **Translate to German using OpenAI with an explicit API key:**
194
+ ```bash
195
+ rocktranslate document.pdf -m openai/gpt-4o-mini -k YOUR_OPENAI_KEY -l German
196
+ ```
197
+ 4. **Run fully local translation using Ollama (no API key required):**
198
+ ```bash
199
+ rocktranslate document.pdf -m ollama/llama3 -l French
200
+ ```
201
+
202
+ ---
203
+
204
+ ### πŸ’‘ Dynamic Model Routing & Frontier Models Guidance
205
+
206
+ #### 1. Model Naming Convention (LiteLLM Integration)
207
+ RockTranslate inherits its entire model routing architecture directly from **LiteLLM**. All model identifiers passed through the `-m / --model` CLI flag (or through the API) must strictly follow the standard `provider/model_name` syntax.
208
+
209
+ Both the provider prefix and the model name must match the exact naming conventions defined in the [LiteLLM Supported Providers & Models Documentation](https://docs.litellm.ai/docs/providers).
210
+
211
+ #### 2. Why Frontier Models are Essential for Perfect Visual Layouts
212
+ While local or lightweight models function perfectly, we highly recommend using advanced **frontier models**β€”such as **Gemini 3.5 Flash**, **GPT 5.5**, **Claude 4.X**, **DeepSeek V4**, **Kimi K2.6**, or **GLM 5.5 ; Any other open-source LLM provider**β€”for complex scientific papers.
213
+
214
+ * **Instruction-Following & Tag Integrity:** Frontier models possess superior reasoning capabilities. They strictly preserve nested XML style tags (like `<color_HEX>`) and structural JSON mapping arrays, allowing the renderer to position text segments with pixel-perfect accuracy.
215
+ * **Academic Register & Context:** They avoid literal, broken word-by-word translations of fragmented segments. Instead, they understand the global paragraph context, translating complex double-column academic layouts into natural scientific prose.
216
+
217
+
218
+ ### C. API Developer Library
219
+ Integrate layout-preserved document translation directly into your Python scripts or data pipelines.
220
+
221
+ #### Programmatic Integration Scenarios:
222
+ ```python
223
+ import os
224
+ from rocktranslate import RockTranslator
225
+
226
+ # Ensure a sample file is present before initiating diagnostic runs
227
+ sample_pdf = "article_scientifique.pdf"
228
+
229
+ if not os.path.exists(sample_pdf):
230
+ print(f"Sample file '{sample_pdf}' not found. Please provide a valid PDF.")
231
+ else:
232
+ # ──────────────────────────────────────────────────────────────────────
233
+ # SCENARIO 1: Basic Translation (Using Google Gemini with environment key)
234
+ # ──────────────────────────────────────────────────────────────────────
235
+ # Automatically searches for GEMINI_API_KEY inside system environment variables.
236
+ # Uses the advanced Gemini 3.5 Flash model for superior layout preservation.
237
+ translator_gemini = RockTranslator(
238
+ model="gemini/gemini-3.5-flash",
239
+ target_lang="Spanish"
240
+ )
241
+
242
+ # Executes translation, saving the file to '[article_scientifique]_translated.pdf'
243
+ success_gemini = translator_gemini.translate(input_pdf_path=sample_pdf)
244
+ print(f"Scenario 1 complete. Success: {success_gemini}")
245
+
246
+ # ──────────────────────────────────────────────────────────────────────
247
+ # SCENARIO 2: Custom Output Path and Language Customization
248
+ # ──────────────────────────────────────────────────────────────────────
249
+ translator_custom = RockTranslator(
250
+ model="gemini/gemini-3.5-flash",
251
+ target_lang="German"
252
+ )
253
+
254
+ # Translates to German and writes output to a custom specified path
255
+ custom_output = "results/german_report.pdf"
256
+ os.makedirs("results", exist_ok=True)
257
+
258
+ success_custom = translator_custom.translate(
259
+ input_pdf_path=sample_pdf,
260
+ output_pdf_path=custom_output
261
+ )
262
+ print(f"Scenario 2 complete. Translated PDF written to: {custom_output} (Success: {success_custom})")
263
+
264
+ # ──────────────────────────────────────────────────────────────────────
265
+ # SCENARIO 3: Frontier Provider (OpenAI GPT 5.5) with Explicit API Key
266
+ # ──────────────────────────────────────────────────────────────────────
267
+ # Explicit credentials pass overrides local environment configurations.
268
+ # We route the request using the exact LiteLLM naming convention (provider/model_name).
269
+ # Learn more at: https://docs.litellm.ai/docs/providers
270
+ translator_openai = RockTranslator(
271
+ model="openai/gpt-5.5",
272
+ api_key="sk-your-openai-api-key-here", # Replace with a valid credentials key
273
+ target_lang="Italian",
274
+ temperature=0.3 # Lower temperature for more rigid, literal academic translation
275
+ )
276
+
277
+ # success_openai = translator_openai.translate(input_pdf_path=sample_pdf)
278
+ print("Scenario 3 configured. (Run skipped to avoid credential errors.)")
279
+
280
+ # ──────────────────────────────────────────────────────────────────────
281
+ # SCENARIO 4: Fully Local and Offline Translation (Using Ollama)
282
+ # ──────────────────────────────────────────────────────────────────────
283
+ # No API keys or remote servers required. Ensure Ollama is running on the host machine.
284
+ translator_local = RockTranslator(
285
+ model="ollama/llama3",
286
+ target_lang="French",
287
+ custom_base_url="http://localhost:11434" # Default local Ollama gateway port
288
+ )
289
+
290
+ # success_local = translator_local.translate(input_pdf_path=sample_pdf)
291
+ print("Scenario 4 configured for local offline execution.")
292
+ ```
293
+
294
+ ---
295
+
296
+ ## 6. Known Limitations & Roadmap (TODO)
297
+
298
+ ### Current Limitations:
299
+ * **The LaTeX FontForge Crash (Windows):** Older standalone versions of `pdf2htmlEX` on Windows occasionally experience segmentation faults or infinite loops when compiling complex, customized LaTeX mathematical fonts (Type-1 vector fonts) [2.2.6].
300
+ * *Our Solution:* We have implemented a robust Windows crash preventer (`SetErrorMode`) and a strict 30-second subprocess timeout. If a compilation hangs, RockTranslate instantly terminates the process and fails gracefully in under 50ms without freezing the UI [1].
301
+
302
+ ### Roadmap & Future TODOs:
303
+ * [ ] **PyQt6 / QWebEngine Migration:** Migrate the Desktop GUI away from PyQt6 and heavy Chromium-based `QWebEngine` wrappers, transitioning towards a lightweight native webview (e.g., `pywebview`). This will reduce the compiled `.exe` bundle size from ~150MB down to under 20MB.
304
+ * [ ] **Automatic Fallback to Serverless Cloud Conversion:** Integrate an optional, free, or self-hosted serverless cloud rendering API (using the official Docker Linux image) to handle complex LaTeX papers without any local system limitations [1, 2].
305
+ * [ ] **Concurrent Batch Translation:** Implement parallel API calls (limited to 3 concurrent requests to respect free-tier quotas) to speed up translation times by 3x [1].
306
+
307
+ ---
308
+
309
+ ## 7. Contributing & Community Support
310
+
311
+ We believe in making scientific literature universally accessible and welcome contributions from researchers, developers, and educators. Here is how you can help advance the project:
312
+
313
+ * **Core UI Refactoring:** Help us migrate from the resource-intensive PyQt6/QWebEngine setup to a lightweight `pywebview` client.
314
+ * **Bug Reports & Edge Cases:** Found a PDF with highly complex LaTeX layout issues? Open an issue and upload the file (or a sample page) so we can optimize our BeautifulSoup parser rules.
315
+ * **Translation & Localization:** Contribute internationalization files (`.qm`/`.ts` translations) to make the user interface available in more languages.
316
+ * **Prompt Optimization:** Help us refine the instructions in `prompts.py` to further improve terminology preservation and tag alignment across different languages.
317
+
318
+ To contribute, please fork the repository, make your changes in a dedicated branch, and submit a pull request. For major architectural modifications, feel free to open an issue first to discuss your ideas with the core maintainers.
319
+
320
+ ---
321
+
322
+ ## 8. Acknowledgements & Credits
323
+
324
+ RockTranslate stands on the shoulders of giants. We would like to express our deepest gratitude to the open-source projects that made this tool possible:
325
+ * **pdf2htmlEX:** The geometric engine used to compile PDF structures into HTML [2.2.1] ([GitHub](https://github.com/pdf2htmlEX/pdf2htmlEX)).
326
+ * **Poppler & FontForge:** The underlying vector engines driving pdf2htmlEX [3.2.4] ([Poppler Website](https://poppler.freedesktop.org/) | [FontForge Website](https://fontforge.org/)).
327
+ * **LiteLLM:** The multi-provider AI routing wrapper [2.3.1] ([Official Documentation](https://docs.litellm.ai/)).
328
+ * **BeautifulSoup4 & lxml:** Driving high-speed, programmatic DOM analysis ([BeautifulSoup Documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) | [lxml Website](https://lxml.de/)).
@@ -0,0 +1,299 @@
1
+
2
+ # <img src="src/rocktranslate/assets/rocktranslate_icon.png" width="48" align="center" alt="RockTranslate Icon" /> RockTranslate
3
+
4
+ <p align="center">
5
+ <img src="src/rocktranslate/assets/RockTranslate_logo.png" width="480" alt="RockTranslate Logo" />
6
+ </p>
7
+
8
+ <p align="center">
9
+ <strong>High-Fidelity AI Layout-Preserved PDF Translator</strong>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <!-- High-visibility dynamic download badge -->
14
+ <a href="https://github.com/PerfectWin7777/RockTranslate/releases/download/v1.0.0/RockTranslate_Setup_v1.0.0.exe">
15
+ <img src="https://img.shields.io/badge/Download-Windows%20GUI%20Installer-blue?style=for-the-badge&logo=windows&logoColor=white" alt="Download Windows GUI Installer" />
16
+ </a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License" />
21
+ <img src="https://img.shields.io/badge/Python-3.9+-green.svg" alt="Python 3.9+" />
22
+ <img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg" alt="Supported Platforms" />
23
+ </p>
24
+
25
+ ---
26
+
27
+ ### πŸ“₯ [Click here to download the standalone Windows Desktop GUI Installer (.exe)](https://github.com/PerfectWin7777/RockTranslate/releases/tag/v1.0.0-beta/RockTranslate_Setup_v1.0.0.exe)
28
+
29
+ ---
30
+
31
+ ## 1. Introduction & Origin Story
32
+
33
+ > *"RockTranslate breaks the limits of traditional PDF translation. By combining advanced LLMs with high-fidelity geometric DOM mapping, it reconstructs complex scientific papers from publishers like Elsevier and Springer into completely native, translated PDFs."*
34
+
35
+ ### Our Story: Bridging the Academic Inequality Gap
36
+
37
+ Scientific and academic research is a global endeavor, yet the vast majority of high-impact literature is published in English. For students and researchers in developing nations, particularly in Africa and Cameroon, accessing, translating, and fully understanding these highly complex documents poses a massive challenge [1].
38
+
39
+ Traditional translation tools are either:
40
+ 1. **Prohibitively expensive** or heavily restricted by paid subscription tiers (e.g., DeepL, Google Translate).
41
+ 2. **Lacking visual layout preservation** (e.g., standard text extractors, legacy translation proxies), rendering complex formulas, double-column structures, and tables completely unreadable [2].
42
+
43
+ **RockTranslate** was born out of academic necessity, created by students facing these exact barriers. It is designed to be a fully accessible, local-first, high-fidelity alternative that allows any researcher, anywhere, to translate academic PDFs without losing their original layoutβ€”empowering global education without financial borders [1].
44
+
45
+ ---
46
+
47
+ ## 2. Key Features
48
+
49
+ RockTranslate is a desktop application designed for translating scientific, technical, and academic PDF documents while preserving their original structure, formatting, figures, tables, and visual layout.
50
+
51
+ Built with a local-first architecture, RockTranslate prioritizes performance, reliability, and user control. The application combines advanced document analysis, intelligent translation workflows, and high-fidelity PDF reconstruction to deliver professional-quality results.
52
+
53
+ * **Layout-Preserved PDF Translation:** Retains the exact geometry, columns, margins, and alignment of the original document [2].
54
+ * **Scientific and Technical Document Support:** Specially designed to handle mathematical formulas, indices, equations, and proper academic nomenclature.
55
+ * **High-Fidelity PDF Reconstruction:** Preserves figures, images, and tables in their original spatial coordinates.
56
+ * **Fast Desktop Performance:** Employs parallel and asynchronous processing to deliver translations without blocking user interfaces [1].
57
+ * **Lightweight and Responsive User Experience:** Optimized loading speeds and visual feedback indicators.
58
+ * **Privacy-Conscious Workflow:** Supports offline and local-first execution via local LLMs (Ollama) to guarantee complete data privacy.
59
+ * **Open-Source and Community-Driven:** Built entirely on open-source foundations, giving control back to the scientific community.
60
+
61
+ ---
62
+
63
+
64
+ ## 3. Installation
65
+
66
+ Choose the installation method that best suits your requirements:
67
+
68
+ ### A. Package Installation (via pip)
69
+ Once published on PyPI, you can install the latest stable version of RockTranslate directly:
70
+ ```bash
71
+ pip install rocktranslate
72
+ ```
73
+
74
+ ### B. Development Installation (via Git)
75
+ For the most up-to-date features, or to run the application directly from source:
76
+ ```bash
77
+ # Clone the repository
78
+ git clone https://github.com/PerfectWin7777/RockTranslate.git
79
+ cd RockTranslate
80
+
81
+ # Install dependencies and the package in editable mode
82
+ pip install -e .
83
+ ```
84
+
85
+ ### C. Direct Remote Install
86
+ You can also install the development version directly from GitHub without cloning the repository manually:
87
+ ```bash
88
+ pip install git+https://github.com/PerfectWin7777/RockTranslate.git
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 4. Visual Demonstration (Before & After)
94
+
95
+ ### Real-Time Application Lifecycle
96
+ *The following animation demonstrates opening, rendering, and translating a multi-column paper dynamically:*
97
+
98
+ <p align="center">
99
+ <img src=".github/assets/readme_animation.gif" width="800" alt="RockTranslate Application Demo" />
100
+ </p>
101
+
102
+ ---
103
+
104
+ ### πŸ”¬ 1. English to Spanish (Elsevier Double-Column Layout)
105
+ *Demonstrating perfect preservation of multi-column text flow, publisher headers, and author blocks.*
106
+
107
+ ![English to Spanish Comparison](.github/assets/readme_comparison_en_to_spa.png)
108
+
109
+ *The original Elsevier double-column layout is fully retained with zero text-overlapping or margin drift.*
110
+
111
+ ---
112
+
113
+ ### 🧠 2. English to French (Attention Is All You Need β€” Abstract & Title)
114
+ *Demonstrating precise preservation of scientific structures, titles, and mathematical equations.*
115
+
116
+ ![English to French Comparison](.github/assets/readme_comparison_en_to_fr.png)
117
+
118
+ *Mathematical formulas, paragraph flows, and proper academic register remain completely intact.*
119
+
120
+ ---
121
+
122
+ ### 🌸 3. English to Japanese (Attention Is All You Need β€” Paragraph Flow)
123
+ *Demonstrating robust handling of double-byte CJK characters without vertical line collapses or overlapping.*
124
+
125
+ ![English to Japanese Comparison](.github/assets/readme_comparison_en_to_jn.png)
126
+
127
+ *Japanese Kanji and Kana characters are rendered cleanly with proportional horizontal scaling.*
128
+
129
+ ---
130
+
131
+ ### 🌸 4. English to German (Elsevier Double-Column Layoutβ€” Paragraph Flow and Table)
132
+ *Demonstrating robust preservation of tables and math formulas in a double-column layout..*
133
+
134
+ ![English to German Comparison](.github/assets/readme_comparison_en_to_ge.png)
135
+
136
+ *Clarity of paragraphs, tables and styles, preservation of mathematical formulas.*
137
+
138
+ ---
139
+
140
+ ## 5. The Three Versions
141
+
142
+ RockTranslate provides three entry points to support any workflow:
143
+
144
+ ### A. Graphical User Interface (GUI)
145
+ A responsive desktop application featuring:
146
+ * Synchronized dual-pane viewports (Original PDF vs. Live Translated HTML) [2].
147
+ * Real-time zoom sliders and page navigation.
148
+ * Visual shimmer skeleton loaders and real-time status bars [1, 2].
149
+
150
+ ### πŸ“₯ [Click here to download the standalone Windows Desktop GUI Installer (.exe)](https://github.com/PerfectWin7777/RockTranslate/releases/tag/v1.0.0-beta/RockTranslate_Setup_v1.0.0.exe)
151
+
152
+ ### B. Command-Line Interface (CLI)
153
+ A lightweight execution engine that can be run globally from the terminal once installed [3].
154
+
155
+ #### Usage Examples:
156
+ 1. **Translate to French (default) using the default Gemini model:**
157
+ ```bash
158
+ rocktranslate article_scientifique.pdf -l French
159
+ ```
160
+ 2. **Translate to Spanish and save to a custom output file:**
161
+ ```bash
162
+ rocktranslate paper.pdf -l Spanish -o report_es.pdf
163
+ ```
164
+ 3. **Translate to German using OpenAI with an explicit API key:**
165
+ ```bash
166
+ rocktranslate document.pdf -m openai/gpt-4o-mini -k YOUR_OPENAI_KEY -l German
167
+ ```
168
+ 4. **Run fully local translation using Ollama (no API key required):**
169
+ ```bash
170
+ rocktranslate document.pdf -m ollama/llama3 -l French
171
+ ```
172
+
173
+ ---
174
+
175
+ ### πŸ’‘ Dynamic Model Routing & Frontier Models Guidance
176
+
177
+ #### 1. Model Naming Convention (LiteLLM Integration)
178
+ RockTranslate inherits its entire model routing architecture directly from **LiteLLM**. All model identifiers passed through the `-m / --model` CLI flag (or through the API) must strictly follow the standard `provider/model_name` syntax.
179
+
180
+ Both the provider prefix and the model name must match the exact naming conventions defined in the [LiteLLM Supported Providers & Models Documentation](https://docs.litellm.ai/docs/providers).
181
+
182
+ #### 2. Why Frontier Models are Essential for Perfect Visual Layouts
183
+ While local or lightweight models function perfectly, we highly recommend using advanced **frontier models**β€”such as **Gemini 3.5 Flash**, **GPT 5.5**, **Claude 4.X**, **DeepSeek V4**, **Kimi K2.6**, or **GLM 5.5 ; Any other open-source LLM provider**β€”for complex scientific papers.
184
+
185
+ * **Instruction-Following & Tag Integrity:** Frontier models possess superior reasoning capabilities. They strictly preserve nested XML style tags (like `<color_HEX>`) and structural JSON mapping arrays, allowing the renderer to position text segments with pixel-perfect accuracy.
186
+ * **Academic Register & Context:** They avoid literal, broken word-by-word translations of fragmented segments. Instead, they understand the global paragraph context, translating complex double-column academic layouts into natural scientific prose.
187
+
188
+
189
+ ### C. API Developer Library
190
+ Integrate layout-preserved document translation directly into your Python scripts or data pipelines.
191
+
192
+ #### Programmatic Integration Scenarios:
193
+ ```python
194
+ import os
195
+ from rocktranslate import RockTranslator
196
+
197
+ # Ensure a sample file is present before initiating diagnostic runs
198
+ sample_pdf = "article_scientifique.pdf"
199
+
200
+ if not os.path.exists(sample_pdf):
201
+ print(f"Sample file '{sample_pdf}' not found. Please provide a valid PDF.")
202
+ else:
203
+ # ──────────────────────────────────────────────────────────────────────
204
+ # SCENARIO 1: Basic Translation (Using Google Gemini with environment key)
205
+ # ──────────────────────────────────────────────────────────────────────
206
+ # Automatically searches for GEMINI_API_KEY inside system environment variables.
207
+ # Uses the advanced Gemini 3.5 Flash model for superior layout preservation.
208
+ translator_gemini = RockTranslator(
209
+ model="gemini/gemini-3.5-flash",
210
+ target_lang="Spanish"
211
+ )
212
+
213
+ # Executes translation, saving the file to '[article_scientifique]_translated.pdf'
214
+ success_gemini = translator_gemini.translate(input_pdf_path=sample_pdf)
215
+ print(f"Scenario 1 complete. Success: {success_gemini}")
216
+
217
+ # ──────────────────────────────────────────────────────────────────────
218
+ # SCENARIO 2: Custom Output Path and Language Customization
219
+ # ──────────────────────────────────────────────────────────────────────
220
+ translator_custom = RockTranslator(
221
+ model="gemini/gemini-3.5-flash",
222
+ target_lang="German"
223
+ )
224
+
225
+ # Translates to German and writes output to a custom specified path
226
+ custom_output = "results/german_report.pdf"
227
+ os.makedirs("results", exist_ok=True)
228
+
229
+ success_custom = translator_custom.translate(
230
+ input_pdf_path=sample_pdf,
231
+ output_pdf_path=custom_output
232
+ )
233
+ print(f"Scenario 2 complete. Translated PDF written to: {custom_output} (Success: {success_custom})")
234
+
235
+ # ──────────────────────────────────────────────────────────────────────
236
+ # SCENARIO 3: Frontier Provider (OpenAI GPT 5.5) with Explicit API Key
237
+ # ──────────────────────────────────────────────────────────────────────
238
+ # Explicit credentials pass overrides local environment configurations.
239
+ # We route the request using the exact LiteLLM naming convention (provider/model_name).
240
+ # Learn more at: https://docs.litellm.ai/docs/providers
241
+ translator_openai = RockTranslator(
242
+ model="openai/gpt-5.5",
243
+ api_key="sk-your-openai-api-key-here", # Replace with a valid credentials key
244
+ target_lang="Italian",
245
+ temperature=0.3 # Lower temperature for more rigid, literal academic translation
246
+ )
247
+
248
+ # success_openai = translator_openai.translate(input_pdf_path=sample_pdf)
249
+ print("Scenario 3 configured. (Run skipped to avoid credential errors.)")
250
+
251
+ # ──────────────────────────────────────────────────────────────────────
252
+ # SCENARIO 4: Fully Local and Offline Translation (Using Ollama)
253
+ # ──────────────────────────────────────────────────────────────────────
254
+ # No API keys or remote servers required. Ensure Ollama is running on the host machine.
255
+ translator_local = RockTranslator(
256
+ model="ollama/llama3",
257
+ target_lang="French",
258
+ custom_base_url="http://localhost:11434" # Default local Ollama gateway port
259
+ )
260
+
261
+ # success_local = translator_local.translate(input_pdf_path=sample_pdf)
262
+ print("Scenario 4 configured for local offline execution.")
263
+ ```
264
+
265
+ ---
266
+
267
+ ## 6. Known Limitations & Roadmap (TODO)
268
+
269
+ ### Current Limitations:
270
+ * **The LaTeX FontForge Crash (Windows):** Older standalone versions of `pdf2htmlEX` on Windows occasionally experience segmentation faults or infinite loops when compiling complex, customized LaTeX mathematical fonts (Type-1 vector fonts) [2.2.6].
271
+ * *Our Solution:* We have implemented a robust Windows crash preventer (`SetErrorMode`) and a strict 30-second subprocess timeout. If a compilation hangs, RockTranslate instantly terminates the process and fails gracefully in under 50ms without freezing the UI [1].
272
+
273
+ ### Roadmap & Future TODOs:
274
+ * [ ] **PyQt6 / QWebEngine Migration:** Migrate the Desktop GUI away from PyQt6 and heavy Chromium-based `QWebEngine` wrappers, transitioning towards a lightweight native webview (e.g., `pywebview`). This will reduce the compiled `.exe` bundle size from ~150MB down to under 20MB.
275
+ * [ ] **Automatic Fallback to Serverless Cloud Conversion:** Integrate an optional, free, or self-hosted serverless cloud rendering API (using the official Docker Linux image) to handle complex LaTeX papers without any local system limitations [1, 2].
276
+ * [ ] **Concurrent Batch Translation:** Implement parallel API calls (limited to 3 concurrent requests to respect free-tier quotas) to speed up translation times by 3x [1].
277
+
278
+ ---
279
+
280
+ ## 7. Contributing & Community Support
281
+
282
+ We believe in making scientific literature universally accessible and welcome contributions from researchers, developers, and educators. Here is how you can help advance the project:
283
+
284
+ * **Core UI Refactoring:** Help us migrate from the resource-intensive PyQt6/QWebEngine setup to a lightweight `pywebview` client.
285
+ * **Bug Reports & Edge Cases:** Found a PDF with highly complex LaTeX layout issues? Open an issue and upload the file (or a sample page) so we can optimize our BeautifulSoup parser rules.
286
+ * **Translation & Localization:** Contribute internationalization files (`.qm`/`.ts` translations) to make the user interface available in more languages.
287
+ * **Prompt Optimization:** Help us refine the instructions in `prompts.py` to further improve terminology preservation and tag alignment across different languages.
288
+
289
+ To contribute, please fork the repository, make your changes in a dedicated branch, and submit a pull request. For major architectural modifications, feel free to open an issue first to discuss your ideas with the core maintainers.
290
+
291
+ ---
292
+
293
+ ## 8. Acknowledgements & Credits
294
+
295
+ RockTranslate stands on the shoulders of giants. We would like to express our deepest gratitude to the open-source projects that made this tool possible:
296
+ * **pdf2htmlEX:** The geometric engine used to compile PDF structures into HTML [2.2.1] ([GitHub](https://github.com/pdf2htmlEX/pdf2htmlEX)).
297
+ * **Poppler & FontForge:** The underlying vector engines driving pdf2htmlEX [3.2.4] ([Poppler Website](https://poppler.freedesktop.org/) | [FontForge Website](https://fontforge.org/)).
298
+ * **LiteLLM:** The multi-provider AI routing wrapper [2.3.1] ([Official Documentation](https://docs.litellm.ai/)).
299
+ * **BeautifulSoup4 & lxml:** Driving high-speed, programmatic DOM analysis ([BeautifulSoup Documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) | [lxml Website](https://lxml.de/)).