-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from dkedar7/docs
[New example] Translate to multiple languages
- Loading branch information
Showing
15 changed files
with
378 additions
and
335 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1cb94cfb", | ||
"metadata": {}, | ||
"source": [ | ||
"[](https://githubtocolab.com/dkedar7/fast_dash/blob/release/docs/Examples/01_simple_text_to_text.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ce363e40", | ||
"metadata": {}, | ||
"source": [ | ||
"This notebook is optimized to run in Google Colab." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "15601ea1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# !pip install fast-dash jupyter_dash" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "512fe61d-7889-4c5b-90bc-c7284e87f28f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fast_dash import fastdash" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "e6b45553-4509-4662-b6bc-248779bd554e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"@fastdash(mode='inline', port=5000)\n", | ||
"def text_to_text_function(input_text):\n", | ||
" return input_text" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "fastdash_docs", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1cb94cfb", | ||
"metadata": {}, | ||
"source": [ | ||
"[](https://githubtocolab.com/dkedar7/fast_dash/blob/release/docs/Examples/02_translate_to_multiple_languages.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ce363e40", | ||
"metadata": {}, | ||
"source": [ | ||
"This notebook is optimized to run in Google Colab." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "15601ea1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install fast-dash jupyter_dash" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "2f402652", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"# This demo uses Huffing Face API inference. To use this, get your token from https://huggingface.co/settings/tokens and paste it below.\n", | ||
"import os\n", | ||
"os.environ[\"HF_TOKEN\"] = \"hf_xxxxxxxxxxxxxxxxxxxxxxxxxxx\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "9153b0d3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fast_dash import fastdash\n", | ||
"import requests\n", | ||
"\n", | ||
"API_URL = \"https://api-inference.huggingface.co/models/t5-base\"\n", | ||
"headers = {\"Authorization\": f\"Bearer {os.environ.get('HF_TOKEN')}\"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "99030b06", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"@fastdash(mode='inline', port=5000)\n", | ||
"def translate_to_multiple_languages(text: str = \"Translate this text to another language\", language: str = [\"German\", \"French\", \"Romanian\"]):\n", | ||
" \"Uses the T5 Base model from Hugging Face. May give incorrect results.\"\n", | ||
"\t\n", | ||
" payload = {\"inputs\": f\"translate English to {language}: {text}\"}\n", | ||
" response = requests.post(API_URL, headers=headers, json=payload)\n", | ||
" translation = response.json()[0]['translation_text'] if 'translation_text' in response.json()[0] else str(response.json())\n", | ||
" return translation" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "fastdash_docs", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.