Spaces:
Runtime error
Runtime error
Add application files
Browse files
README.md
CHANGED
|
@@ -12,7 +12,7 @@ license: mit
|
|
| 12 |
|
| 13 |
<!-- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference --># Hugging Face Spaces From A Notebook
|
| 14 |
|
| 15 |
-
> A demo of using nbdev with Hugging Face Spaces
|
| 16 |
|
| 17 |
## 1. Create a Gradio-enabled Space on Hugging Face
|
| 18 |
|
|
@@ -24,7 +24,7 @@ After you are done creating the space, **clone the repo per the instructions pro
|
|
| 24 |
|
| 25 |
## 2. Make an app with Gradio
|
| 26 |
|
| 27 |
-
Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces).
|
| 28 |
|
| 29 |
First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:
|
| 30 |
|
|
@@ -35,6 +35,8 @@ import gradio as gr
|
|
| 35 |
from fastcore.net import urljson, HTTPError
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
| 38 |
|
| 39 |
```
|
| 40 |
#|export
|
|
@@ -101,7 +103,7 @@ iface.close()
|
|
| 101 |
|
| 102 |
## 3. Converting This Notebook Into A Gradio App
|
| 103 |
|
| 104 |
-
In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`.
|
| 105 |
|
| 106 |
|
| 107 |
```
|
|
@@ -154,7 +156,7 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
| 154 |
|
| 155 |
### Fill out `requirements.txt`
|
| 156 |
|
| 157 |
-
You must supply a requirements.txt file so the
|
| 158 |
|
| 159 |
|
| 160 |
```
|
|
@@ -165,7 +167,7 @@ You must supply a requirements.txt file so the gradio app knows how to build you
|
|
| 165 |
|
| 166 |
## 4. Launch Your Gradio App
|
| 167 |
|
| 168 |
-
To launch your gradio app, you need to commit the changes
|
| 169 |
|
| 170 |
```
|
| 171 |
git add -A; git commit -m "Add application files"; git push
|
|
@@ -175,6 +177,10 @@ git add -A; git commit -m "Add application files"; git push
|
|
| 175 |
|
| 176 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
```
|
| 180 |
|
|
|
|
| 12 |
|
| 13 |
<!-- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference --># Hugging Face Spaces From A Notebook
|
| 14 |
|
| 15 |
+
> A demo of using nbdev with Hugging Face Spaces & Gradio
|
| 16 |
|
| 17 |
## 1. Create a Gradio-enabled Space on Hugging Face
|
| 18 |
|
|
|
|
| 24 |
|
| 25 |
## 2. Make an app with Gradio
|
| 26 |
|
| 27 |
+
Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces).
|
| 28 |
|
| 29 |
First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:
|
| 30 |
|
|
|
|
| 35 |
from fastcore.net import urljson, HTTPError
|
| 36 |
```
|
| 37 |
|
| 38 |
+
Next, write the functions your gradio app will use. Because of [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/), you can prototype and package your code all in one place. **The special comment `#|export` marks which cells will be sent to a python script** (more on this later). Note that there are only three cells in this notebook with the `#|export` directive.
|
| 39 |
+
|
| 40 |
|
| 41 |
```
|
| 42 |
#|export
|
|
|
|
| 103 |
|
| 104 |
## 3. Converting This Notebook Into A Gradio App
|
| 105 |
|
| 106 |
+
In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`. As a reminder, this is what the special `#|export` comment that you have seen in cells above do! You can export code from this notebook like so:
|
| 107 |
|
| 108 |
|
| 109 |
```
|
|
|
|
| 156 |
|
| 157 |
### Fill out `requirements.txt`
|
| 158 |
|
| 159 |
+
You must supply a requirements.txt file so the Gradio app knows how to build your dependencies. In this example, the only dependency other than Gradio is `fastcore`. You don't need to specify Gradio itself as a dependency in `requirements.txt`, so our `requirements.txt` file has only one dependency:
|
| 160 |
|
| 161 |
|
| 162 |
```
|
|
|
|
| 167 |
|
| 168 |
## 4. Launch Your Gradio App
|
| 169 |
|
| 170 |
+
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
| 171 |
|
| 172 |
```
|
| 173 |
git add -A; git commit -m "Add application files"; git push
|
|
|
|
| 177 |
|
| 178 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
| 179 |
|
| 180 |
+
# Shameless Plug: [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)
|
| 181 |
+
|
| 182 |
+
Hopefully you felt something magical while doing this example. Even though the target application required you to write a python script (`app.py`), you didn't have to refactor your script from a notebook! We believe that you shouldn't have to refactor your code and switch contexts even when creating python packages! If this intrigues you, check out [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)
|
| 183 |
+
|
| 184 |
|
| 185 |
```
|
| 186 |
|
app.ipynb
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
"source": [
|
| 8 |
"# Hugging Face Spaces From A Notebook\n",
|
| 9 |
"\n",
|
| 10 |
-
"> A demo of using nbdev with Hugging Face Spaces"
|
| 11 |
]
|
| 12 |
},
|
| 13 |
{
|
|
@@ -54,7 +54,7 @@
|
|
| 54 |
"id": "14a884fc-36e2-43ec-8e42-ca2903aaa4de",
|
| 55 |
"metadata": {},
|
| 56 |
"source": [
|
| 57 |
-
"Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces)
|
| 58 |
"\n",
|
| 59 |
"First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:"
|
| 60 |
]
|
|
@@ -71,6 +71,14 @@
|
|
| 71 |
"from fastcore.net import urljson, HTTPError"
|
| 72 |
]
|
| 73 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
{
|
| 75 |
"cell_type": "code",
|
| 76 |
"execution_count": null,
|
|
@@ -211,7 +219,7 @@
|
|
| 211 |
"id": "5c18ca6e-8de8-49e1-b95a-304070bbc171",
|
| 212 |
"metadata": {},
|
| 213 |
"source": [
|
| 214 |
-
"In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`.
|
| 215 |
]
|
| 216 |
},
|
| 217 |
{
|
|
@@ -303,7 +311,7 @@
|
|
| 303 |
"source": [
|
| 304 |
"### Fill out `requirements.txt`\n",
|
| 305 |
"\n",
|
| 306 |
-
"You must supply a requirements.txt file so the
|
| 307 |
]
|
| 308 |
},
|
| 309 |
{
|
|
@@ -331,7 +339,7 @@
|
|
| 331 |
"source": [
|
| 332 |
"## 4. Launch Your Gradio App\n",
|
| 333 |
"\n",
|
| 334 |
-
"To launch your gradio app, you need to commit the changes
|
| 335 |
"\n",
|
| 336 |
"```\n",
|
| 337 |
"git add -A; git commit -m \"Add application files\"; git push\n",
|
|
@@ -354,10 +362,26 @@
|
|
| 354 |
"After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo."
|
| 355 |
]
|
| 356 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
{
|
| 358 |
"cell_type": "code",
|
| 359 |
"execution_count": null,
|
| 360 |
-
"id": "
|
| 361 |
"metadata": {},
|
| 362 |
"outputs": [],
|
| 363 |
"source": []
|
|
|
|
| 7 |
"source": [
|
| 8 |
"# Hugging Face Spaces From A Notebook\n",
|
| 9 |
"\n",
|
| 10 |
+
"> A demo of using nbdev with Hugging Face Spaces & Gradio"
|
| 11 |
]
|
| 12 |
},
|
| 13 |
{
|
|
|
|
| 54 |
"id": "14a884fc-36e2-43ec-8e42-ca2903aaa4de",
|
| 55 |
"metadata": {},
|
| 56 |
"source": [
|
| 57 |
+
"Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces). \n",
|
| 58 |
"\n",
|
| 59 |
"First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:"
|
| 60 |
]
|
|
|
|
| 71 |
"from fastcore.net import urljson, HTTPError"
|
| 72 |
]
|
| 73 |
},
|
| 74 |
+
{
|
| 75 |
+
"cell_type": "markdown",
|
| 76 |
+
"id": "ecc45936-fc16-4e60-b4b7-c323900666c7",
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"source": [
|
| 79 |
+
"Next, write the functions your gradio app will use. Because of [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/), you can prototype and package your code all in one place. **The special comment `#|export` marks which cells will be sent to a python script** (more on this later). Note that there are only three cells in this notebook with the `#|export` directive."
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
{
|
| 83 |
"cell_type": "code",
|
| 84 |
"execution_count": null,
|
|
|
|
| 219 |
"id": "5c18ca6e-8de8-49e1-b95a-304070bbc171",
|
| 220 |
"metadata": {},
|
| 221 |
"source": [
|
| 222 |
+
"In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`. As a reminder, this is what the special `#|export` comment that you have seen in cells above do! You can export code from this notebook like so:"
|
| 223 |
]
|
| 224 |
},
|
| 225 |
{
|
|
|
|
| 311 |
"source": [
|
| 312 |
"### Fill out `requirements.txt`\n",
|
| 313 |
"\n",
|
| 314 |
+
"You must supply a requirements.txt file so the Gradio app knows how to build your dependencies. In this example, the only dependency other than Gradio is `fastcore`. You don't need to specify Gradio itself as a dependency in `requirements.txt`, so our `requirements.txt` file has only one dependency:"
|
| 315 |
]
|
| 316 |
},
|
| 317 |
{
|
|
|
|
| 339 |
"source": [
|
| 340 |
"## 4. Launch Your Gradio App\n",
|
| 341 |
"\n",
|
| 342 |
+
"To launch your gradio app, you need to commit the changes to the Hugging Face repo:\n",
|
| 343 |
"\n",
|
| 344 |
"```\n",
|
| 345 |
"git add -A; git commit -m \"Add application files\"; git push\n",
|
|
|
|
| 362 |
"After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo."
|
| 363 |
]
|
| 364 |
},
|
| 365 |
+
{
|
| 366 |
+
"cell_type": "markdown",
|
| 367 |
+
"id": "a9832cfb-9fe9-47e3-9928-1a1fd4b85bdd",
|
| 368 |
+
"metadata": {},
|
| 369 |
+
"source": [
|
| 370 |
+
"# Shameless Plug: [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)"
|
| 371 |
+
]
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"cell_type": "markdown",
|
| 375 |
+
"id": "8a7e43cc-104a-43b0-9433-a5b515c3a8d2",
|
| 376 |
+
"metadata": {},
|
| 377 |
+
"source": [
|
| 378 |
+
"Hopefully you felt something magical while doing this example. Even though the target application required you to write a python script (`app.py`), you didn't have to refactor your script from a notebook! We believe that you shouldn't have to refactor your code and switch contexts even when creating python packages! If this intrigues you, check out [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)"
|
| 379 |
+
]
|
| 380 |
+
},
|
| 381 |
{
|
| 382 |
"cell_type": "code",
|
| 383 |
"execution_count": null,
|
| 384 |
+
"id": "9a8ea66e-236c-416a-8958-dcf813a5f8c9",
|
| 385 |
"metadata": {},
|
| 386 |
"outputs": [],
|
| 387 |
"source": []
|
app.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# Hugging Face Spaces From A Notebook
|
| 2 |
|
| 3 |
-
> A demo of using nbdev with Hugging Face Spaces
|
| 4 |
|
| 5 |
## 1. Create a Gradio-enabled Space on Hugging Face
|
| 6 |
|
|
@@ -12,7 +12,7 @@ After you are done creating the space, **clone the repo per the instructions pro
|
|
| 12 |
|
| 13 |
## 2. Make an app with Gradio
|
| 14 |
|
| 15 |
-
Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces).
|
| 16 |
|
| 17 |
First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:
|
| 18 |
|
|
@@ -23,6 +23,8 @@ import gradio as gr
|
|
| 23 |
from fastcore.net import urljson, HTTPError
|
| 24 |
```
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
```
|
| 28 |
#|export
|
|
@@ -89,7 +91,7 @@ iface.close()
|
|
| 89 |
|
| 90 |
## 3. Converting This Notebook Into A Gradio App
|
| 91 |
|
| 92 |
-
In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`.
|
| 93 |
|
| 94 |
|
| 95 |
```
|
|
@@ -142,7 +144,7 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
| 142 |
|
| 143 |
### Fill out `requirements.txt`
|
| 144 |
|
| 145 |
-
You must supply a requirements.txt file so the
|
| 146 |
|
| 147 |
|
| 148 |
```
|
|
@@ -153,7 +155,7 @@ You must supply a requirements.txt file so the gradio app knows how to build you
|
|
| 153 |
|
| 154 |
## 4. Launch Your Gradio App
|
| 155 |
|
| 156 |
-
To launch your gradio app, you need to commit the changes
|
| 157 |
|
| 158 |
```
|
| 159 |
git add -A; git commit -m "Add application files"; git push
|
|
@@ -163,6 +165,10 @@ git add -A; git commit -m "Add application files"; git push
|
|
| 163 |
|
| 164 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
```
|
| 168 |
|
|
|
|
| 1 |
# Hugging Face Spaces From A Notebook
|
| 2 |
|
| 3 |
+
> A demo of using nbdev with Hugging Face Spaces & Gradio
|
| 4 |
|
| 5 |
## 1. Create a Gradio-enabled Space on Hugging Face
|
| 6 |
|
|
|
|
| 12 |
|
| 13 |
## 2. Make an app with Gradio
|
| 14 |
|
| 15 |
+
Below, we will create a [gradio](https://gradio.app/) app in a notebook and show you how to deploy it to [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces).
|
| 16 |
|
| 17 |
First, lets specify the libraries we need, which in this case are `gradio` and `fastcore`:
|
| 18 |
|
|
|
|
| 23 |
from fastcore.net import urljson, HTTPError
|
| 24 |
```
|
| 25 |
|
| 26 |
+
Next, write the functions your gradio app will use. Because of [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/), you can prototype and package your code all in one place. **The special comment `#|export` marks which cells will be sent to a python script** (more on this later). Note that there are only three cells in this notebook with the `#|export` directive.
|
| 27 |
+
|
| 28 |
|
| 29 |
```
|
| 30 |
#|export
|
|
|
|
| 91 |
|
| 92 |
## 3. Converting This Notebook Into A Gradio App
|
| 93 |
|
| 94 |
+
In order to host this code on Hugging Faces spaces, you will export parts of this notebook to a script named `app.py`. As a reminder, this is what the special `#|export` comment that you have seen in cells above do! You can export code from this notebook like so:
|
| 95 |
|
| 96 |
|
| 97 |
```
|
|
|
|
| 144 |
|
| 145 |
### Fill out `requirements.txt`
|
| 146 |
|
| 147 |
+
You must supply a requirements.txt file so the Gradio app knows how to build your dependencies. In this example, the only dependency other than Gradio is `fastcore`. You don't need to specify Gradio itself as a dependency in `requirements.txt`, so our `requirements.txt` file has only one dependency:
|
| 148 |
|
| 149 |
|
| 150 |
```
|
|
|
|
| 155 |
|
| 156 |
## 4. Launch Your Gradio App
|
| 157 |
|
| 158 |
+
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
| 159 |
|
| 160 |
```
|
| 161 |
git add -A; git commit -m "Add application files"; git push
|
|
|
|
| 165 |
|
| 166 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
| 167 |
|
| 168 |
+
# Shameless Plug: [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)
|
| 169 |
+
|
| 170 |
+
Hopefully you felt something magical while doing this example. Even though the target application required you to write a python script (`app.py`), you didn't have to refactor your script from a notebook! We believe that you shouldn't have to refactor your code and switch contexts even when creating python packages! If this intrigues you, check out [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)
|
| 171 |
+
|
| 172 |
|
| 173 |
```
|
| 174 |
|
create_space.png
DELETED
|
Binary file (57.6 kB)
|
|
|