Catherine ZHOU commited on
Commit
1089e3f
·
1 Parent(s): 26107d6

add notebooks

Browse files
Files changed (3) hide show
  1. app.py +3 -1
  2. notebooks/01-hello-word.ipynb +91 -0
  3. notebooks/02-gpt-j.ipynb +251 -0
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import gradio as gr
2
 
 
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
  import gradio as gr
2
 
3
+ # HELLO WORLD
4
+
5
  def greet(name):
6
  return "Hello " + name + "!!"
7
 
8
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
+ iface.launch()
notebooks/01-hello-word.ipynb ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "# TRIAL 1: HELLO WORLD\n",
9
+ "\n",
10
+ "Lastest Update @ Apr 2, 2022"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 1,
16
+ "metadata": {},
17
+ "outputs": [],
18
+ "source": [
19
+ "# IMPORTS\n",
20
+ "\n",
21
+ "import gradio as gr"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 2,
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "name": "stdout",
31
+ "output_type": "stream",
32
+ "text": [
33
+ "Running on local URL: http://127.0.0.1:7860\n",
34
+ "\n",
35
+ "To create a public link, set `share=True` in `launch()`.\n"
36
+ ]
37
+ },
38
+ {
39
+ "data": {
40
+ "text/html": [
41
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
42
+ ],
43
+ "text/plain": [
44
+ "<IPython.core.display.HTML object>"
45
+ ]
46
+ },
47
+ "metadata": {},
48
+ "output_type": "display_data"
49
+ },
50
+ {
51
+ "data": {
52
+ "text/plain": []
53
+ },
54
+ "execution_count": 2,
55
+ "metadata": {},
56
+ "output_type": "execute_result"
57
+ }
58
+ ],
59
+ "source": [
60
+ "def greet(name):\n",
61
+ " return \"Hello \" + name + \"!!\"\n",
62
+ "\n",
63
+ "\n",
64
+ "iface = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n",
65
+ "iface.launch()\n"
66
+ ]
67
+ }
68
+ ],
69
+ "metadata": {
70
+ "kernelspec": {
71
+ "display_name": "base",
72
+ "language": "python",
73
+ "name": "python3"
74
+ },
75
+ "language_info": {
76
+ "codemirror_mode": {
77
+ "name": "ipython",
78
+ "version": 3
79
+ },
80
+ "file_extension": ".py",
81
+ "mimetype": "text/x-python",
82
+ "name": "python",
83
+ "nbconvert_exporter": "python",
84
+ "pygments_lexer": "ipython3",
85
+ "version": "3.10.9"
86
+ },
87
+ "orig_nbformat": 4
88
+ },
89
+ "nbformat": 4,
90
+ "nbformat_minor": 2
91
+ }
notebooks/02-gpt-j.ipynb ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "# TIRAL 2: GPT-J\n",
9
+ "\n",
10
+ "Link: https://huggingface.co/course/chapter9/5?fw=pt\n",
11
+ "\n",
12
+ "Lastest Update Date: Apr. 2, 2023\n",
13
+ "\n",
14
+ "## Loading models from the Hugging Face Hub"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 1,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "# IMPORTS\n",
24
+ "\n",
25
+ "import gradio as gr"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 2,
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stderr",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "/Users/zhilinzhou/anaconda3/lib/python3.10/site-packages/gradio/interface.py:93: UserWarning: gr.Intrerface.load() will be deprecated. Use gr.load() instead.\n",
38
+ " warnings.warn(\"gr.Intrerface.load() will be deprecated. Use gr.load() instead.\")\n"
39
+ ]
40
+ },
41
+ {
42
+ "name": "stdout",
43
+ "output_type": "stream",
44
+ "text": [
45
+ "Fetching model from: https://huggingface.co/EleutherAI/gpt-j-6B\n"
46
+ ]
47
+ },
48
+ {
49
+ "name": "stderr",
50
+ "output_type": "stream",
51
+ "text": [
52
+ "/Users/zhilinzhou/anaconda3/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `enable_queue` is deprecated in `Interface()`, please use it within `launch()` instead.\n",
53
+ " warnings.warn(value)\n"
54
+ ]
55
+ },
56
+ {
57
+ "name": "stdout",
58
+ "output_type": "stream",
59
+ "text": [
60
+ "Running on local URL: http://127.0.0.1:7861\n",
61
+ "\n",
62
+ "To create a public link, set `share=True` in `launch()`.\n"
63
+ ]
64
+ },
65
+ {
66
+ "data": {
67
+ "text/html": [
68
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
69
+ ],
70
+ "text/plain": [
71
+ "<IPython.core.display.HTML object>"
72
+ ]
73
+ },
74
+ "metadata": {},
75
+ "output_type": "display_data"
76
+ },
77
+ {
78
+ "data": {
79
+ "text/plain": []
80
+ },
81
+ "execution_count": 2,
82
+ "metadata": {},
83
+ "output_type": "execute_result"
84
+ }
85
+ ],
86
+ "source": [
87
+ "title = \"GPT-J-6B\"\n",
88
+ "description = \"Gradio Demo for GPT-J 6B, a transformer model trained using Ben Wang's Mesh Transformer JAX. 'GPT-J' refers to the class of model, while '6B' represents the number of trainable parameters. To use it, simply add your text, or click one of the examples to load them. Read more at the links below.\"\n",
89
+ "article = \"<p style='text-align: center'><a href='https://github.com/kingoflolz/mesh-transformer-jax' target='_blank'>GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model</a></p>\"\n",
90
+ "examples = [\n",
91
+ " [\"The tower is 324 metres (1,063 ft) tall,\"],\n",
92
+ " [\"The Moon's orbit around Earth has\"],\n",
93
+ " [\"The smooth Borealis basin in the Northern Hemisphere covers 40%\"],\n",
94
+ "]\n",
95
+ "gr.load(\n",
96
+ " \"huggingface/EleutherAI/gpt-j-6B\",\n",
97
+ " inputs=gr.Textbox(lines=5, label=\"Input Text\"),\n",
98
+ " title=title,\n",
99
+ " description=description,\n",
100
+ " article=article,\n",
101
+ " examples=examples,\n",
102
+ " enable_queue=True,\n",
103
+ ").launch()"
104
+ ]
105
+ },
106
+ {
107
+ "attachments": {},
108
+ "cell_type": "markdown",
109
+ "metadata": {},
110
+ "source": [
111
+ "## Loading from Hugging Face Spaces\n"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 3,
117
+ "metadata": {},
118
+ "outputs": [
119
+ {
120
+ "name": "stderr",
121
+ "output_type": "stream",
122
+ "text": [
123
+ "/Users/zhilinzhou/anaconda3/lib/python3.10/site-packages/gradio/interface.py:93: UserWarning: gr.Intrerface.load() will be deprecated. Use gr.load() instead.\n",
124
+ " warnings.warn(\"gr.Intrerface.load() will be deprecated. Use gr.load() instead.\")\n"
125
+ ]
126
+ },
127
+ {
128
+ "name": "stdout",
129
+ "output_type": "stream",
130
+ "text": [
131
+ "Fetching Space from: https://huggingface.co/spaces/abidlabs/remove-bg\n",
132
+ "Loaded as API: https://abidlabs-remove-bg.hf.space ✔\n",
133
+ "Running on local URL: http://127.0.0.1:7862\n",
134
+ "\n",
135
+ "To create a public link, set `share=True` in `launch()`.\n"
136
+ ]
137
+ },
138
+ {
139
+ "data": {
140
+ "text/html": [
141
+ "<div><iframe src=\"http://127.0.0.1:7862/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
142
+ ],
143
+ "text/plain": [
144
+ "<IPython.core.display.HTML object>"
145
+ ]
146
+ },
147
+ "metadata": {},
148
+ "output_type": "display_data"
149
+ },
150
+ {
151
+ "data": {
152
+ "text/plain": []
153
+ },
154
+ "execution_count": 3,
155
+ "metadata": {},
156
+ "output_type": "execute_result"
157
+ }
158
+ ],
159
+ "source": [
160
+ "gr.Interface.load(\"spaces/abidlabs/remove-bg\").launch()\n"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 4,
166
+ "metadata": {},
167
+ "outputs": [
168
+ {
169
+ "name": "stderr",
170
+ "output_type": "stream",
171
+ "text": [
172
+ "/Users/zhilinzhou/anaconda3/lib/python3.10/site-packages/gradio/interface.py:93: UserWarning: gr.Intrerface.load() will be deprecated. Use gr.load() instead.\n",
173
+ " warnings.warn(\"gr.Intrerface.load() will be deprecated. Use gr.load() instead.\")\n"
174
+ ]
175
+ },
176
+ {
177
+ "name": "stdout",
178
+ "output_type": "stream",
179
+ "text": [
180
+ "Fetching Space from: https://huggingface.co/spaces/abidlabs/remove-bg\n"
181
+ ]
182
+ },
183
+ {
184
+ "name": "stderr",
185
+ "output_type": "stream",
186
+ "text": [
187
+ "/Users/zhilinzhou/anaconda3/lib/python3.10/site-packages/gradio/external.py:445: UserWarning: You cannot override parameters for this Space by passing in kwargs. Instead, please load the Space as a function and use it to create a Blocks or Interface locally. You may find this Guide helpful: https://gradio.app/using_blocks_like_functions/\n",
188
+ " warnings.warn(\n"
189
+ ]
190
+ },
191
+ {
192
+ "name": "stdout",
193
+ "output_type": "stream",
194
+ "text": [
195
+ "Loaded as API: https://abidlabs-remove-bg.hf.space ✔\n",
196
+ "Running on local URL: http://127.0.0.1:7863\n",
197
+ "\n",
198
+ "To create a public link, set `share=True` in `launch()`.\n"
199
+ ]
200
+ },
201
+ {
202
+ "data": {
203
+ "text/html": [
204
+ "<div><iframe src=\"http://127.0.0.1:7863/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
205
+ ],
206
+ "text/plain": [
207
+ "<IPython.core.display.HTML object>"
208
+ ]
209
+ },
210
+ "metadata": {},
211
+ "output_type": "display_data"
212
+ },
213
+ {
214
+ "data": {
215
+ "text/plain": []
216
+ },
217
+ "execution_count": 4,
218
+ "metadata": {},
219
+ "output_type": "execute_result"
220
+ }
221
+ ],
222
+ "source": [
223
+ "gr.Interface.load(\n",
224
+ " \"spaces/abidlabs/remove-bg\", inputs=\"webcam\", title=\"Remove your webcam background!\"\n",
225
+ ").launch()\n"
226
+ ]
227
+ }
228
+ ],
229
+ "metadata": {
230
+ "kernelspec": {
231
+ "display_name": "base",
232
+ "language": "python",
233
+ "name": "python3"
234
+ },
235
+ "language_info": {
236
+ "codemirror_mode": {
237
+ "name": "ipython",
238
+ "version": 3
239
+ },
240
+ "file_extension": ".py",
241
+ "mimetype": "text/x-python",
242
+ "name": "python",
243
+ "nbconvert_exporter": "python",
244
+ "pygments_lexer": "ipython3",
245
+ "version": "3.10.9"
246
+ },
247
+ "orig_nbformat": 4
248
+ },
249
+ "nbformat": 4,
250
+ "nbformat_minor": 2
251
+ }