Youfeng commited on
Commit
6e65adc
1 Parent(s): 271b7d3

Add applicationfiles

Browse files
.ipynb_checkpoints/Untitled-checkpoint.ipynb ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [],
3
+ "metadata": {},
4
+ "nbformat": 4,
5
+ "nbformat_minor": 5
6
+ }
app.ipynb ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 13,
6
+ "id": "11aa3546",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|export\n",
11
+ "import gradio as gr\n",
12
+ "from fastcore.net import urljson, HTTPError"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 14,
18
+ "id": "d14a651d",
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "#|export\n",
23
+ "def size(repo:str):\n",
24
+ " \"Returns the size in GB of a HuggingFace Dataset.\"\n",
25
+ " url = f'https://huggingface.co/api/datasets/{repo}'\n",
26
+ " try: resp = urljson(f'{url}/treesize/main')\n",
27
+ " except HTTPError: return f'Did not find repo: {url}'\n",
28
+ " gb = resp['size'] / 1e9\n",
29
+ " return f'{gb:.2f} GB'"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": 15,
35
+ "id": "4d45b1b7",
36
+ "metadata": {},
37
+ "outputs": [
38
+ {
39
+ "data": {
40
+ "text/plain": [
41
+ "'5.49 GB'"
42
+ ]
43
+ },
44
+ "execution_count": 15,
45
+ "metadata": {},
46
+ "output_type": "execute_result"
47
+ }
48
+ ],
49
+ "source": [
50
+ "size(\"tglcourse/CelebA-faces-cropped-128\")"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 16,
56
+ "id": "b7d2c926",
57
+ "metadata": {},
58
+ "outputs": [
59
+ {
60
+ "name": "stdout",
61
+ "output_type": "stream",
62
+ "text": [
63
+ "Running on local URL: http://127.0.0.1:7860\n",
64
+ "\n",
65
+ "To create a public link, set `share=True` in `launch()`.\n"
66
+ ]
67
+ },
68
+ {
69
+ "data": {
70
+ "text/html": [
71
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"500\" height=\"450\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
72
+ ],
73
+ "text/plain": [
74
+ "<IPython.core.display.HTML object>"
75
+ ]
76
+ },
77
+ "metadata": {},
78
+ "output_type": "display_data"
79
+ },
80
+ {
81
+ "data": {
82
+ "text/plain": [
83
+ "(<gradio.routes.App at 0x16c1daf70>, 'http://127.0.0.1:7860/', None)"
84
+ ]
85
+ },
86
+ "execution_count": 16,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "#|export\n",
93
+ "iface = gr.Interface(fn=size, inputs=gr.Text(value=\"tglcourse/CelebA-faces-cropped-128\"), outputs=\"text\")\n",
94
+ "iface.launch(height=450, width=500)"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 17,
100
+ "id": "a027b638",
101
+ "metadata": {},
102
+ "outputs": [
103
+ {
104
+ "name": "stdout",
105
+ "output_type": "stream",
106
+ "text": [
107
+ "Closing server running on port: 7860\n"
108
+ ]
109
+ }
110
+ ],
111
+ "source": [
112
+ "# this is only necessary in a notebook\n",
113
+ "iface.close()"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "execution_count": 23,
119
+ "id": "28eeace2",
120
+ "metadata": {},
121
+ "outputs": [
122
+ {
123
+ "ename": "TypeError",
124
+ "evalue": "nb_export() got an unexpected keyword argument 'name'",
125
+ "output_type": "error",
126
+ "traceback": [
127
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
128
+ "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
129
+ "\u001b[1;32m/Users/youfeng/nbs/github/hf_demo/app.ipynb Cell 6\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/youfeng/nbs/github/hf_demo/app.ipynb#W5sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mnbdev\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mexport\u001b[39;00m \u001b[39mimport\u001b[39;00m nb_export\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/youfeng/nbs/github/hf_demo/app.ipynb#W5sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m nb_export(\u001b[39m'\u001b[39;49m\u001b[39mapp.ipynb\u001b[39;49m\u001b[39m'\u001b[39;49m, lib_path\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m.\u001b[39;49m\u001b[39m'\u001b[39;49m, name\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mapp\u001b[39;49m\u001b[39m'\u001b[39;49m)\n",
130
+ "\u001b[0;31mTypeError\u001b[0m: nb_export() got an unexpected keyword argument 'name'"
131
+ ]
132
+ }
133
+ ],
134
+ "source": [
135
+ "from nbdev.export import nb_export\n",
136
+ "nb_export('app.ipynb', lib_path='.', name='app')"
137
+ ]
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ "execution_count": 21,
142
+ "id": "3d0a3c97",
143
+ "metadata": {},
144
+ "outputs": [
145
+ {
146
+ "name": "stdout",
147
+ "output_type": "stream",
148
+ "text": [
149
+ "\u001b[0;31mSignature:\u001b[0m\n",
150
+ "\u001b[0mnb_export\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
151
+ "\u001b[0;34m\u001b[0m \u001b[0mnbname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
152
+ "\u001b[0;34m\u001b[0m \u001b[0mlib_path\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
153
+ "\u001b[0;34m\u001b[0m \u001b[0mprocs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m<\u001b[0m\u001b[0mfunction\u001b[0m \u001b[0mblack_format\u001b[0m \u001b[0mat\u001b[0m \u001b[0;36m0x16cbc15e0\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
154
+ "\u001b[0;34m\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
155
+ "\u001b[0;34m\u001b[0m \u001b[0mmod_maker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m<\u001b[0m\u001b[0;32mclass\u001b[0m \u001b[0;34m'nbdev.maker.ModuleMaker'\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
156
+ "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
157
+ "\u001b[0;31mSource:\u001b[0m \n",
158
+ "\u001b[0;32mdef\u001b[0m \u001b[0mnb_export\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnbname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlib_path\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprocs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mblack_format\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmod_maker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mModuleMaker\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
159
+ "\u001b[0;34m\u001b[0m \u001b[0;34m\"Create module(s) from notebook\"\u001b[0m\u001b[0;34m\u001b[0m\n",
160
+ "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlib_path\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlib_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_config\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlib_path\u001b[0m\u001b[0;34m\u001b[0m\n",
161
+ "\u001b[0;34m\u001b[0m \u001b[0mexp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mExportModuleProc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
162
+ "\u001b[0;34m\u001b[0m \u001b[0mnb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNBProcessor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnbname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprocs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
163
+ "\u001b[0;34m\u001b[0m \u001b[0mnb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
164
+ "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcells\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mexp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodules\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
165
+ "\u001b[0;34m\u001b[0m \u001b[0mall_cells\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0min_all\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mmod\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n",
166
+ "\u001b[0;34m\u001b[0m \u001b[0mnm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mifnone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'default_exp'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;34m'#'\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
167
+ "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mnm\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
168
+ "\u001b[0;34m\u001b[0m \u001b[0mwarn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\u001b[0m\u001b[0;34m\u001b[0m\n",
169
+ "\u001b[0;34m\u001b[0m \u001b[0;34m\"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\\n\"\u001b[0m\u001b[0;34m\u001b[0m\n",
170
+ "\u001b[0;34m\u001b[0m \u001b[0;34m\"See https://nbdev.fast.ai/getting_started.html for more information.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
171
+ "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m\u001b[0m\n",
172
+ "\u001b[0;34m\u001b[0m \u001b[0mmm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmod_maker\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdest\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlib_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnb_path\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnbname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mis_new\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;34m'#'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
173
+ "\u001b[0;34m\u001b[0m \u001b[0mmm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcells\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mall_cells\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlib_path\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlib_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
174
+ "\u001b[0;31mFile:\u001b[0m ~/mambaforge/lib/python3.9/site-packages/nbdev/export.py\n",
175
+ "\u001b[0;31mType:\u001b[0m function\n"
176
+ ]
177
+ }
178
+ ],
179
+ "source": [
180
+ "nb_export??"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "execution_count": null,
186
+ "id": "54f49e8b",
187
+ "metadata": {},
188
+ "outputs": [],
189
+ "source": []
190
+ }
191
+ ],
192
+ "metadata": {
193
+ "kernelspec": {
194
+ "display_name": "base",
195
+ "language": "python",
196
+ "name": "python3"
197
+ },
198
+ "language_info": {
199
+ "codemirror_mode": {
200
+ "name": "ipython",
201
+ "version": 3
202
+ },
203
+ "file_extension": ".py",
204
+ "mimetype": "text/x-python",
205
+ "name": "python",
206
+ "nbconvert_exporter": "python",
207
+ "pygments_lexer": "ipython3",
208
+ "version": "3.9.13"
209
+ },
210
+ "vscode": {
211
+ "interpreter": {
212
+ "hash": "93fbf386d2b6859b9885bbb12872af61d24fa1b32a8010b807d9024f580d7b17"
213
+ }
214
+ }
215
+ },
216
+ "nbformat": 4,
217
+ "nbformat_minor": 5
218
+ }
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['iface', 'size']
5
+
6
+ # %% app.ipynb 0
7
+ import gradio as gr
8
+ from fastcore.net import urljson, HTTPError
9
+
10
+ # %% app.ipynb 1
11
+ def size(repo:str):
12
+ "Returns the size in GB of a HuggingFace Dataset."
13
+ url = f'https://huggingface.co/api/datasets/{repo}'
14
+ try: resp = urljson(f'{url}/treesize/main')
15
+ except HTTPError: return f'Did not find repo: {url}'
16
+ gb = resp['size'] / 1e9
17
+ return f'{gb:.2f} GB'
18
+
19
+ # %% app.ipynb 3
20
+ iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
21
+ iface.launch(height=450, width=500)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastcore