translang


Nametranslang JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/dsdanielpark/hf-transllm
SummaryTranslation Service API Module.
upload_time2023-06-25 17:13:59
maintainer
docs_urlNone
authordaniel park
requires_python>=3.6
license
keywords python api bard google bard large language model chatbot api google api chatbot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # translang
Translation Service Module for other projects. 

## Install
```
pip install translang
```

## Usage
### Seamless Integration of Translation APIs through Inheritance
You can easily extend the `TranslationService` class to integrate with popular translation API services.
Refer to the [`inference` method](https://github.com/dsdanielpark/hf-transllm/blob/main/transllm/core.py#L75) and [`generate` method](https://github.com/dsdanielpark/hf-transllm/blob/main/transllm/core.py#L93) in [hf-transllm](https://github.com/dsdanielpark/hf-transllm) project.

```python
from translang import TranslationService

class CustomTranslationService(TranslationService):
    def __init__(self, translator="google", deepl_api_key=None, bard_api_key=None, openai_api_key=None, openai_model='gpt-3.5-turbo'):
        super().__init__(translator, deepl_api_key, bard_api_key, openai_api_key, openai_model)

    def custom_process_with_translation(self, text: str, target_lang: str) -> str:
        translated_text = self.translate(text, target_lang)
        # Perform additional customization or processing if needed
        return translated_text
```

Commercial use or official use of the Google Translate service is chargeable. Please provide the google_official argument and google_api_key. Refer to the following notebook file and official link for more information. Use the google argument only for some basic functionality testing.
```python
translator = CustomTranslationService(translator="google")

translated_text = translator.custom_process_with_translation("Hello", "ko")
print(translated_text)
```

<br>

### `TranslationService.translate` Method
Google Translator, DeepL, OpenAI, Bard
```python
fomr translang import TranslationService

translator = TranslationService(translator="google")                                                                         # Google
# translator = TranslationService(translator="deepl", deepl_api_key="YOUR_DEEPL_API_KEY")                                    # DeepL
# translator = TranslationService(translator="bard", bard_api_key="YOUR_BARD_API_KEY")                                       # Bard
# translator = TranslationService(translator="openai", openai_api_key="YOUR_OPENAI_API_KEY", openai_model="gpt-3.5-trubo")   # Open AI

translated_text = translator.translate("Hello", "ko")
print(translated_text)
```


<br>

### `TranslationService.translate_parallel` Method

```python
from translang import TranslationService

# Create an instance of TranslationService
translator = TranslationService(translator="google", use_cache=True)

# List of texts to translate
texts = [
    "Hello",
    "Nice to meet you",
    "Testing the translation service"
]

# Destination language code
target_lang = "ko"

# Call the translate_parallel method
translated_texts = translator.translate_parallel(texts, target_lang)

# Print the translated texts
for text, translated_text in zip(texts, translated_texts):
    print(f"Original: {text}")
    print(f"Translated: {translated_text}")
    print("-----")

```

<br><br>

## License
[MIT](https://opensource.org/license/mit/) <br>
I hold no legal responsibility; 
```
The MIT License (MIT)

Copyright (c) 2023 Minwoo Park

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

### Bugs and Issues
Sincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.

### Contacts
- Core maintainer: [Daniel Park, South Korea](https://github.com/DSDanielPark) <br>
- E-mail: parkminwoo1991@gmail.com <br>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dsdanielpark/hf-transllm",
    "name": "translang",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "Python,API,Bard,Google Bard,Large Language Model,Chatbot API,Google API,Chatbot",
    "author": "daniel park",
    "author_email": "parkminwoo1991@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/7e/a3c1362996846e7846df8e64033ae664cc8308a294f9113900ef3b6d80d6/translang-0.1.4.tar.gz",
    "platform": null,
    "description": "# translang\r\nTranslation Service Module for other projects. \r\n\r\n## Install\r\n```\r\npip install translang\r\n```\r\n\r\n## Usage\r\n### Seamless Integration of Translation APIs through Inheritance\r\nYou can easily extend the `TranslationService` class to integrate with popular translation API services.\r\nRefer to the [`inference` method](https://github.com/dsdanielpark/hf-transllm/blob/main/transllm/core.py#L75) and [`generate` method](https://github.com/dsdanielpark/hf-transllm/blob/main/transllm/core.py#L93) in [hf-transllm](https://github.com/dsdanielpark/hf-transllm) project.\r\n\r\n```python\r\nfrom translang import TranslationService\r\n\r\nclass CustomTranslationService(TranslationService):\r\n    def __init__(self, translator=\"google\", deepl_api_key=None, bard_api_key=None, openai_api_key=None, openai_model='gpt-3.5-turbo'):\r\n        super().__init__(translator, deepl_api_key, bard_api_key, openai_api_key, openai_model)\r\n\r\n    def custom_process_with_translation(self, text: str, target_lang: str) -> str:\r\n        translated_text = self.translate(text, target_lang)\r\n        # Perform additional customization or processing if needed\r\n        return translated_text\r\n```\r\n\r\nCommercial use or official use of the Google Translate service is chargeable. Please provide the google_official argument and google_api_key. Refer to the following notebook file and official link for more information. Use the google argument only for some basic functionality testing.\r\n```python\r\ntranslator = CustomTranslationService(translator=\"google\")\r\n\r\ntranslated_text = translator.custom_process_with_translation(\"Hello\", \"ko\")\r\nprint(translated_text)\r\n```\r\n\r\n<br>\r\n\r\n### `TranslationService.translate` Method\r\nGoogle Translator, DeepL, OpenAI, Bard\r\n```python\r\nfomr translang import TranslationService\r\n\r\ntranslator = TranslationService(translator=\"google\")                                                                         # Google\r\n# translator = TranslationService(translator=\"deepl\", deepl_api_key=\"YOUR_DEEPL_API_KEY\")                                    # DeepL\r\n# translator = TranslationService(translator=\"bard\", bard_api_key=\"YOUR_BARD_API_KEY\")                                       # Bard\r\n# translator = TranslationService(translator=\"openai\", openai_api_key=\"YOUR_OPENAI_API_KEY\", openai_model=\"gpt-3.5-trubo\")   # Open AI\r\n\r\ntranslated_text = translator.translate(\"Hello\", \"ko\")\r\nprint(translated_text)\r\n```\r\n\r\n\r\n<br>\r\n\r\n### `TranslationService.translate_parallel` Method\r\n\r\n```python\r\nfrom translang import TranslationService\r\n\r\n# Create an instance of TranslationService\r\ntranslator = TranslationService(translator=\"google\", use_cache=True)\r\n\r\n# List of texts to translate\r\ntexts = [\r\n    \"Hello\",\r\n    \"Nice to meet you\",\r\n    \"Testing the translation service\"\r\n]\r\n\r\n# Destination language code\r\ntarget_lang = \"ko\"\r\n\r\n# Call the translate_parallel method\r\ntranslated_texts = translator.translate_parallel(texts, target_lang)\r\n\r\n# Print the translated texts\r\nfor text, translated_text in zip(texts, translated_texts):\r\n    print(f\"Original: {text}\")\r\n    print(f\"Translated: {translated_text}\")\r\n    print(\"-----\")\r\n\r\n```\r\n\r\n<br><br>\r\n\r\n## License\r\n[MIT](https://opensource.org/license/mit/) <br>\r\nI hold no legal responsibility; \r\n```\r\nThe MIT License (MIT)\r\n\r\nCopyright (c) 2023 Minwoo Park\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n```\r\n\r\n### Bugs and Issues\r\nSincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.\r\n\r\n### Contacts\r\n- Core maintainer: [Daniel Park, South Korea](https://github.com/DSDanielPark) <br>\r\n- E-mail: parkminwoo1991@gmail.com <br>\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Translation Service API Module.",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/dsdanielpark/hf-transllm"
    },
    "split_keywords": [
        "python",
        "api",
        "bard",
        "google bard",
        "large language model",
        "chatbot api",
        "google api",
        "chatbot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0302218df6e73d0383682049bb1b4d2d02a7d160fbbeb6488a92a217db881b1",
                "md5": "b9bb5f066063678db52dcb61551187f5",
                "sha256": "21f492bfd8c62eff3c61ab244d0a58963a9bb49b57fec9190e6967d0a3428d18"
            },
            "downloads": -1,
            "filename": "translang-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9bb5f066063678db52dcb61551187f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6112,
            "upload_time": "2023-06-25T17:13:53",
            "upload_time_iso_8601": "2023-06-25T17:13:53.225072Z",
            "url": "https://files.pythonhosted.org/packages/f0/30/2218df6e73d0383682049bb1b4d2d02a7d160fbbeb6488a92a217db881b1/translang-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b47ea3c1362996846e7846df8e64033ae664cc8308a294f9113900ef3b6d80d6",
                "md5": "ee32430f917286c024340d9dd420c2f3",
                "sha256": "374195283cd77497998df2811e5496fb39b7483b30d7bd986c19cd8ba9322678"
            },
            "downloads": -1,
            "filename": "translang-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "ee32430f917286c024340d9dd420c2f3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5191,
            "upload_time": "2023-06-25T17:13:59",
            "upload_time_iso_8601": "2023-06-25T17:13:59.294377Z",
            "url": "https://files.pythonhosted.org/packages/b4/7e/a3c1362996846e7846df8e64033ae664cc8308a294f9113900ef3b6d80d6/translang-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-25 17:13:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dsdanielpark",
    "github_project": "hf-transllm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "translang"
}
        
Elapsed time: 0.99324s