# 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
```bash
pip install bntrans
```
## Usage
You can use this package to translate any Bangla to English or English to Bangla.
```python
from bntrans import Translator
translator = Translator(src="en", dest="bn")
translation = translator.translate("Hello world!") # ্যালো বিশ্ব!
print(translation)
```
### Some Useful Methods
```python
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](https://huggingface.co/settings/tokens) (Read Token is enough) and use it like this:
```python
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:
```bash
bntrans "Hello world!"
```
```bash
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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/shhossain/BanglaTranslationKit",
"name": "bntrans",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "bangla,english,translation,nlp,machine-translation,bangla to english translation,english to bangla translation",
"author": "shhossain",
"author_email": "",
"download_url": "",
"platform": null,
"description": "# BanglaTranslationKit\r\n\r\nBanglaTranslationKit is a open-source translation package for offline conversion between both Bengali and English languages (English to Bangla and Bangla to English)\r\n\r\n## Installation\r\n\r\n```bash\r\npip install bntrans\r\n```\r\n\r\n## Usage\r\n\r\nYou can use this package to translate any Bangla to English or English to Bangla.\r\n\r\n```python\r\nfrom bntrans import Translator\r\n\r\ntranslator = Translator(src=\"en\", dest=\"bn\")\r\ntranslation = translator.translate(\"Hello world!\") # \u09cd\u09af\u09be\u09b2\u09cb \u09ac\u09bf\u09b6\u09cd\u09ac!\r\nprint(translation)\r\n```\r\n\r\n### Some Useful Methods\r\n\r\n```python\r\nfrom bntrans import Translator\r\n\r\n# You can tell the model to use cpu\r\ntranslator = Translator(src=\"en\", dest=\"bn\", use_gpu=False)\r\n\r\n# Specify a custom model (from huggingface.co/models or local path)\r\ntranslator = Translator(model=\"mymodel\")\r\n\r\n# 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.\r\ntranslator = Translator(model=\"mymodel\", max_length=512)\r\n\r\n# You can also use `generate` method to get raw output from the model\r\ntranslator.generate(\"Hello world!\")\r\n```\r\n\r\n## Use Cloud Translation API (Free)\r\n\r\nIf you want to test the model without installing it, you can use the cloud translation API. Get a free Token from [here](https://huggingface.co/settings/tokens) (Read Token is enough) and use it like this:\r\n\r\n```python\r\nfrom bntrans import Translator\r\n\r\ntranslator = Translator(src=\"en\", dest=\"bn\", use_cloud=True, huggingface_token=\"YOUR_TOKEN\")\r\ntranslation = translator.translate(\"Hello world!\") # \u09cd\u09af\u09be\u09b2\u09cb \u09ac\u09bf\u09b6\u09cd\u09ac!\r\nprint(translation)\r\n```\r\n\r\n## Use in Command Line\r\n\r\nYou can also use this package in command line. Just install it and run the following command:\r\n\r\n```bash\r\nbntrans \"Hello world!\"\r\n```\r\n\r\n```bash\r\nusage: cli.py [-h] [-s SRC] [-d DEST] [-m MODEL] [-g GPU] [-l MAX_LENGTH] [-c USE_CLOUD] [-t HUGGINGFACE_TOKEN] text\r\n\r\nTranslate text from one language to another.\r\n\r\npositional arguments:\r\n text Text to translate\r\n\r\noptions:\r\n -h, --help show this help message and exit\r\n -s SRC, --src SRC Source language (default: en)\r\n -d DEST, --dest DEST Destination language (default: bn)\r\n -m MODEL, --model MODEL\r\n Model to use for translation\r\n -g GPU, --gpu GPU Whether to use GPU for translation (default: True)\r\n -l MAX_LENGTH, --max-length MAX_LENGTH\r\n Maximum length of the model (default: None)\r\n -c USE_CLOUD, --use-cloud USE_CLOUD\r\n Whether to use huggingface inference API (default: False)\r\n -t HUGGINGFACE_TOKEN, --huggingface-token HUGGINGFACE_TOKEN\r\n Huggingface inference API token (default: None)\r\n```\r\n",
"bugtrack_url": null,
"license": "",
"summary": "BanglaTranslationKit: Open-source tool for offline Bangla-English translation.",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://github.com/shhossain/BanglaTranslationKit"
},
"split_keywords": [
"bangla",
"english",
"translation",
"nlp",
"machine-translation",
"bangla to english translation",
"english to bangla translation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f8675218af985e5fa92c233e8f0a3efddb1a24a4afeacd99c6eee30fb9bd2e78",
"md5": "0abe846c26b58bc3707378f43b6ebfe3",
"sha256": "c7958a8581641348750aad66836b738bd1f453055b8df7d9806b846d04dbe2c6"
},
"downloads": -1,
"filename": "bntrans-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0abe846c26b58bc3707378f43b6ebfe3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 62920,
"upload_time": "2023-08-27T08:35:03",
"upload_time_iso_8601": "2023-08-27T08:35:03.412946Z",
"url": "https://files.pythonhosted.org/packages/f8/67/5218af985e5fa92c233e8f0a3efddb1a24a4afeacd99c6eee30fb9bd2e78/bntrans-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-27 08:35:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shhossain",
"github_project": "BanglaTranslationKit",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "bntrans"
}