Spaces:
Sleeping
Sleeping
Upload 3 files
Browse filesCheck the new exports
- app.ipynb +45 -55
- app.py +1 -1
- requirements.txt +1 -2
app.ipynb
CHANGED
@@ -9,7 +9,12 @@
|
|
9 |
"\n",
|
10 |
"> A demo of using nbdev with Hugging Face Spaces & Gradio\n",
|
11 |
"\n",
|
12 |
-
"[
|
|
|
|
|
|
|
|
|
|
|
13 |
"\n",
|
14 |
"[![<a href=\"https://huggingface.co/spaces/hamel/hfspace_demo\">A Gradio app</a> that shows the size of a HF Dataset.](final_app.png)](https://huggingface.co/spaces/hamel/hfspace_demo)\n",
|
15 |
"\n",
|
@@ -81,7 +86,7 @@
|
|
81 |
},
|
82 |
{
|
83 |
"cell_type": "code",
|
84 |
-
"execution_count":
|
85 |
"id": "e5e5d597-19ad-46e5-81ad-8f646d8a1c21",
|
86 |
"metadata": {},
|
87 |
"outputs": [],
|
@@ -101,7 +106,7 @@
|
|
101 |
},
|
102 |
{
|
103 |
"cell_type": "code",
|
104 |
-
"execution_count":
|
105 |
"id": "38a4389f-ef53-4626-a6f5-a859354f854b",
|
106 |
"metadata": {},
|
107 |
"outputs": [],
|
@@ -128,7 +133,7 @@
|
|
128 |
},
|
129 |
{
|
130 |
"cell_type": "code",
|
131 |
-
"execution_count":
|
132 |
"id": "95bc32b8-d8ff-4761-a2d7-0880c51d0a42",
|
133 |
"metadata": {},
|
134 |
"outputs": [
|
@@ -138,7 +143,7 @@
|
|
138 |
"'5.49 GB'"
|
139 |
]
|
140 |
},
|
141 |
-
"execution_count":
|
142 |
"metadata": {},
|
143 |
"output_type": "execute_result"
|
144 |
}
|
@@ -157,7 +162,7 @@
|
|
157 |
},
|
158 |
{
|
159 |
"cell_type": "code",
|
160 |
-
"execution_count":
|
161 |
"id": "7b20e2a1-b622-4970-9069-0202ce10a2ce",
|
162 |
"metadata": {},
|
163 |
"outputs": [
|
@@ -185,10 +190,10 @@
|
|
185 |
{
|
186 |
"data": {
|
187 |
"text/plain": [
|
188 |
-
"(<gradio.routes.App
|
189 |
]
|
190 |
},
|
191 |
-
"execution_count":
|
192 |
"metadata": {},
|
193 |
"output_type": "execute_result"
|
194 |
}
|
@@ -209,7 +214,7 @@
|
|
209 |
},
|
210 |
{
|
211 |
"cell_type": "code",
|
212 |
-
"execution_count":
|
213 |
"id": "39d7be72-9389-42cf-91b1-78e8f4bbd083",
|
214 |
"metadata": {},
|
215 |
"outputs": [
|
@@ -239,7 +244,7 @@
|
|
239 |
},
|
240 |
{
|
241 |
"cell_type": "code",
|
242 |
-
"execution_count":
|
243 |
"id": "6706d92c-5785-4f09-9773-b9a944c493a5",
|
244 |
"metadata": {},
|
245 |
"outputs": [],
|
@@ -266,36 +271,38 @@
|
|
266 |
},
|
267 |
{
|
268 |
"cell_type": "code",
|
269 |
-
"execution_count":
|
270 |
"id": "4bae6a5c-58bc-4a0f-9aac-34c092150fdc",
|
271 |
"metadata": {},
|
272 |
"outputs": [
|
273 |
{
|
274 |
-
"
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
299 |
}
|
300 |
],
|
301 |
"source": [
|
@@ -314,7 +321,7 @@
|
|
314 |
},
|
315 |
{
|
316 |
"cell_type": "code",
|
317 |
-
"execution_count":
|
318 |
"id": "0b611d9c-d262-4124-9e9e-4fe754ac4378",
|
319 |
"metadata": {},
|
320 |
"outputs": [
|
@@ -390,26 +397,9 @@
|
|
390 |
],
|
391 |
"metadata": {
|
392 |
"kernelspec": {
|
393 |
-
"display_name": "Python 3
|
394 |
"language": "python",
|
395 |
"name": "python3"
|
396 |
-
},
|
397 |
-
"language_info": {
|
398 |
-
"codemirror_mode": {
|
399 |
-
"name": "ipython",
|
400 |
-
"version": 3
|
401 |
-
},
|
402 |
-
"file_extension": ".py",
|
403 |
-
"mimetype": "text/x-python",
|
404 |
-
"name": "python",
|
405 |
-
"nbconvert_exporter": "python",
|
406 |
-
"pygments_lexer": "ipython3",
|
407 |
-
"version": "3.9.13"
|
408 |
-
},
|
409 |
-
"vscode": {
|
410 |
-
"interpreter": {
|
411 |
-
"hash": "2cb9b8e4ba0e26b1cdc35fa509fd363b1c45cea0b423b3e9d0e061db9bbef286"
|
412 |
-
}
|
413 |
}
|
414 |
},
|
415 |
"nbformat": 4,
|
|
|
9 |
"\n",
|
10 |
"> A demo of using nbdev with Hugging Face Spaces & Gradio\n",
|
11 |
"\n",
|
12 |
+
"![Image created with Stable Diffusion from [this space](https://huggingface.co/spaces/stabilityai/stable-diffusion)](blog_cover.jpeg)\n",
|
13 |
+
"\n",
|
14 |
+
"[Hugging Face Spaces](https://huggingface.co/spaces/launch) provides an easy ways to deploy a web app with python. [Gradio](https://gradio.app/) is one of my favorite tools for building these web apps. Gradio allows you to prototype your web apps in notebooks which allow you to iterate fast. However, Hugging Face Spaces requires you to package your web application code as a python script named `app.py`. \n",
|
15 |
+
"\n",
|
16 |
+
"\n",
|
17 |
+
"However, **thanks to [nbdev](https://nbdev.fast.ai) you can deploy a Gradio app to Spaces from a notebook without having to refactor your code into a script!**, When you finish this tutorial, you will have an app that looks like this:\n",
|
18 |
"\n",
|
19 |
"[![<a href=\"https://huggingface.co/spaces/hamel/hfspace_demo\">A Gradio app</a> that shows the size of a HF Dataset.](final_app.png)](https://huggingface.co/spaces/hamel/hfspace_demo)\n",
|
20 |
"\n",
|
|
|
86 |
},
|
87 |
{
|
88 |
"cell_type": "code",
|
89 |
+
"execution_count": null,
|
90 |
"id": "e5e5d597-19ad-46e5-81ad-8f646d8a1c21",
|
91 |
"metadata": {},
|
92 |
"outputs": [],
|
|
|
106 |
},
|
107 |
{
|
108 |
"cell_type": "code",
|
109 |
+
"execution_count": null,
|
110 |
"id": "38a4389f-ef53-4626-a6f5-a859354f854b",
|
111 |
"metadata": {},
|
112 |
"outputs": [],
|
|
|
133 |
},
|
134 |
{
|
135 |
"cell_type": "code",
|
136 |
+
"execution_count": null,
|
137 |
"id": "95bc32b8-d8ff-4761-a2d7-0880c51d0a42",
|
138 |
"metadata": {},
|
139 |
"outputs": [
|
|
|
143 |
"'5.49 GB'"
|
144 |
]
|
145 |
},
|
146 |
+
"execution_count": null,
|
147 |
"metadata": {},
|
148 |
"output_type": "execute_result"
|
149 |
}
|
|
|
162 |
},
|
163 |
{
|
164 |
"cell_type": "code",
|
165 |
+
"execution_count": null,
|
166 |
"id": "7b20e2a1-b622-4970-9069-0202ce10a2ce",
|
167 |
"metadata": {},
|
168 |
"outputs": [
|
|
|
190 |
{
|
191 |
"data": {
|
192 |
"text/plain": [
|
193 |
+
"(<gradio.routes.App>, 'http://127.0.0.1:7861/', None)"
|
194 |
]
|
195 |
},
|
196 |
+
"execution_count": null,
|
197 |
"metadata": {},
|
198 |
"output_type": "execute_result"
|
199 |
}
|
|
|
214 |
},
|
215 |
{
|
216 |
"cell_type": "code",
|
217 |
+
"execution_count": null,
|
218 |
"id": "39d7be72-9389-42cf-91b1-78e8f4bbd083",
|
219 |
"metadata": {},
|
220 |
"outputs": [
|
|
|
244 |
},
|
245 |
{
|
246 |
"cell_type": "code",
|
247 |
+
"execution_count": null,
|
248 |
"id": "6706d92c-5785-4f09-9773-b9a944c493a5",
|
249 |
"metadata": {},
|
250 |
"outputs": [],
|
|
|
271 |
},
|
272 |
{
|
273 |
"cell_type": "code",
|
274 |
+
"execution_count": null,
|
275 |
"id": "4bae6a5c-58bc-4a0f-9aac-34c092150fdc",
|
276 |
"metadata": {},
|
277 |
"outputs": [
|
278 |
{
|
279 |
+
"data": {
|
280 |
+
"text/plain": [
|
281 |
+
"\u001b[0;31m# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.\u001b[0m\u001b[0;34m\u001b[0m\n",
|
282 |
+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
|
283 |
+
"\u001b[0;34m\u001b[0m\u001b[0;31m# %% auto 0\u001b[0m\u001b[0;34m\u001b[0m\n",
|
284 |
+
"\u001b[0;34m\u001b[0m\u001b[0m__all__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'iface'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'size'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n",
|
285 |
+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
|
286 |
+
"\u001b[0;34m\u001b[0m\u001b[0;31m# %% app.ipynb 6\u001b[0m\u001b[0;34m\u001b[0m\n",
|
287 |
+
"\u001b[0;34m\u001b[0m\u001b[0;32mimport\u001b[0m \u001b[0mgradio\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m\u001b[0m\n",
|
288 |
+
"\u001b[0;34m\u001b[0m\u001b[0;32mfrom\u001b[0m \u001b[0mfastcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnet\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0murljson\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m\u001b[0m\n",
|
289 |
+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
|
290 |
+
"\u001b[0;34m\u001b[0m\u001b[0;31m# %% app.ipynb 8\u001b[0m\u001b[0;34m\u001b[0m\n",
|
291 |
+
"\u001b[0;34m\u001b[0m\u001b[0;32mdef\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepo\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
|
292 |
+
"\u001b[0;34m\u001b[0m \u001b[0;34m\"Returns the size in GB of a HuggingFace Dataset.\"\u001b[0m\u001b[0;34m\u001b[0m\n",
|
293 |
+
"\u001b[0;34m\u001b[0m \u001b[0murl\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mf'https://huggingface.co/api/datasets/{repo}'\u001b[0m\u001b[0;34m\u001b[0m\n",
|
294 |
+
"\u001b[0;34m\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mresp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0murljson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf'{url}/treesize/main'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
|
295 |
+
"\u001b[0;34m\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34mf'Did not find repo: {url}'\u001b[0m\u001b[0;34m\u001b[0m\n",
|
296 |
+
"\u001b[0;34m\u001b[0m \u001b[0mgb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'size'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m1e9\u001b[0m\u001b[0;34m\u001b[0m\n",
|
297 |
+
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34mf'{gb:.2f} GB'\u001b[0m\u001b[0;34m\u001b[0m\n",
|
298 |
+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
|
299 |
+
"\u001b[0;34m\u001b[0m\u001b[0;31m# %% app.ipynb 12\u001b[0m\u001b[0;34m\u001b[0m\n",
|
300 |
+
"\u001b[0;34m\u001b[0m\u001b[0miface\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mInterface\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msize\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mText\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"tglcourse/CelebA-faces-cropped-128\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"text\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
|
301 |
+
"\u001b[0;34m\u001b[0m\u001b[0miface\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlaunch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mheight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m450\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwidth\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m500\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n"
|
302 |
+
]
|
303 |
+
},
|
304 |
+
"metadata": {},
|
305 |
+
"output_type": "display_data"
|
306 |
}
|
307 |
],
|
308 |
"source": [
|
|
|
321 |
},
|
322 |
{
|
323 |
"cell_type": "code",
|
324 |
+
"execution_count": null,
|
325 |
"id": "0b611d9c-d262-4124-9e9e-4fe754ac4378",
|
326 |
"metadata": {},
|
327 |
"outputs": [
|
|
|
397 |
],
|
398 |
"metadata": {
|
399 |
"kernelspec": {
|
400 |
+
"display_name": "Python 3 (ipykernel)",
|
401 |
"language": "python",
|
402 |
"name": "python3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
}
|
404 |
},
|
405 |
"nbformat": 4,
|
app.py
CHANGED
@@ -18,4 +18,4 @@ def size(repo:str):
|
|
18 |
|
19 |
# %% app.ipynb 12
|
20 |
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
21 |
-
iface.launch(height=450, width=500)
|
|
|
18 |
|
19 |
# %% app.ipynb 12
|
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
CHANGED
@@ -1,2 +1 @@
|
|
1 |
-
fastcore
|
2 |
-
|
|
|
1 |
+
fastcore
|
|