Skip to content

Commit

Permalink
Merge pull request #20 from dkedar7/docs
Browse files Browse the repository at this point in the history
[New example] Translate to multiple languages
  • Loading branch information
dkedar7 authored Jul 22, 2023
2 parents 2779202 + dd8a361 commit ca205e4
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 335 deletions.
9 changes: 0 additions & 9 deletions AUTHORS.md

This file was deleted.

112 changes: 0 additions & 112 deletions CONTRIBUTING.md

This file was deleted.

68 changes: 0 additions & 68 deletions HISTORY.md

This file was deleted.

73 changes: 73 additions & 0 deletions docs/Examples/01_simple_text_to_text.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1cb94cfb",
"metadata": {},
"source": [
"[![Open in colab](https://colab.research.google.com/assets/colab-badge.svg)](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
}
95 changes: 95 additions & 0 deletions docs/Examples/02_translate_to_multiple_languages.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1cb94cfb",
"metadata": {},
"source": [
"[![Open in colab](https://colab.research.google.com/assets/colab-badge.svg)](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
}
Loading

0 comments on commit ca205e4

Please sign in to comment.