arunslb123 commited on
Commit
df4b062
1 Parent(s): a27ffde

Add application files

Browse files
Files changed (3) hide show
  1. app.ipynb +193 -0
  2. app.py +22 -0
  3. requirements.txt +1 -0
app.ipynb ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|export\n",
10
+ "import gradio as gr\n",
11
+ "from fastcore.net import urljson, HTTPError\n"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "def size(repo:str):\n",
22
+ " \"Returns the size in GB of a HuggingFace Dataset.\"\n",
23
+ " url = f'https://huggingface.co/api/datasets/{repo}'\n",
24
+ " try: resp = urljson(f'{url}/treesize/main')\n",
25
+ " except HTTPError: return f'Did not find repo: {url}'\n",
26
+ " gb = resp['size'] / 1e9\n",
27
+ " return f'{gb:.2f} GB'"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 3,
33
+ "metadata": {},
34
+ "outputs": [
35
+ {
36
+ "data": {
37
+ "text/plain": [
38
+ "'5.49 GB'"
39
+ ]
40
+ },
41
+ "execution_count": 3,
42
+ "metadata": {},
43
+ "output_type": "execute_result"
44
+ }
45
+ ],
46
+ "source": [
47
+ "size(\"tglcourse/CelebA-faces-cropped-128\")\n"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": 4,
53
+ "metadata": {},
54
+ "outputs": [
55
+ {
56
+ "name": "stdout",
57
+ "output_type": "stream",
58
+ "text": [
59
+ "Running on local URL: http://127.0.0.1:7860/\n",
60
+ "\n",
61
+ "To create a public link, set `share=True` in `launch()`.\n"
62
+ ]
63
+ },
64
+ {
65
+ "data": {
66
+ "text/html": [
67
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"500\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
68
+ ],
69
+ "text/plain": [
70
+ "<IPython.core.display.HTML object>"
71
+ ]
72
+ },
73
+ "metadata": {},
74
+ "output_type": "display_data"
75
+ },
76
+ {
77
+ "data": {
78
+ "text/plain": [
79
+ "(<gradio.routes.App at 0x12c602d10>, 'http://127.0.0.1:7860/', None)"
80
+ ]
81
+ },
82
+ "execution_count": 4,
83
+ "metadata": {},
84
+ "output_type": "execute_result"
85
+ }
86
+ ],
87
+ "source": [
88
+ "#|export\n",
89
+ "iface = gr.Interface(fn=size, inputs=gr.Text(value=\"tglcourse/CelebA-faces-cropped-128\"), outputs=\"text\")\n",
90
+ "iface.launch(width=500)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 5,
96
+ "metadata": {},
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "Closing server running on port: 7860\n"
103
+ ]
104
+ }
105
+ ],
106
+ "source": [
107
+ "# this is only necessary in a notebook\n",
108
+ "iface.close()"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 6,
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "name": "stdout",
118
+ "output_type": "stream",
119
+ "text": [
120
+ "Overwriting requirements.txt\n"
121
+ ]
122
+ }
123
+ ],
124
+ "source": [
125
+ "%%writefile requirements.txt\n",
126
+ "fastcore"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "execution_count": 9,
132
+ "metadata": {},
133
+ "outputs": [
134
+ {
135
+ "ename": "JSONDecodeError",
136
+ "evalue": "Expecting value: line 1 column 1 (char 0)",
137
+ "output_type": "error",
138
+ "traceback": [
139
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
140
+ "\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)",
141
+ "Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\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----> 2\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",
142
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nbdev/export.py:48\u001b[0m, in \u001b[0;36mnb_export\u001b[0;34m(nbname, lib_path, procs, debug, mod_maker, name)\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[39mif\u001b[39;00m lib_path \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: lib_path \u001b[39m=\u001b[39m get_config()\u001b[39m.\u001b[39mlib_path\n\u001b[1;32m 47\u001b[0m exp \u001b[39m=\u001b[39m ExportModuleProc()\n\u001b[0;32m---> 48\u001b[0m nb \u001b[39m=\u001b[39m NBProcessor(nbname, [exp]\u001b[39m+\u001b[39;49mL(procs), debug\u001b[39m=\u001b[39;49mdebug)\n\u001b[1;32m 49\u001b[0m nb\u001b[39m.\u001b[39mprocess()\n\u001b[1;32m 50\u001b[0m \u001b[39mfor\u001b[39;00m mod,cells \u001b[39min\u001b[39;00m exp\u001b[39m.\u001b[39mmodules\u001b[39m.\u001b[39mitems():\n",
143
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nbdev/process.py:92\u001b[0m, in \u001b[0;36mNBProcessor.__init__\u001b[0;34m(self, path, procs, nb, debug, rm_directives, process)\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\u001b[39mself\u001b[39m, path\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, procs\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, nb\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, debug\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m, rm_directives\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m, process\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m):\n\u001b[0;32m---> 92\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnb \u001b[39m=\u001b[39m read_nb(path) \u001b[39mif\u001b[39;00m nb \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m nb\n\u001b[1;32m 93\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlang \u001b[39m=\u001b[39m nb_lang(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnb)\n\u001b[1;32m 94\u001b[0m \u001b[39mfor\u001b[39;00m cell \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnb\u001b[39m.\u001b[39mcells: cell\u001b[39m.\u001b[39mdirectives_ \u001b[39m=\u001b[39m extract_directives(cell, remove\u001b[39m=\u001b[39mrm_directives, lang\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlang)\n",
144
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/execnb/nbio.py:57\u001b[0m, in \u001b[0;36mread_nb\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mread_nb\u001b[39m(path):\n\u001b[1;32m 56\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mReturn notebook at `path`\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m---> 57\u001b[0m res \u001b[39m=\u001b[39m dict2nb(_read_json(path, encoding\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mutf-8\u001b[39;49m\u001b[39m'\u001b[39;49m))\n\u001b[1;32m 58\u001b[0m res[\u001b[39m'\u001b[39m\u001b[39mpath_\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(path)\n\u001b[1;32m 59\u001b[0m \u001b[39mreturn\u001b[39;00m res\n",
145
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/execnb/nbio.py:16\u001b[0m, in \u001b[0;36m_read_json\u001b[0;34m(self, encoding, errors)\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_read_json\u001b[39m(\u001b[39mself\u001b[39m, encoding\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, errors\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m):\n\u001b[0;32m---> 16\u001b[0m \u001b[39mreturn\u001b[39;00m loads(Path(\u001b[39mself\u001b[39;49m)\u001b[39m.\u001b[39;49mread_text(encoding\u001b[39m=\u001b[39;49mencoding, errors\u001b[39m=\u001b[39;49merrors))\n",
146
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py:346\u001b[0m, in \u001b[0;36mloads\u001b[0;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m 341\u001b[0m s \u001b[39m=\u001b[39m s\u001b[39m.\u001b[39mdecode(detect_encoding(s), \u001b[39m'\u001b[39m\u001b[39msurrogatepass\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m 343\u001b[0m \u001b[39mif\u001b[39;00m (\u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m object_hook \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m\n\u001b[1;32m 344\u001b[0m parse_int \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m parse_float \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m\n\u001b[1;32m 345\u001b[0m parse_constant \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m object_pairs_hook \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m kw):\n\u001b[0;32m--> 346\u001b[0m \u001b[39mreturn\u001b[39;00m _default_decoder\u001b[39m.\u001b[39;49mdecode(s)\n\u001b[1;32m 347\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 348\u001b[0m \u001b[39mcls\u001b[39m \u001b[39m=\u001b[39m JSONDecoder\n",
147
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py:337\u001b[0m, in \u001b[0;36mJSONDecoder.decode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m 332\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdecode\u001b[39m(\u001b[39mself\u001b[39m, s, _w\u001b[39m=\u001b[39mWHITESPACE\u001b[39m.\u001b[39mmatch):\n\u001b[1;32m 333\u001b[0m \u001b[39m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001b[39;00m\n\u001b[1;32m 334\u001b[0m \u001b[39m containing a JSON document).\u001b[39;00m\n\u001b[1;32m 335\u001b[0m \n\u001b[1;32m 336\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 337\u001b[0m obj, end \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mraw_decode(s, idx\u001b[39m=\u001b[39;49m_w(s, \u001b[39m0\u001b[39;49m)\u001b[39m.\u001b[39;49mend())\n\u001b[1;32m 338\u001b[0m end \u001b[39m=\u001b[39m _w(s, end)\u001b[39m.\u001b[39mend()\n\u001b[1;32m 339\u001b[0m \u001b[39mif\u001b[39;00m end \u001b[39m!=\u001b[39m \u001b[39mlen\u001b[39m(s):\n",
148
+ "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py:355\u001b[0m, in \u001b[0;36mJSONDecoder.raw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m 353\u001b[0m obj, end \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mscan_once(s, idx)\n\u001b[1;32m 354\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mStopIteration\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[0;32m--> 355\u001b[0m \u001b[39mraise\u001b[39;00m JSONDecodeError(\u001b[39m\"\u001b[39m\u001b[39mExpecting value\u001b[39m\u001b[39m\"\u001b[39m, s, err\u001b[39m.\u001b[39mvalue) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[1;32m 356\u001b[0m \u001b[39mreturn\u001b[39;00m obj, end\n",
149
+ "\u001b[0;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)"
150
+ ]
151
+ }
152
+ ],
153
+ "source": [
154
+ "from nbdev.export import nb_export\n",
155
+ "nb_export('app.ipynb', lib_path='.', name='app')"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": null,
161
+ "metadata": {},
162
+ "outputs": [],
163
+ "source": []
164
+ }
165
+ ],
166
+ "metadata": {
167
+ "kernelspec": {
168
+ "display_name": "Python 3.10.4 64-bit",
169
+ "language": "python",
170
+ "name": "python3"
171
+ },
172
+ "language_info": {
173
+ "codemirror_mode": {
174
+ "name": "ipython",
175
+ "version": 3
176
+ },
177
+ "file_extension": ".py",
178
+ "mimetype": "text/x-python",
179
+ "name": "python",
180
+ "nbconvert_exporter": "python",
181
+ "pygments_lexer": "ipython3",
182
+ "version": "3.10.4"
183
+ },
184
+ "orig_nbformat": 4,
185
+ "vscode": {
186
+ "interpreter": {
187
+ "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
188
+ }
189
+ }
190
+ },
191
+ "nbformat": 4,
192
+ "nbformat_minor": 2
193
+ }
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
11
+ # %% app.ipynb 1
12
+ def size(repo:str):
13
+ "Returns the size in GB of a HuggingFace Dataset."
14
+ url = f'https://huggingface.co/api/datasets/{repo}'
15
+ try: resp = urljson(f'{url}/treesize/main')
16
+ except HTTPError: return f'Did not find repo: {url}'
17
+ gb = resp['size'] / 1e9
18
+ return f'{gb:.2f} GB'
19
+
20
+ # %% app.ipynb 3
21
+ iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
22
+ iface.launch(width=500)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastcore