Skip to main content

BanglaTranslationKit: Open-source tool for offline Bangla-English translation.

Project description

BanglaTranslationKit

BanglaTranslationKit is a open-source translation package for offline conversion between both Bengali and English languages (English to Bangla and Bangla to English)

Installation

pip install bntrans

Usage

You can use this package to translate any Bangla to English or English to Bangla.

from bntrans import Translator

translator = Translator(src="en", dest="bn")
translation = translator.translate("Hello world!")  #  ্যালো বিশ্ব!
print(translation)

Some Useful Methods

from bntrans import Translator

# You can tell the model to use cpu
translator = Translator(src="en", dest="bn", use_gpu=False)

# Specify a custom model (from huggingface.co/models or local path)
translator = Translator(model="mymodel")

# If custom model doesn't have a maximum length, you can specify it. It is better to specify it as some models have wrong maximum length in their config.
translator = Translator(model="mymodel", max_length=512)

# You can also use `generate` method to get raw output from the model
translator.generate("Hello world!")

Use Cloud Translation API (Free)

If you want to test the model without installing it, you can use the cloud translation API. Get a free Token from here (Read Token is enough) and use it like this:

from bntrans import Translator

translator = Translator(src="en", dest="bn", use_cloud=True, huggingface_token="YOUR_TOKEN")
translation = translator.translate("Hello world!")  #  ্যালো বিশ্ব!
print(translation)

Use in Command Line

You can also use this package in command line. Just install it and run the following command:

bntrans "Hello world!"
usage: cli.py [-h] [-s SRC] [-d DEST] [-m MODEL] [-g GPU] [-l MAX_LENGTH] [-c USE_CLOUD] [-t HUGGINGFACE_TOKEN] text

Translate text from one language to another.

positional arguments:
  text                  Text to translate

options:
  -h, --help            show this help message and exit
  -s SRC, --src SRC     Source language (default: en)
  -d DEST, --dest DEST  Destination language (default: bn)
  -m MODEL, --model MODEL
                        Model to use for translation
  -g GPU, --gpu GPU     Whether to use GPU for translation (default: True)
  -l MAX_LENGTH, --max-length MAX_LENGTH
                        Maximum length of the model (default: None)
  -c USE_CLOUD, --use-cloud USE_CLOUD
                        Whether to use huggingface inference API (default: False)
  -t HUGGINGFACE_TOKEN, --huggingface-token HUGGINGFACE_TOKEN
                        Huggingface inference API token (default: None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

bntrans-0.0.5-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file bntrans-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: bntrans-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for bntrans-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c7958a8581641348750aad66836b738bd1f453055b8df7d9806b846d04dbe2c6
MD5 0abe846c26b58bc3707378f43b6ebfe3
BLAKE2b-256 f8675218af985e5fa92c233e8f0a3efddb1a24a4afeacd99c6eee30fb9bd2e78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page