Afeezee commited on
Commit
1cde37b
Β·
verified Β·
1 Parent(s): 0f03650

Upload Multilingual_Translation.ipynb

Browse files
Files changed (1) hide show
  1. Multilingual_Translation.ipynb +317 -0
Multilingual_Translation.ipynb ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "source": [
20
+ "!pip install gradio\n",
21
+ "!pip install translate"
22
+ ],
23
+ "metadata": {
24
+ "colab": {
25
+ "base_uri": "https://localhost:8080/"
26
+ },
27
+ "id": "QvRHyaZT2uAN",
28
+ "outputId": "a18ce9ae-66d8-43f8-ad22-e9b4804349ff"
29
+ },
30
+ "execution_count": 1,
31
+ "outputs": [
32
+ {
33
+ "output_type": "stream",
34
+ "name": "stdout",
35
+ "text": [
36
+ "Collecting gradio\n",
37
+ " Downloading gradio-4.40.0-py3-none-any.whl.metadata (15 kB)\n",
38
+ "Collecting aiofiles<24.0,>=22.0 (from gradio)\n",
39
+ " Downloading aiofiles-23.2.1-py3-none-any.whl.metadata (9.7 kB)\n",
40
+ "Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
41
+ "Collecting fastapi (from gradio)\n",
42
+ " Downloading fastapi-0.112.0-py3-none-any.whl.metadata (27 kB)\n",
43
+ "Collecting ffmpy (from gradio)\n",
44
+ " Downloading ffmpy-0.4.0-py3-none-any.whl.metadata (2.9 kB)\n",
45
+ "Collecting gradio-client==1.2.0 (from gradio)\n",
46
+ " Downloading gradio_client-1.2.0-py3-none-any.whl.metadata (7.1 kB)\n",
47
+ "Collecting httpx>=0.24.1 (from gradio)\n",
48
+ " Downloading httpx-0.27.0-py3-none-any.whl.metadata (7.2 kB)\n",
49
+ "Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.23.5)\n",
50
+ "Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.4.0)\n",
51
+ "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.4)\n",
52
+ "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n",
53
+ "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
54
+ "Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.26.4)\n",
55
+ "Collecting orjson~=3.0 (from gradio)\n",
56
+ " Downloading orjson-3.10.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (50 kB)\n",
57
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.4/50.4 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
58
+ "\u001b[?25hRequirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (24.1)\n",
59
+ "Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.4)\n",
60
+ "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
61
+ "Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.8.2)\n",
62
+ "Collecting pydub (from gradio)\n",
63
+ " Downloading pydub-0.25.1-py2.py3-none-any.whl.metadata (1.4 kB)\n",
64
+ "Collecting python-multipart>=0.0.9 (from gradio)\n",
65
+ " Downloading python_multipart-0.0.9-py3-none-any.whl.metadata (2.5 kB)\n",
66
+ "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
67
+ "Collecting ruff>=0.2.2 (from gradio)\n",
68
+ " Downloading ruff-0.5.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (24 kB)\n",
69
+ "Collecting semantic-version~=2.0 (from gradio)\n",
70
+ " Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\n",
71
+ "Collecting tomlkit==0.12.0 (from gradio)\n",
72
+ " Downloading tomlkit-0.12.0-py3-none-any.whl.metadata (2.7 kB)\n",
73
+ "Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.3)\n",
74
+ "Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.12.2)\n",
75
+ "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.7)\n",
76
+ "Collecting uvicorn>=0.14.0 (from gradio)\n",
77
+ " Downloading uvicorn-0.30.5-py3-none-any.whl.metadata (6.6 kB)\n",
78
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.2.0->gradio) (2024.6.1)\n",
79
+ "Collecting websockets<13.0,>=10.0 (from gradio-client==1.2.0->gradio)\n",
80
+ " Downloading websockets-12.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.6 kB)\n",
81
+ "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (3.7)\n",
82
+ "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n",
83
+ "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.2.2)\n",
84
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2024.7.4)\n",
85
+ "Collecting httpcore==1.* (from httpx>=0.24.1->gradio)\n",
86
+ " Downloading httpcore-1.0.5-py3-none-any.whl.metadata (20 kB)\n",
87
+ "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.24.1->gradio)\n",
88
+ " Downloading h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)\n",
89
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.15.4)\n",
90
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
91
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n",
92
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.1)\n",
93
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
94
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.53.1)\n",
95
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
96
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.2)\n",
97
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
98
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
99
+ "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
100
+ "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.7.0)\n",
101
+ "Requirement already satisfied: pydantic-core==2.20.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.20.1)\n",
102
+ "Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
103
+ "Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
104
+ "Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
105
+ "Collecting starlette<0.38.0,>=0.37.2 (from fastapi->gradio)\n",
106
+ " Downloading starlette-0.37.2-py3-none-any.whl.metadata (5.9 kB)\n",
107
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
108
+ "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
109
+ "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.16.1)\n",
110
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
111
+ "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
112
+ "Downloading gradio-4.40.0-py3-none-any.whl (12.5 MB)\n",
113
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.5/12.5 MB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
114
+ "\u001b[?25hDownloading gradio_client-1.2.0-py3-none-any.whl (318 kB)\n",
115
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.6/318.6 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
116
+ "\u001b[?25hDownloading tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
117
+ "Downloading aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
118
+ "Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n",
119
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
120
+ "\u001b[?25hDownloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
121
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
122
+ "\u001b[?25hDownloading orjson-3.10.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)\n",
123
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.1/141.1 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
124
+ "\u001b[?25hDownloading python_multipart-0.0.9-py3-none-any.whl (22 kB)\n",
125
+ "Downloading ruff-0.5.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB)\n",
126
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.2/10.2 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
127
+ "\u001b[?25hDownloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
128
+ "Downloading uvicorn-0.30.5-py3-none-any.whl (62 kB)\n",
129
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.8/62.8 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
130
+ "\u001b[?25hDownloading fastapi-0.112.0-py3-none-any.whl (93 kB)\n",
131
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m93.1/93.1 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
132
+ "\u001b[?25hDownloading ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n",
133
+ "Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
134
+ "Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
135
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
136
+ "\u001b[?25hDownloading starlette-0.37.2-py3-none-any.whl (71 kB)\n",
137
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
138
+ "\u001b[?25hDownloading websockets-12.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (130 kB)\n",
139
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
140
+ "\u001b[?25hInstalling collected packages: pydub, websockets, tomlkit, semantic-version, ruff, python-multipart, orjson, h11, ffmpy, aiofiles, uvicorn, starlette, httpcore, httpx, fastapi, gradio-client, gradio\n",
141
+ " Attempting uninstall: tomlkit\n",
142
+ " Found existing installation: tomlkit 0.13.0\n",
143
+ " Uninstalling tomlkit-0.13.0:\n",
144
+ " Successfully uninstalled tomlkit-0.13.0\n",
145
+ "Successfully installed aiofiles-23.2.1 fastapi-0.112.0 ffmpy-0.4.0 gradio-4.40.0 gradio-client-1.2.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 orjson-3.10.6 pydub-0.25.1 python-multipart-0.0.9 ruff-0.5.6 semantic-version-2.10.0 starlette-0.37.2 tomlkit-0.12.0 uvicorn-0.30.5 websockets-12.0\n",
146
+ "Collecting translate\n",
147
+ " Downloading translate-3.6.1-py2.py3-none-any.whl.metadata (7.7 kB)\n",
148
+ "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from translate) (8.1.7)\n",
149
+ "Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from translate) (4.9.4)\n",
150
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from translate) (2.31.0)\n",
151
+ "Collecting libretranslatepy==2.1.1 (from translate)\n",
152
+ " Downloading libretranslatepy-2.1.1-py3-none-any.whl.metadata (233 bytes)\n",
153
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->translate) (3.3.2)\n",
154
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->translate) (3.7)\n",
155
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->translate) (2.0.7)\n",
156
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->translate) (2024.7.4)\n",
157
+ "Downloading translate-3.6.1-py2.py3-none-any.whl (12 kB)\n",
158
+ "Downloading libretranslatepy-2.1.1-py3-none-any.whl (3.2 kB)\n",
159
+ "Installing collected packages: libretranslatepy, translate\n",
160
+ "Successfully installed libretranslatepy-2.1.1 translate-3.6.1\n"
161
+ ]
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 2,
168
+ "metadata": {
169
+ "colab": {
170
+ "base_uri": "https://localhost:8080/",
171
+ "height": 228
172
+ },
173
+ "id": "wgs_g8sV2j3H",
174
+ "outputId": "c68a4742-8744-4a53-899b-0840d37d94d9"
175
+ },
176
+ "outputs": [
177
+ {
178
+ "output_type": "error",
179
+ "ename": "AttributeError",
180
+ "evalue": "module 'gradio' has no attribute 'inputs'",
181
+ "traceback": [
182
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
183
+ "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
184
+ "\u001b[0;32m<ipython-input-2-a12a776bcb96>\u001b[0m in \u001b[0;36m<cell line: 27>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfrom_lang\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mto_lang\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtranslate_text\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mget_code\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfrom_lang\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mget_code\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mto_lang\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 29\u001b[0m inputs=[\n\u001b[0;32m---> 30\u001b[0;31m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTextbox\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Input Text\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 31\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDropdown\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlanguage_options\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"From Language\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"English\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDropdown\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlanguage_options\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"To Language\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Yoruba\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
185
+ "\u001b[0;31mAttributeError\u001b[0m: module 'gradio' has no attribute 'inputs'"
186
+ ]
187
+ }
188
+ ],
189
+ "source": [
190
+ "import gradio as gr\n",
191
+ "from translate import Translator\n",
192
+ "\n",
193
+ "def translate_text(text, from_lang, to_lang):\n",
194
+ " translator = Translator(from_lang=from_lang, to_lang=to_lang)\n",
195
+ " return translator.translate(text)\n",
196
+ "\n",
197
+ "languages = [\n",
198
+ " (\"English\", \"en\"),\n",
199
+ " (\"Spanish\", \"es\"),\n",
200
+ " (\"French\", \"fr\"),\n",
201
+ " (\"German\", \"de\"),\n",
202
+ " (\"Chinese\", \"zh\"),\n",
203
+ " (\"Japanese\", \"ja\"),\n",
204
+ " (\"Yoruba\", \"yo\"),\n",
205
+ " (\"Hausa\", \"ha\"),\n",
206
+ " (\"Ibo\", \"ig\")\n",
207
+ " # Add more languages as needed\n",
208
+ "]\n",
209
+ "\n",
210
+ "language_options = [lang[0] for lang in languages]\n",
211
+ "language_codes = {lang[0]: lang[1] for lang in languages}\n",
212
+ "\n",
213
+ "def get_code(language_name):\n",
214
+ " return language_codes.get(language_name, \"en\")\n",
215
+ "\n",
216
+ "interface = gr.Interface(\n",
217
+ " fn=lambda text, from_lang, to_lang: translate_text(text, get_code(from_lang), get_code(to_lang)),\n",
218
+ " inputs=[\n",
219
+ " gr.inputs.Textbox(label=\"Input Text\"),\n",
220
+ " gr.inputs.Dropdown(language_options, label=\"From Language\", default=\"English\"),\n",
221
+ " gr.inputs.Dropdown(language_options, label=\"To Language\", default=\"Yoruba\")\n",
222
+ " ],\n",
223
+ " outputs=\"text\",\n",
224
+ " title=\"Multi-Language Translator Application\"\n",
225
+ ")\n",
226
+ "\n",
227
+ "interface.launch()"
228
+ ]
229
+ },
230
+ {
231
+ "source": [
232
+ "import gradio as gr\n",
233
+ "from translate import Translator\n",
234
+ "\n",
235
+ "def translate_text(text, from_lang, to_lang):\n",
236
+ " translator = Translator(from_lang=from_lang, to_lang=to_lang)\n",
237
+ " return translator.translate(text)\n",
238
+ "\n",
239
+ "languages = [\n",
240
+ " (\"English\", \"en\"),\n",
241
+ " (\"Spanish\", \"es\"),\n",
242
+ " (\"French\", \"fr\"),\n",
243
+ " (\"German\", \"de\"),\n",
244
+ " (\"Chinese\", \"zh\"),\n",
245
+ " (\"Japanese\", \"ja\"),\n",
246
+ " (\"Yoruba\", \"yo\"),\n",
247
+ " (\"Hausa\", \"ha\"),\n",
248
+ " (\"Ibo\", \"ig\")\n",
249
+ " # Add more languages as needed\n",
250
+ "]\n",
251
+ "\n",
252
+ "language_options = [lang[0] for lang in languages]\n",
253
+ "language_codes = {lang[0]: lang[1] for lang in languages}\n",
254
+ "\n",
255
+ "def get_code(language_name):\n",
256
+ " return language_codes.get(language_name, \"en\")\n",
257
+ "\n",
258
+ "interface = gr.Interface(\n",
259
+ " fn=lambda text, from_lang, to_lang: translate_text(text, get_code(from_lang), get_code(to_lang)),\n",
260
+ " inputs=[\n",
261
+ " gr.Textbox(label=\"Input Text\"),\n",
262
+ " gr.Dropdown(choices=language_options, label=\"From Language\", value=\"English\"), # Use 'value' instead of 'default'\n",
263
+ " gr.Dropdown(choices=language_options, label=\"To Language\", value=\"Yoruba\") # Use 'value' instead of 'default'\n",
264
+ " ],\n",
265
+ " outputs=\"text\",\n",
266
+ " title=\"Multi-Language Translator Application\"\n",
267
+ ")\n",
268
+ "\n",
269
+ "interface.launch()"
270
+ ],
271
+ "cell_type": "code",
272
+ "metadata": {
273
+ "colab": {
274
+ "base_uri": "https://localhost:8080/",
275
+ "height": 646
276
+ },
277
+ "id": "N5yioy454YNf",
278
+ "outputId": "f93a9652-1f94-46d8-e7d1-f240c2af4be6"
279
+ },
280
+ "execution_count": 4,
281
+ "outputs": [
282
+ {
283
+ "output_type": "stream",
284
+ "name": "stdout",
285
+ "text": [
286
+ "Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
287
+ "\n",
288
+ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
289
+ "Running on public URL: https://0928efa583e02b0f4d.gradio.live\n",
290
+ "\n",
291
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
292
+ ]
293
+ },
294
+ {
295
+ "output_type": "display_data",
296
+ "data": {
297
+ "text/plain": [
298
+ "<IPython.core.display.HTML object>"
299
+ ],
300
+ "text/html": [
301
+ "<div><iframe src=\"https://0928efa583e02b0f4d.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
302
+ ]
303
+ },
304
+ "metadata": {}
305
+ },
306
+ {
307
+ "output_type": "execute_result",
308
+ "data": {
309
+ "text/plain": []
310
+ },
311
+ "metadata": {},
312
+ "execution_count": 4
313
+ }
314
+ ]
315
+ }
316
+ ]
317
+ }