A powerful multilingual translation application built with Gradio, LangChain, and Hugging Face Transformers. This app provides an intuitive web interface for translating text between multiple languages, with special support for Cantonese translation.
- Multiple Language Support: Translate between 10+ language pairs including English, French, Spanish, German, Italian, Portuguese, Chinese, and Cantonese
- Cantonese Specialization: Enhanced Cantonese translation using Facebook's NLLB-200 model
- Dual Translation Modes: Switch between LangChain integration and direct HuggingFace pipeline
- GPU Acceleration: Automatic GPU detection and utilization for faster translations
- User-Friendly Interface: Clean, modern Gradio interface with examples and clear instructions
- Batch Processing Ready: Infrastructure for batch translation capabilities
- Context-Aware Translation: Framework for context-sensitive translations
- Python 3.9 or higher
- CUDA-capable GPU (optional, for acceleration)
- Clone the repository:
git clone https://github.com/WWIIITT/language-translation-app.git
cd language-translation-app
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
python LTM.py
The app will launch and provide you with a local URL (typically http://localhost:7860
). If you set share=True
, it will also provide a public URL for sharing.
Create a requirements.txt
file with:
gradio>=4.0.0
langchain>=0.1.0
transformers>=4.30.0
torch>=2.0.0
sentencepiece>=0.1.99
protobuf>=3.20.0
- English โ French
- English โ Spanish
- English โ German
- English โ Italian
- English โ Portuguese
- English โ Chinese (Simplified/Traditional)
- Cantonese/Chinese โ English
- English โ Cantonese (Alternative) - Better quality for Cantonese
- Select your translation direction from the dropdown
- Enter the text you want to translate
- Click the "๐ Translate" button
- View the translated result
- LangChain Mode: Toggle between LangChain integration and direct pipeline for different processing approaches
- Examples: Click on any example to quickly test the translation
You can also use the translation functionality programmatically:
from LTM import TranslationApp
# Initialize the app
app = TranslationApp()
# Translate text
translated = app.translate_with_langchain(
"Hello, world!",
"English to French"
)
print(translated) # "Bonjour, le monde!"
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Gradio UI โโโโโโถโ TranslationApp โโโโโโถโ HuggingFace โ
โ Interface โ โ Class โ โ Models โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โ
โโโโโโโโโโโโโโโโ โ
โ LangChain โโโโโโโโโโโโโโโโโโโโโ
โ Pipeline โ
โโโโโโโโโโโโโโโโ
Models are defined in the TRANSLATION_MODELS
and ALTERNATIVE_MODELS
dictionaries. To add new models:
TRANSLATION_MODELS["English to NewLanguage"] = "model-name-here"
- GPU Usage: Automatically detected and used when available
- Max Length: Default 512 tokens, adjustable in pipeline configuration
- Batch Size: Can be modified for batch processing needs
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/
# Format code
black LTM.py
-
Model Loading Errors
- Ensure you have stable internet for first-time model downloads
- Check available disk space (models can be 1-2GB each)
-
GPU Not Detected
- Verify CUDA installation:
python -c "import torch; print(torch.cuda.is_available())"
- Install appropriate PyTorch version for your CUDA version
- Verify CUDA installation:
-
Cantonese Translation Issues
- NLLB model requires additional memory (4GB+)
- Ensure
sentencepiece
is properly installed
This project is licensed under the MIT License - see the LICENSE file for details.
- Helsinki-NLP for OPUS-MT models
- Facebook/Meta for NLLB-200 model
- Gradio for the amazing UI framework
- LangChain for the LLM orchestration framework
- Hugging Face for model hosting and transformers library
- Add more language pairs
- Implement document translation
- Add translation quality metrics
- Create REST API endpoint
- Add translation history
- Implement custom model fine-tuning
- Add support for audio translation
โญ๏ธ If you find this project useful, please consider giving it a star!