Gztavo commited on
Commit
1163bbe
β€’
1 Parent(s): 5efc907

use load by image captioning

Browse files
vit_gpt2_image_captioning_gradioload.ipynb ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": 1,
20
+ "metadata": {
21
+ "colab": {
22
+ "base_uri": "https://localhost:8080/"
23
+ },
24
+ "id": "V8i3gjxY85ps",
25
+ "outputId": "b5286759-f627-4e7d-89fb-91ced8842cad"
26
+ },
27
+ "outputs": [
28
+ {
29
+ "output_type": "stream",
30
+ "name": "stdout",
31
+ "text": [
32
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
33
+ "Collecting gradio\n",
34
+ " Downloading gradio-3.20.1-py3-none-any.whl (14.3 MB)\n",
35
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m14.3/14.3 MB\u001b[0m \u001b[31m50.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
36
+ "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.8/dist-packages (from gradio) (1.3.5)\n",
37
+ "Collecting uvicorn\n",
38
+ " Downloading uvicorn-0.20.0-py3-none-any.whl (56 kB)\n",
39
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.9/56.9 KB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
40
+ "\u001b[?25hCollecting markdown-it-py[linkify]>=2.0.0\n",
41
+ " Downloading markdown_it_py-2.2.0-py3-none-any.whl (84 kB)\n",
42
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m84.5/84.5 KB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
43
+ "\u001b[?25hCollecting pydub\n",
44
+ " Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
45
+ "Requirement already satisfied: markupsafe in /usr/local/lib/python3.8/dist-packages (from gradio) (2.1.2)\n",
46
+ "Requirement already satisfied: requests in /usr/local/lib/python3.8/dist-packages (from gradio) (2.25.1)\n",
47
+ "Collecting python-multipart\n",
48
+ " Downloading python_multipart-0.0.6-py3-none-any.whl (45 kB)\n",
49
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.7/45.7 KB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
50
+ "\u001b[?25hCollecting pycryptodome\n",
51
+ " Downloading pycryptodome-3.17-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)\n",
52
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m51.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
53
+ "\u001b[?25hCollecting ffmpy\n",
54
+ " Downloading ffmpy-0.3.0.tar.gz (4.8 kB)\n",
55
+ " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
56
+ "Collecting orjson\n",
57
+ " Downloading orjson-3.8.7-cp38-cp38-manylinux_2_28_x86_64.whl (140 kB)\n",
58
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m140.7/140.7 KB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
59
+ "\u001b[?25hRequirement already satisfied: typing-extensions in /usr/local/lib/python3.8/dist-packages (from gradio) (4.5.0)\n",
60
+ "Collecting httpx\n",
61
+ " Downloading httpx-0.23.3-py3-none-any.whl (71 kB)\n",
62
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.5/71.5 KB\u001b[0m \u001b[31m6.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
63
+ "\u001b[?25hRequirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from gradio) (1.22.4)\n",
64
+ "Collecting fastapi\n",
65
+ " Downloading fastapi-0.93.0-py3-none-any.whl (56 kB)\n",
66
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 KB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
67
+ "\u001b[?25hRequirement already satisfied: pydantic in /usr/local/lib/python3.8/dist-packages (from gradio) (1.10.5)\n",
68
+ "Collecting aiofiles\n",
69
+ " Downloading aiofiles-23.1.0-py3-none-any.whl (14 kB)\n",
70
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.8/dist-packages (from gradio) (2023.1.0)\n",
71
+ "Requirement already satisfied: altair>=4.2.0 in /usr/local/lib/python3.8/dist-packages (from gradio) (4.2.2)\n",
72
+ "Requirement already satisfied: aiohttp in /usr/local/lib/python3.8/dist-packages (from gradio) (3.8.4)\n",
73
+ "Requirement already satisfied: pillow in /usr/local/lib/python3.8/dist-packages (from gradio) (8.4.0)\n",
74
+ "Collecting mdit-py-plugins<=0.3.3\n",
75
+ " Downloading mdit_py_plugins-0.3.3-py3-none-any.whl (50 kB)\n",
76
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.5/50.5 KB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
77
+ "\u001b[?25hRequirement already satisfied: pyyaml in /usr/local/lib/python3.8/dist-packages (from gradio) (6.0)\n",
78
+ "Collecting websockets>=10.0\n",
79
+ " Downloading websockets-10.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106 kB)\n",
80
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.0/107.0 KB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
81
+ "\u001b[?25hRequirement already satisfied: jinja2 in /usr/local/lib/python3.8/dist-packages (from gradio) (3.1.2)\n",
82
+ "Requirement already satisfied: matplotlib in /usr/local/lib/python3.8/dist-packages (from gradio) (3.5.3)\n",
83
+ "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.8/dist-packages (from altair>=4.2.0->gradio) (4.3.3)\n",
84
+ "Requirement already satisfied: entrypoints in /usr/local/lib/python3.8/dist-packages (from altair>=4.2.0->gradio) (0.4)\n",
85
+ "Requirement already satisfied: toolz in /usr/local/lib/python3.8/dist-packages (from altair>=4.2.0->gradio) (0.12.0)\n",
86
+ "Collecting mdurl~=0.1\n",
87
+ " Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n",
88
+ "Collecting linkify-it-py<3,>=1\n",
89
+ " Downloading linkify_it_py-2.0.0-py3-none-any.whl (19 kB)\n",
90
+ "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.8/dist-packages (from pandas->gradio) (2.8.2)\n",
91
+ "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.8/dist-packages (from pandas->gradio) (2022.7.1)\n",
92
+ "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (1.3.3)\n",
93
+ "Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (3.0.1)\n",
94
+ "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (4.0.2)\n",
95
+ "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (1.3.1)\n",
96
+ "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (6.0.4)\n",
97
+ "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (22.2.0)\n",
98
+ "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.8/dist-packages (from aiohttp->gradio) (1.8.2)\n",
99
+ "Collecting starlette<0.26.0,>=0.25.0\n",
100
+ " Downloading starlette-0.25.0-py3-none-any.whl (66 kB)\n",
101
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.4/66.4 KB\u001b[0m \u001b[31m501.7 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
102
+ "\u001b[?25hCollecting sniffio\n",
103
+ " Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)\n",
104
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.8/dist-packages (from httpx->gradio) (2022.12.7)\n",
105
+ "Collecting rfc3986[idna2008]<2,>=1.3\n",
106
+ " Downloading rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)\n",
107
+ "Collecting httpcore<0.17.0,>=0.15.0\n",
108
+ " Downloading httpcore-0.16.3-py3-none-any.whl (69 kB)\n",
109
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m69.6/69.6 KB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
110
+ "\u001b[?25hRequirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->gradio) (1.4.4)\n",
111
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib->gradio) (23.0)\n",
112
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib->gradio) (0.11.0)\n",
113
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib->gradio) (4.38.0)\n",
114
+ "Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->gradio) (3.0.9)\n",
115
+ "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.8/dist-packages (from requests->gradio) (2.10)\n",
116
+ "Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.8/dist-packages (from requests->gradio) (4.0.0)\n",
117
+ "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from requests->gradio) (1.26.14)\n",
118
+ "Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.8/dist-packages (from uvicorn->gradio) (8.1.3)\n",
119
+ "Collecting h11>=0.8\n",
120
+ " Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
121
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 KB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
122
+ "\u001b[?25hCollecting anyio<5.0,>=3.0\n",
123
+ " Downloading anyio-3.6.2-py3-none-any.whl (80 kB)\n",
124
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m80.6/80.6 KB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
125
+ "\u001b[?25hRequirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.8/dist-packages (from jsonschema>=3.0->altair>=4.2.0->gradio) (0.19.3)\n",
126
+ "Requirement already satisfied: importlib-resources>=1.4.0 in /usr/local/lib/python3.8/dist-packages (from jsonschema>=3.0->altair>=4.2.0->gradio) (5.12.0)\n",
127
+ "Collecting uc-micro-py\n",
128
+ " Downloading uc_micro_py-1.0.1-py3-none-any.whl (6.2 kB)\n",
129
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/dist-packages (from python-dateutil>=2.7.3->pandas->gradio) (1.15.0)\n",
130
+ "Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.8/dist-packages (from importlib-resources>=1.4.0->jsonschema>=3.0->altair>=4.2.0->gradio) (3.15.0)\n",
131
+ "Building wheels for collected packages: ffmpy\n",
132
+ " Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
133
+ " Created wheel for ffmpy: filename=ffmpy-0.3.0-py3-none-any.whl size=4711 sha256=13f8ffda7263e49659b8cfa6e64058f5b17b4ea5d25f283bfe79404460f085ff\n",
134
+ " Stored in directory: /root/.cache/pip/wheels/ff/5b/59/913b443e7369dc04b61f607a746b6f7d83fb65e2e19fcc958d\n",
135
+ "Successfully built ffmpy\n",
136
+ "Installing collected packages: rfc3986, pydub, ffmpy, websockets, uc-micro-py, sniffio, python-multipart, pycryptodome, orjson, mdurl, h11, aiofiles, uvicorn, markdown-it-py, linkify-it-py, anyio, starlette, mdit-py-plugins, httpcore, httpx, fastapi, gradio\n",
137
+ "Successfully installed aiofiles-23.1.0 anyio-3.6.2 fastapi-0.93.0 ffmpy-0.3.0 gradio-3.20.1 h11-0.14.0 httpcore-0.16.3 httpx-0.23.3 linkify-it-py-2.0.0 markdown-it-py-2.2.0 mdit-py-plugins-0.3.3 mdurl-0.1.2 orjson-3.8.7 pycryptodome-3.17 pydub-0.25.1 python-multipart-0.0.6 rfc3986-1.5.0 sniffio-1.3.0 starlette-0.25.0 uc-micro-py-1.0.1 uvicorn-0.20.0 websockets-10.4\n"
138
+ ]
139
+ }
140
+ ],
141
+ "source": [
142
+ "!pip install gradio"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "source": [
148
+ "import gradio as gr\n",
149
+ "gr.Interface.load(\n",
150
+ " 'huggingface/nlpconnect/vit-gpt2-image-captioning',\n",
151
+ " inputs = gr.Image(label=\"Carga una imagen\"),\n",
152
+ " title = \"Classificator\",\n",
153
+ " description = \"Obtener descripcion por imagen\"\n",
154
+ ").launch()"
155
+ ],
156
+ "metadata": {
157
+ "colab": {
158
+ "base_uri": "https://localhost:8080/",
159
+ "height": 634
160
+ },
161
+ "id": "TFIAntoh9MCp",
162
+ "outputId": "53099e44-244d-41c3-aef8-8a3060baf087"
163
+ },
164
+ "execution_count": 5,
165
+ "outputs": [
166
+ {
167
+ "output_type": "stream",
168
+ "name": "stdout",
169
+ "text": [
170
+ "Fetching model from: https://huggingface.co/nlpconnect/vit-gpt2-image-captioning\n",
171
+ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
172
+ "Note: opening Chrome Inspector may crash demo inside Colab notebooks.\n",
173
+ "\n",
174
+ "To create a public link, set `share=True` in `launch()`.\n"
175
+ ]
176
+ },
177
+ {
178
+ "output_type": "display_data",
179
+ "data": {
180
+ "text/plain": [
181
+ "<IPython.core.display.Javascript object>"
182
+ ],
183
+ "application/javascript": [
184
+ "(async (port, path, width, height, cache, element) => {\n",
185
+ " if (!google.colab.kernel.accessAllowed && !cache) {\n",
186
+ " return;\n",
187
+ " }\n",
188
+ " element.appendChild(document.createTextNode(''));\n",
189
+ " const url = await google.colab.kernel.proxyPort(port, {cache});\n",
190
+ "\n",
191
+ " const external_link = document.createElement('div');\n",
192
+ " external_link.innerHTML = `\n",
193
+ " <div style=\"font-family: monospace; margin-bottom: 0.5rem\">\n",
194
+ " Running on <a href=${new URL(path, url).toString()} target=\"_blank\">\n",
195
+ " https://localhost:${port}${path}\n",
196
+ " </a>\n",
197
+ " </div>\n",
198
+ " `;\n",
199
+ " element.appendChild(external_link);\n",
200
+ "\n",
201
+ " const iframe = document.createElement('iframe');\n",
202
+ " iframe.src = new URL(path, url).toString();\n",
203
+ " iframe.height = height;\n",
204
+ " iframe.allow = \"autoplay; camera; microphone; clipboard-read; clipboard-write;\"\n",
205
+ " iframe.width = width;\n",
206
+ " iframe.style.border = 0;\n",
207
+ " element.appendChild(iframe);\n",
208
+ " })(7860, \"/\", \"100%\", 500, false, window.element)"
209
+ ]
210
+ },
211
+ "metadata": {}
212
+ },
213
+ {
214
+ "output_type": "execute_result",
215
+ "data": {
216
+ "text/plain": []
217
+ },
218
+ "metadata": {},
219
+ "execution_count": 5
220
+ }
221
+ ]
222
+ }
223
+ ]
224
+ }