How dhanush0959/geminidecode works
1. System shape
- This is a single-service Flask application with a browser UI and a backend translation pipeline.
- The main boundary is between the HTTP layer in app.py and the document-processing engine in translate.py.
2. Request/response entry point
- The web app is served from app.py, with the homepage rendered from templates/index.html.
- Static assets are split into static/js/main.js for UI behavior and static/css/style.css for presentation.
3. User interaction flow
- A user uploads a PDF through the web interface.
- The backend stores the uploaded file under a per-document folder in ./data/.
- The frontend then polls for progress and refreshes the UI while translation runs.
4. Translation pipeline boundary
- translate.py is the core processing subsystem.
- Its job is to take the uploaded PDF, extract page content, call Gemini for transcription/translation, and assemble the final translated document.
- The README describes a multi-stage pipeline: transcription, translation, and compilation.
5. AI and document-processing dependencies
- Google Gemini is the external AI service that performs the language conversion.
- PyMuPDF and Pillow are used for PDF/page extraction and image handling.
- WeasyPrint and python-docx are used to generate output artifacts in multiple formats.
6. Document storage model
- Each translation appears to be isolated in its own directory under data/<document-name>/.
- That directory contains the original PDF, intermediate transcription files, intermediate translation files, and a final translated.md.
- This directory-per-job structure is the main persistence boundary in the app.
7. Output and retrieval paths
- The app exposes endpoints for viewing the translated result in-browser, downloading it in several formats, and accessing the original PDF.
- The supported download targets are Markdown, TXT, DOCX, and PDF.
- This makes the final compiled translation the source artifact, with other formats generated from it.
8. Progress and concurrency model
- The README indicates live progress tracking and concurrent translation of up to 8 pages simultaneously.
- That means translation is not a simple single blocking operation; it is a job-like process with intermediate state exposed to the UI.
- The progress endpoint is a key integration point between backend processing and frontend polling.
9. Operational/runtime boundary
- The project is containerized with Docker and Docker Compose.
- The runtime is Python/Flask, with file-backed persistence mounted via a data volume and logs managed separately.
- This suggests the service is designed to be deployed as one container rather than a distributed system.
10. API surface
- The repository exposes a small HTTP API in addition to the UI: upload, progress, file listing, view, download, original-file access, delete, and health check.
- These endpoints form the control plane around the translation jobs and the file store.
- The health endpoint is the main operational signal for container/platform monitoring.
11. Frontend architecture
- The frontend is intentionally lightweight: server-rendered HTML plus vanilla JavaScript.
- JavaScript likely handles upload interaction, progress polling, preview updates, and deletion/download actions.
- There is no separate frontend framework or SPA boundary here.
12. Deployment and security assumptions
- Configuration is environment-driven, especially the Gemini API key.
- The README notes the app is intended to run behind Cloudflare with Google Authentication, but internal auth is not implemented in the codebase itself.
- For an architecture diagram, treat authentication as an external deployment concern, not an application subsystem.
Main entry points: app.py Flask app · translate.py Translator · index.html Homepage · main.js Main JS
Components 19
Web UI
Server-rendered interface plus browser behavior
- Homepage · Server-rendered entry page for uploads and results
templates/index.html - Main JS · Handles upload actions, polling, previews, and file actions
static/js/main.js - Stylesheet · UI styling for the web interface
static/css/style.css
Backend
Flask routes and translation pipeline
- Flask app · Serves pages and exposes the upload/progress/download API
app.py - Translator · Coordinates document processing from PDF to translated outputs
translate.py - Page extract · Reads PDF pages and prepares page content for processing
translate.py - Gemini pass · Calls Gemini to transcribe and translate page content
translate.py - Compile doc · Merges translated content into the final translated document
translate.py - Format export · Generates Markdown, TXT, DOCX, and PDF artifacts
translate.py - Progress API · Exposes live translation progress for frontend polling
app.py - Download API · Serves translated artifacts in multiple formats and the original PDF
app.py
Job Storage
Per-document file-backed persistence
- Job folder · Per-document directory under data/<name>/ with intermediates and outputs
- Original PDF · Uploaded source document stored with each job
- Translated MD · Canonical translated output used to derive other formats
Runtime
Container and deployment boundary
- Health check · Operational signal for container monitoring
app.py - Docker runtime · Containerized Flask deployment with mounted data volume
Dockerfile - Compose setup · Local orchestration and service wiring for the container
docker-compose.yml - Gemini API · External model service used for transcription and translation
- PDF/Doc libs · PyMuPDF, Pillow, WeasyPrint, and python-docx processing layer
Connections 20
- Homepage → Flask app: renders · Homepage is served by the Flask app
- Main JS → Flask app: calls API · Browser script invokes upload, progress, view, download, and delete endpoints
- Stylesheet → Homepage: styles · Presentation is applied to the rendered page
- Flask app → Translator: starts job · Upload handling hands the document to the translation engine
- Translator → Page extract: reads pages · Pipeline extracts page content from the source PDF
- Page extract → Gemini pass: feeds text · Extracted page material is prepared for model conversion
- Gemini pass → Compile doc: returns translation · Translated/transcribed content is assembled into document form
- Compile doc → Format export: produces outputs · Compiled content is exported into multiple deliverable formats
- Translator → Job folder: writes state · Intermediate and final artifacts are stored in the per-job directory
- Original PDF → Job folder: stored in · Uploaded PDF is persisted with the job folder
- Format export → Translated MD: derives · Markdown acts as the canonical generated artifact
- Flask app → Progress API: reports status · Backend exposes live progress for polling UI updates
- Progress API → Main JS: polled by · Frontend repeatedly checks job status
- Flask app → Download API: serves files · Backend returns translated outputs and the original PDF
- Download API → Job folder: reads from · Download endpoints pull artifacts from the job directory
- Flask app → Health check: exposes · Health endpoint is served for platform checks
- Translator → Gemini API: uses · Translation depends on the external Gemini service
- Translator → PDF/Doc libs: uses · Document extraction and export rely on PDF/document libraries
- Docker runtime → Flask app: runs · Container launches the Flask application
- Compose setup → Docker runtime: orchestrates · Compose defines the local deployment wiring