Paulie-Aditya commited on
Commit
10b09df
1 Parent(s): d1f4023

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .gitignore +5 -0
  2. requirements.txt +91 -0
  3. translator.ipynb +452 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ secret.py
2
+ __pycache__
3
+ .venv
4
+ flagged
5
+ *.github
requirements.txt ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.3.0
3
+ annotated-types==0.7.0
4
+ anyio==4.4.0
5
+ attrs==23.2.0
6
+ blinker==1.6.3
7
+ certifi==2023.7.22
8
+ charset-normalizer==3.3.1
9
+ click==8.1.7
10
+ colorama==0.4.6
11
+ contourpy==1.2.1
12
+ cycler==0.12.1
13
+ dnspython==2.6.1
14
+ email_validator==2.1.1
15
+ fastapi==0.111.0
16
+ fastapi-cli==0.0.4
17
+ ffmpy==0.3.2
18
+ filelock==3.13.0
19
+ Flask==3.0.0
20
+ fonttools==4.52.4
21
+ fsspec==2023.10.0
22
+ gradio==4.32.0
23
+ gradio_client==0.17.0
24
+ h11==0.14.0
25
+ httpcore==1.0.5
26
+ httptools==0.6.1
27
+ httpx==0.27.0
28
+ huggingface-hub==0.17.3
29
+ idna==3.4
30
+ importlib_resources==6.4.0
31
+ intel-openmp==2021.4.0
32
+ itsdangerous==2.1.2
33
+ Jinja2==3.1.2
34
+ joblib==1.3.2
35
+ jsonschema==4.22.0
36
+ jsonschema-specifications==2023.12.1
37
+ kiwisolver==1.4.5
38
+ markdown-it-py==3.0.0
39
+ MarkupSafe==2.1.3
40
+ matplotlib==3.9.0
41
+ mdurl==0.1.2
42
+ mkl==2021.4.0
43
+ mpmath==1.3.0
44
+ networkx==3.3
45
+ nltk==3.8.1
46
+ numpy==1.26.1
47
+ orjson==3.10.3
48
+ packaging==23.2
49
+ pandas==2.2.2
50
+ pillow==10.3.0
51
+ protobuf==5.27.0
52
+ pydantic==2.7.2
53
+ pydantic_core==2.18.3
54
+ pydub==0.25.1
55
+ Pygments==2.18.0
56
+ pyparsing==3.1.2
57
+ python-dateutil==2.9.0.post0
58
+ python-dotenv==1.0.1
59
+ python-multipart==0.0.9
60
+ pytz==2024.1
61
+ PyYAML==6.0.1
62
+ referencing==0.35.1
63
+ regex==2023.10.3
64
+ requests==2.31.0
65
+ rich==13.7.1
66
+ rpds-py==0.18.1
67
+ ruff==0.4.6
68
+ safetensors==0.4.0
69
+ semantic-version==2.10.0
70
+ sentencepiece==0.1.99
71
+ shellingham==1.5.4
72
+ six==1.16.0
73
+ sniffio==1.3.1
74
+ starlette==0.37.2
75
+ sympy==1.12.1
76
+ tbb==2021.12.0
77
+ tokenizers==0.14.1
78
+ tomlkit==0.12.0
79
+ toolz==0.12.1
80
+ torch==2.3.0
81
+ tqdm==4.66.1
82
+ transformers==4.34.1
83
+ typer==0.12.3
84
+ typing_extensions==4.8.0
85
+ tzdata==2024.1
86
+ ujson==5.10.0
87
+ urllib3==2.0.7
88
+ uvicorn==0.30.0
89
+ watchfiles==0.22.0
90
+ websockets==11.0.3
91
+ Werkzeug==3.0.1
translator.ipynb ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "execution_count": null,
20
+ "metadata": {
21
+ "colab": {
22
+ "base_uri": "https://localhost:8080/"
23
+ },
24
+ "id": "JW_q5khKnpb7",
25
+ "outputId": "56c6c160-d1bc-43e1-c25b-677f149e230b"
26
+ },
27
+ "outputs": [
28
+ {
29
+ "output_type": "stream",
30
+ "name": "stdout",
31
+ "text": [
32
+ "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (4.41.1)\n",
33
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers) (3.14.0)\n",
34
+ "Requirement already satisfied: huggingface-hub<1.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.23.1)\n",
35
+ "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (1.25.2)\n",
36
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers) (24.0)\n",
37
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (6.0.1)\n",
38
+ "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (2024.5.15)\n",
39
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers) (2.31.0)\n",
40
+ "Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.19.1)\n",
41
+ "Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.4.3)\n",
42
+ "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers) (4.66.4)\n",
43
+ "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.23.0->transformers) (2023.6.0)\n",
44
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.23.0->transformers) (4.11.0)\n",
45
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (3.3.2)\n",
46
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (3.7)\n",
47
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2.0.7)\n",
48
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2024.2.2)\n",
49
+ "Requirement already satisfied: huggingface_hub in /usr/local/lib/python3.10/dist-packages (0.23.1)\n",
50
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (3.14.0)\n",
51
+ "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (2023.6.0)\n",
52
+ "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (24.0)\n",
53
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (6.0.1)\n",
54
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (2.31.0)\n",
55
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (4.66.4)\n",
56
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface_hub) (4.11.0)\n",
57
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface_hub) (3.3.2)\n",
58
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface_hub) (3.7)\n",
59
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface_hub) (2.0.7)\n",
60
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface_hub) (2024.2.2)\n"
61
+ ]
62
+ }
63
+ ],
64
+ "source": [
65
+ "!pip install transformers\n",
66
+ "!pip install huggingface_hub\n",
67
+ "!python -c \"from huggingface_hub.hf_api import HfFolder; HfFolder.save_token(<YOUR_TOKEN_HERE>)\""
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "source": [
73
+ "!pip install sentencepiece\n",
74
+ "nltk.download('punkt')"
75
+ ],
76
+ "metadata": {
77
+ "colab": {
78
+ "base_uri": "https://localhost:8080/"
79
+ },
80
+ "id": "guoGKlR4n1tY",
81
+ "outputId": "2653425f-2888-4318-cb4f-03a38e805077"
82
+ },
83
+ "execution_count": null,
84
+ "outputs": [
85
+ {
86
+ "output_type": "stream",
87
+ "name": "stdout",
88
+ "text": [
89
+ "Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/dist-packages (0.1.99)\n"
90
+ ]
91
+ },
92
+ {
93
+ "output_type": "stream",
94
+ "name": "stderr",
95
+ "text": [
96
+ "[nltk_data] Downloading package punkt to /root/nltk_data...\n",
97
+ "[nltk_data] Package punkt is already up-to-date!\n"
98
+ ]
99
+ },
100
+ {
101
+ "output_type": "execute_result",
102
+ "data": {
103
+ "text/plain": [
104
+ "True"
105
+ ]
106
+ },
107
+ "metadata": {},
108
+ "execution_count": 30
109
+ }
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "source": [
115
+ "!pip install gradio"
116
+ ],
117
+ "metadata": {
118
+ "colab": {
119
+ "base_uri": "https://localhost:8080/"
120
+ },
121
+ "id": "yBUmeZpGo9OX",
122
+ "outputId": "82e89bb1-c748-4314-899b-4c85bafafa5f"
123
+ },
124
+ "execution_count": null,
125
+ "outputs": [
126
+ {
127
+ "output_type": "stream",
128
+ "name": "stdout",
129
+ "text": [
130
+ "Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (4.32.0)\n",
131
+ "Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n",
132
+ "Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n",
133
+ "Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio) (0.111.0)\n",
134
+ "Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.3.2)\n",
135
+ "Requirement already satisfied: gradio-client==0.17.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.17.0)\n",
136
+ "Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.27.0)\n",
137
+ "Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.23.1)\n",
138
+ "Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.4.0)\n",
139
+ "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.4)\n",
140
+ "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n",
141
+ "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
142
+ "Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.25.2)\n",
143
+ "Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.10.3)\n",
144
+ "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (24.0)\n",
145
+ "Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.3)\n",
146
+ "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
147
+ "Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.7.1)\n",
148
+ "Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n",
149
+ "Requirement already satisfied: python-multipart>=0.0.9 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.9)\n",
150
+ "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
151
+ "Requirement already satisfied: ruff>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.4.6)\n",
152
+ "Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n",
153
+ "Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n",
154
+ "Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.3)\n",
155
+ "Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.11.0)\n",
156
+ "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.7)\n",
157
+ "Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.30.0)\n",
158
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.17.0->gradio) (2023.6.0)\n",
159
+ "Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.17.0->gradio) (11.0.3)\n",
160
+ "Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n",
161
+ "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n",
162
+ "Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n",
163
+ "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7.1)\n",
164
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2024.2.2)\n",
165
+ "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.0.5)\n",
166
+ "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7)\n",
167
+ "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.3.1)\n",
168
+ "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
169
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.14.0)\n",
170
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
171
+ "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",
172
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.1)\n",
173
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
174
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.51.0)\n",
175
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
176
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.2)\n",
177
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
178
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n",
179
+ "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
180
+ "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",
181
+ "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.18.2)\n",
182
+ "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",
183
+ "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",
184
+ "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",
185
+ "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.37.2)\n",
186
+ "Requirement already satisfied: fastapi-cli>=0.0.2 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.0.4)\n",
187
+ "Requirement already satisfied: ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (5.10.0)\n",
188
+ "Requirement already satisfied: email_validator>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (2.1.1)\n",
189
+ "Requirement already satisfied: dnspython>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from email_validator>=2.0.0->fastapi->gradio) (2.6.1)\n",
190
+ "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n",
191
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n",
192
+ "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.35.1)\n",
193
+ "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.1)\n",
194
+ "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",
195
+ "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",
196
+ "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",
197
+ "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx>=0.24.1->gradio) (1.2.1)\n",
198
+ "Requirement already satisfied: httptools>=0.5.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.6.1)\n",
199
+ "Requirement already satisfied: python-dotenv>=0.13 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (1.0.1)\n",
200
+ "Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.19.0)\n",
201
+ "Requirement already satisfied: watchfiles>=0.13 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.22.0)\n",
202
+ "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",
203
+ "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"
204
+ ]
205
+ }
206
+ ]
207
+ },
208
+ {
209
+ "cell_type": "code",
210
+ "source": [
211
+ "import requests\n",
212
+ "from transformers import pipeline\n",
213
+ "import nltk\n",
214
+ "from nltk import sent_tokenize\n",
215
+ "from transformers import MBartForConditionalGeneration, MBart50TokenizerFast\n",
216
+ "from transformers import pipeline"
217
+ ],
218
+ "metadata": {
219
+ "id": "laNjJ5sHn7EP"
220
+ },
221
+ "execution_count": null,
222
+ "outputs": []
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "source": [
227
+ "# Use a pipeline as a high-level helper\n",
228
+ "from transformers import pipeline\n",
229
+ "\n",
230
+ "pipe = pipeline(\"text2text-generation\", model=\"SnypzZz/Llama2-13b-Language-translate\", use_fast = False)"
231
+ ],
232
+ "metadata": {
233
+ "id": "GyqW7CypoCsX"
234
+ },
235
+ "execution_count": null,
236
+ "outputs": []
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "source": [
241
+ "tokenizer = MBart50TokenizerFast.from_pretrained(\"SnypzZz/Llama2-13b-Language-translate\", src_lang=\"en_XX\")\n",
242
+ "model = None\n",
243
+ "model_loaded = False"
244
+ ],
245
+ "metadata": {
246
+ "id": "XrBJH1-ToJW3"
247
+ },
248
+ "execution_count": null,
249
+ "outputs": []
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "source": [
254
+ "api_token_header = \"\"\n",
255
+ "with open('/content/secrets.py', 'r') as f:\n",
256
+ " api_token_header = f.read()"
257
+ ],
258
+ "metadata": {
259
+ "id": "yvoISQtlyyF6"
260
+ },
261
+ "execution_count": null,
262
+ "outputs": []
263
+ },
264
+ {
265
+ "cell_type": "code",
266
+ "source": [
267
+ "def load_model():\n",
268
+ " global model, model_loaded\n",
269
+ " model = MBartForConditionalGeneration.from_pretrained(\"SnypzZz/Llama2-13b-Language-translate\")\n",
270
+ " model_loaded =True\n",
271
+ " return model"
272
+ ],
273
+ "metadata": {
274
+ "id": "Z2HyW64woSps"
275
+ },
276
+ "execution_count": null,
277
+ "outputs": []
278
+ },
279
+ {
280
+ "cell_type": "code",
281
+ "source": [
282
+ "def translation(text,dest_lang,dest_lang_code, src_lang_code):\n",
283
+ "\n",
284
+ " if(dest_lang_code == src_lang_code):\n",
285
+ " return \"Please select different languages to translate between.\"\n",
286
+ "\n",
287
+ " # headers = {\"Authorization\": f\"Bearer {secrets_sih.api_token_header}\"}\n",
288
+ " headers = {\"Authorization\": f\"Bearer {api_token_header}\"}\n",
289
+ "\n",
290
+ " # Bengali Done\n",
291
+ " if(dest_lang == \"Bengali\" and src_lang_code == \"en_XX\"):\n",
292
+ " API_URL = \"https://api-inference.huggingface.co/models/csebuetnlp/banglat5_nmt_en_bn\"\n",
293
+ " def query(payload):\n",
294
+ " response = requests.post(API_URL, headers=headers, json=payload)\n",
295
+ " return response.json()\n",
296
+ " output = query({\n",
297
+ " \"inputs\": text,\n",
298
+ " })\n",
299
+ " print(output)\n",
300
+ " return output[0]['translation_text']\n",
301
+ " else:\n",
302
+ " global model\n",
303
+ " if model:\n",
304
+ " pass\n",
305
+ " else:\n",
306
+ " model = load_model()\n",
307
+ " loaded_model = model\n",
308
+ " tokenizer = MBart50TokenizerFast.from_pretrained(\"SnypzZz/Llama2-13b-Language-translate\", src_lang=src_lang_code)\n",
309
+ " #model_inputs = tokenizer(text, return_tensors=\"pt\")\n",
310
+ " loaded_model_inputs = tokenizer(text, return_tensors=\"pt\")\n",
311
+ "\n",
312
+ " # translate\n",
313
+ " generated_tokens = loaded_model.generate(\n",
314
+ " **loaded_model_inputs,\n",
315
+ " forced_bos_token_id=tokenizer.lang_code_to_id[dest_lang_code]\n",
316
+ " )\n",
317
+ " output = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)\n",
318
+ " print(output)\n",
319
+ " return output[0]"
320
+ ],
321
+ "metadata": {
322
+ "id": "q2H24G_lobxo"
323
+ },
324
+ "execution_count": null,
325
+ "outputs": []
326
+ },
327
+ {
328
+ "cell_type": "code",
329
+ "source": [
330
+ "def main_translation(text,dest_lang_code,src_lang_code):\n",
331
+ "\n",
332
+ " codes = {\"en_XX\":\"English\",\"bn_IN\":\"Bengali\", \"en_GB\":\"English\",\"gu_IN\":\"Gujarati\",\"hi_IN\":\"Hindi\",\"ta_IN\":\"Tamil\",\"te_IN\":\"Telugu\",\"mr_IN\":\"Marathi\"}\n",
333
+ " dest_lang = codes[dest_lang_code]\n",
334
+ " src_lang = codes[src_lang_code]\n",
335
+ "\n",
336
+ " sentences = sent_tokenize(text)\n",
337
+ " output = \"\"\n",
338
+ " for line in sentences:\n",
339
+ " output += translation(line,dest_lang,dest_lang_code, src_lang_code)\n",
340
+ " return {\"output\":output}"
341
+ ],
342
+ "metadata": {
343
+ "id": "Q8-OWT7nodES"
344
+ },
345
+ "execution_count": null,
346
+ "outputs": []
347
+ },
348
+ {
349
+ "cell_type": "code",
350
+ "source": [
351
+ "main_translation(\"Hello World\", \"hi_IN\",\"en_XX\")"
352
+ ],
353
+ "metadata": {
354
+ "colab": {
355
+ "base_uri": "https://localhost:8080/"
356
+ },
357
+ "id": "EHt29-U2wMp7",
358
+ "outputId": "c0cd8454-603e-4ed9-919a-cf6801397864"
359
+ },
360
+ "execution_count": null,
361
+ "outputs": [
362
+ {
363
+ "output_type": "stream",
364
+ "name": "stdout",
365
+ "text": [
366
+ "['हेलो वर्ल्ड']\n"
367
+ ]
368
+ },
369
+ {
370
+ "output_type": "execute_result",
371
+ "data": {
372
+ "text/plain": [
373
+ "{'output': 'हेलो वर्ल्ड'}"
374
+ ]
375
+ },
376
+ "metadata": {},
377
+ "execution_count": 56
378
+ }
379
+ ]
380
+ },
381
+ {
382
+ "cell_type": "code",
383
+ "source": [
384
+ "#User Interface\n",
385
+ "\n",
386
+ "import gradio as gr\n",
387
+ "\n",
388
+ "\n",
389
+ "def test(text, src, dest):\n",
390
+ " ans = main_translation(text,dest,src)\n",
391
+ " return ans['output']\n",
392
+ "demo = gr.Interface(\n",
393
+ " test,\n",
394
+ " [\"textbox\",\n",
395
+ " gr.Dropdown(\n",
396
+ " [(\"English\", \"en_XX\"), (\"Hindi\",\"hi_IN\"), (\"Bengali\",\"bn_IN\"), (\"Gujarati\",\"gu_IN\"), (\"Tamil\",\"ta_IN\"), (\"Telugu\",\"te_IN\"), (\"Marathi\",\"mr_IN\")], label=\"Source\", info=\"Select the Source Language!\"\n",
397
+ " ),\n",
398
+ " gr.Dropdown(\n",
399
+ " [(\"English\", \"en_XX\"), (\"Hindi\",\"hi_IN\"), (\"Bengali\",\"bn_IN\"), (\"Gujarati\",\"gu_IN\"), (\"Tamil\",\"ta_IN\"), (\"Telugu\",\"te_IN\"), (\"Marathi\",\"mr_IN\")], label=\"Destination\", info=\"Select the Destination Language!\"\n",
400
+ " ),\n",
401
+ " ],\n",
402
+ " outputs=[\"textbox\"],\n",
403
+ ")\n",
404
+ "\n",
405
+ "demo.launch()\n"
406
+ ],
407
+ "metadata": {
408
+ "colab": {
409
+ "base_uri": "https://localhost:8080/",
410
+ "height": 646
411
+ },
412
+ "id": "ebFtlmmmpCQO",
413
+ "outputId": "a064cd8e-dca3-4eda-d95e-bc25fac28d23"
414
+ },
415
+ "execution_count": null,
416
+ "outputs": [
417
+ {
418
+ "output_type": "stream",
419
+ "name": "stdout",
420
+ "text": [
421
+ "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",
422
+ "\n",
423
+ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
424
+ "Running on public URL: https://3800d81e3201b8d734.gradio.live\n",
425
+ "\n",
426
+ "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"
427
+ ]
428
+ },
429
+ {
430
+ "output_type": "display_data",
431
+ "data": {
432
+ "text/plain": [
433
+ "<IPython.core.display.HTML object>"
434
+ ],
435
+ "text/html": [
436
+ "<div><iframe src=\"https://3800d81e3201b8d734.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
437
+ ]
438
+ },
439
+ "metadata": {}
440
+ },
441
+ {
442
+ "output_type": "execute_result",
443
+ "data": {
444
+ "text/plain": []
445
+ },
446
+ "metadata": {},
447
+ "execution_count": 57
448
+ }
449
+ ]
450
+ }
451
+ ]
452
+ }