This Streamlit application uses Google's Gemini 2.0 Flash model to translate documents from a source language to a target language. It supports .docx
files. The app provides a combined translation (showing both source and target text) and a translated-only version, both downloadable as a single ZIP archive.
- Document Translation: Translates
.docx
and.pdf
documents using the Gemini 2.0 Flash model. - Language Support: Supports a wide range of languages for both source and target. See the language selection dropdown in the app for the full list.
- Summary Generation: Generates a summary of the document in the target language.
- Combined and Translated-Only Output: Produces two DOCX files:
- A combined version with a table showing paragraph IDs, source text, and translated text.
- A translated-only version containing just the translated paragraphs.
- ZIP Download: Packages both output DOCX files into a single ZIP archive for easy download.
- Progress Bar: Displays a progress bar during translation using
tqdm
. - Right-to-Left (RTL) Support: Correctly handles RTL languages (e.g., Hebrew, Arabic) in the output DOCX files, including table and paragraph alignment.
- Error Handling: Includes robust error handling for API issues, invalid API keys, and file processing errors.
- API Key Management: Securely handles the Gemini API key using Streamlit secrets (or an optional input field).
- Streamlit UI: Provides a clean and user-friendly interface built with Streamlit.
- Python 3.9+
streamlit
google-generativeai
python-docx
pandas
tqdm
zipfile
(part of the Python standard library)- A valid Google Gemini API key.
-
Clone the repository:
git clone https://github.com/deedeeharris/AutoDocTranslate.git cd AutoDocTranslate
-
Create a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up your Gemini API Key:
-
Recommended: Using Streamlit Secrets:
-
Create a
.streamlit/secrets.toml
file in your project directory. -
Add your API key to the
secrets.toml
file:GEMINI_API_KEY = "your-api-key-here"
-
-
Alternative (Less Secure): Using an Input Field:
- The application includes an optional text input field in the sidebar where you can enter your API key. This is less secure than using secrets, especially if you deploy your app publicly.
-
-
Run the application:
streamlit run main.py
- Upload a Document: Use the "Choose a file" button to upload a
.docx
file. - Select Languages: Choose the source and target languages from the dropdown menus.
- Translate: Click the "Translate" button.
- View Progress: A progress bar will show the translation progress.
- Download Results: Once the translation is complete, a "Download All Files (ZIP)" button will appear. Click it to download a ZIP archive containing the combined and translated DOCX files.
- View Summary: You can view the generated summary in the target language by expanding the "Show Summary in Target Language" section.
streamlit
google-generativeai
python-docx
pandas
tqdm
- API Key: You must have a valid Google Gemini API key to use this application. Obtain one from the Google AI Studio.
- Rate Limits: Be aware of the Gemini API's rate limits. The code includes a 5-second delay between paragraph translations to help avoid exceeding these limits. You may need to adjust this delay depending on your usage and the API's current limits.
Contributions are welcome! Please feel free to submit pull requests or open issues to suggest improvements or report bugs.