Spaces:
Runtime error
Runtime error
Add application files
Browse files
README.md
CHANGED
@@ -24,7 +24,12 @@ The first step is to create a space and select the appropriate sdk (which is Gra
|
|
24 |
|
25 |
After you are done creating the space, **clone the repo per the instructions provided in the app.** In this example, I ran the command `git clone https://huggingface.co/spaces/hamel/hfspace_demo`.
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
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).
|
30 |
|
@@ -73,22 +78,22 @@ You can construct a simple UI with the `gradio.interface` and then call the `lau
|
|
73 |
```
|
74 |
#|export
|
75 |
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
76 |
-
iface.launch(width=500)
|
77 |
```
|
78 |
|
79 |
-
Running on local URL: http://127.0.0.1:
|
80 |
|
81 |
To create a public link, set `share=True` in `launch()`.
|
82 |
|
83 |
|
84 |
|
85 |
-
<div><iframe src="http://127.0.0.1:
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
-
(<gradio.routes.App>, 'http://127.0.0.1:
|
92 |
|
93 |
|
94 |
|
@@ -100,10 +105,10 @@ Note how running the `launch()` method in a notebook runs a webserver in the bac
|
|
100 |
iface.close()
|
101 |
```
|
102 |
|
103 |
-
Closing server running on port:
|
104 |
|
105 |
|
106 |
-
##
|
107 |
|
108 |
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:
|
109 |
|
@@ -113,15 +118,6 @@ from nbdev.export import nb_export
|
|
113 |
nb_export('app.ipynb', lib_path='.', name='app')
|
114 |
```
|
115 |
|
116 |
-
<div>
|
117 |
-
<link rel="stylesheet" href="https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.css">
|
118 |
-
<div id="target"></div>
|
119 |
-
<script src="https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.js"></script>
|
120 |
-
<script>
|
121 |
-
launchGradioFromSpaces("abidlabs/question-answering", "#target")
|
122 |
-
</script>
|
123 |
-
</div>
|
124 |
-
|
125 |
### Understanding what is generated
|
126 |
|
127 |
Notice how the contents of app.py only contains the exported cells from this notebook:
|
@@ -141,7 +137,7 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
141 |
[0;34m[0m[0;32mimport[0m [0mgradio[0m [0;32mas[0m [0mgr[0m[0;34m[0m
|
142 |
[0;34m[0m[0;32mfrom[0m [0mfastcore[0m[0;34m.[0m[0mnet[0m [0;32mimport[0m [0murljson[0m[0;34m,[0m [0mHTTPError[0m[0;34m[0m
|
143 |
[0;34m[0m[0;34m[0m
|
144 |
-
[0;34m[0m[0;31m# %% app.ipynb
|
145 |
[0;34m[0m[0;32mdef[0m [0msize[0m[0;34m([0m[0mrepo[0m[0;34m:[0m[0mstr[0m[0;34m)[0m[0;34m:[0m[0;34m[0m
|
146 |
[0;34m[0m [0;34m"Returns the size in GB of a HuggingFace Dataset."[0m[0;34m[0m
|
147 |
[0;34m[0m [0murl[0m [0;34m=[0m [0;34mf'https://huggingface.co/api/datasets/{repo}'[0m[0;34m[0m
|
@@ -150,9 +146,9 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
150 |
[0;34m[0m [0mgb[0m [0;34m=[0m [0mresp[0m[0;34m[[0m[0;34m'size'[0m[0;34m][0m [0;34m/[0m [0;36m1e9[0m[0;34m[0m
|
151 |
[0;34m[0m [0;32mreturn[0m [0;34mf'{gb:.2f} GB'[0m[0;34m[0m
|
152 |
[0;34m[0m[0;34m[0m
|
153 |
-
[0;34m[0m[0;31m# %% app.ipynb
|
154 |
[0;34m[0m[0miface[0m [0;34m=[0m [0mgr[0m[0;34m.[0m[0mInterface[0m[0;34m([0m[0mfn[0m[0;34m=[0m[0msize[0m[0;34m,[0m [0minputs[0m[0;34m=[0m[0mgr[0m[0;34m.[0m[0mText[0m[0;34m([0m[0mvalue[0m[0;34m=[0m[0;34m"tglcourse/CelebA-faces-cropped-128"[0m[0;34m)[0m[0;34m,[0m [0moutputs[0m[0;34m=[0m[0;34m"text"[0m[0;34m)[0m[0;34m[0m
|
155 |
-
[0;34m[0m[0miface[0m[0;34m.[0m[0mlaunch[0m[0;34m([0m[0mwidth[0m[0;34m=[0m[0;36m500[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
156 |
|
157 |
|
158 |
|
@@ -169,7 +165,7 @@ You must supply a requirements.txt file so the Gradio app knows how to build you
|
|
169 |
|
170 |
_Note: you may want to add operating system dependencies in addition to python dependencies. You can do this via a `packages.txt` file as [documented here](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)._
|
171 |
|
172 |
-
##
|
173 |
|
174 |
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
175 |
|
@@ -177,7 +173,7 @@ To launch your gradio app, you need to commit the changes to the Hugging Face re
|
|
177 |
git add -A; git commit -m "Add application files"; git push
|
178 |
```
|
179 |
|
180 |
-
|
181 |
|
182 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
183 |
|
|
|
24 |
|
25 |
After you are done creating the space, **clone the repo per the instructions provided in the app.** In this example, I ran the command `git clone https://huggingface.co/spaces/hamel/hfspace_demo`.
|
26 |
|
27 |
+
|
28 |
+
## 2. Create A Notebook
|
29 |
+
|
30 |
+
To follow along, create a notebook called `app.ipynb` in the root of your newly cloned repo. You can write code as described below in your notebook. Alternatively, a minimal version of this notebook can also be [found here](https://gist.github.com/hamelsmu/35be07d242f3f19063c3a3839127dc67).
|
31 |
+
|
32 |
+
## 3. Make an app with Gradio
|
33 |
|
34 |
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).
|
35 |
|
|
|
78 |
```
|
79 |
#|export
|
80 |
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
81 |
+
iface.launch(height=450, width=500)
|
82 |
```
|
83 |
|
84 |
+
Running on local URL: http://127.0.0.1:7861
|
85 |
|
86 |
To create a public link, set `share=True` in `launch()`.
|
87 |
|
88 |
|
89 |
|
90 |
+
<div><iframe src="http://127.0.0.1:7861/" width="500" height="450" allow="autoplay; camera; microphone; clipboard-read; clipboard-write;" frameborder="0" allowfullscreen></iframe></div>
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
+
(<gradio.routes.App>, 'http://127.0.0.1:7861/', None)
|
97 |
|
98 |
|
99 |
|
|
|
105 |
iface.close()
|
106 |
```
|
107 |
|
108 |
+
Closing server running on port: 7861
|
109 |
|
110 |
|
111 |
+
## 4. Convert This Notebook Into A Gradio App
|
112 |
|
113 |
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:
|
114 |
|
|
|
118 |
nb_export('app.ipynb', lib_path='.', name='app')
|
119 |
```
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
### Understanding what is generated
|
122 |
|
123 |
Notice how the contents of app.py only contains the exported cells from this notebook:
|
|
|
137 |
[0;34m[0m[0;32mimport[0m [0mgradio[0m [0;32mas[0m [0mgr[0m[0;34m[0m
|
138 |
[0;34m[0m[0;32mfrom[0m [0mfastcore[0m[0;34m.[0m[0mnet[0m [0;32mimport[0m [0murljson[0m[0;34m,[0m [0mHTTPError[0m[0;34m[0m
|
139 |
[0;34m[0m[0;34m[0m
|
140 |
+
[0;34m[0m[0;31m# %% app.ipynb 8[0m[0;34m[0m
|
141 |
[0;34m[0m[0;32mdef[0m [0msize[0m[0;34m([0m[0mrepo[0m[0;34m:[0m[0mstr[0m[0;34m)[0m[0;34m:[0m[0;34m[0m
|
142 |
[0;34m[0m [0;34m"Returns the size in GB of a HuggingFace Dataset."[0m[0;34m[0m
|
143 |
[0;34m[0m [0murl[0m [0;34m=[0m [0;34mf'https://huggingface.co/api/datasets/{repo}'[0m[0;34m[0m
|
|
|
146 |
[0;34m[0m [0mgb[0m [0;34m=[0m [0mresp[0m[0;34m[[0m[0;34m'size'[0m[0;34m][0m [0;34m/[0m [0;36m1e9[0m[0;34m[0m
|
147 |
[0;34m[0m [0;32mreturn[0m [0;34mf'{gb:.2f} GB'[0m[0;34m[0m
|
148 |
[0;34m[0m[0;34m[0m
|
149 |
+
[0;34m[0m[0;31m# %% app.ipynb 12[0m[0;34m[0m
|
150 |
[0;34m[0m[0miface[0m [0;34m=[0m [0mgr[0m[0;34m.[0m[0mInterface[0m[0;34m([0m[0mfn[0m[0;34m=[0m[0msize[0m[0;34m,[0m [0minputs[0m[0;34m=[0m[0mgr[0m[0;34m.[0m[0mText[0m[0;34m([0m[0mvalue[0m[0;34m=[0m[0;34m"tglcourse/CelebA-faces-cropped-128"[0m[0;34m)[0m[0;34m,[0m [0moutputs[0m[0;34m=[0m[0;34m"text"[0m[0;34m)[0m[0;34m[0m
|
151 |
+
[0;34m[0m[0miface[0m[0;34m.[0m[0mlaunch[0m[0;34m([0m[0mheight[0m[0;34m=[0m[0;36m450[0m[0;34m,[0m [0mwidth[0m[0;34m=[0m[0;36m500[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
152 |
|
153 |
|
154 |
|
|
|
165 |
|
166 |
_Note: you may want to add operating system dependencies in addition to python dependencies. You can do this via a `packages.txt` file as [documented here](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)._
|
167 |
|
168 |
+
## 5. Launch Your Gradio App
|
169 |
|
170 |
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
171 |
|
|
|
173 |
git add -A; git commit -m "Add application files"; git push
|
174 |
```
|
175 |
|
176 |
+
# Voilà! Enjoy your Gradio App
|
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 |
|
app.md
CHANGED
@@ -12,7 +12,12 @@ The first step is to create a space and select the appropriate sdk (which is Gra
|
|
12 |
|
13 |
After you are done creating the space, **clone the repo per the instructions provided in the app.** In this example, I ran the command `git clone https://huggingface.co/spaces/hamel/hfspace_demo`.
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
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).
|
18 |
|
@@ -61,22 +66,22 @@ You can construct a simple UI with the `gradio.interface` and then call the `lau
|
|
61 |
```
|
62 |
#|export
|
63 |
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
64 |
-
iface.launch(width=500)
|
65 |
```
|
66 |
|
67 |
-
Running on local URL: http://127.0.0.1:
|
68 |
|
69 |
To create a public link, set `share=True` in `launch()`.
|
70 |
|
71 |
|
72 |
|
73 |
-
<div><iframe src="http://127.0.0.1:
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
-
(<gradio.routes.App>, 'http://127.0.0.1:
|
80 |
|
81 |
|
82 |
|
@@ -88,10 +93,10 @@ Note how running the `launch()` method in a notebook runs a webserver in the bac
|
|
88 |
iface.close()
|
89 |
```
|
90 |
|
91 |
-
Closing server running on port:
|
92 |
|
93 |
|
94 |
-
##
|
95 |
|
96 |
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:
|
97 |
|
@@ -101,15 +106,6 @@ from nbdev.export import nb_export
|
|
101 |
nb_export('app.ipynb', lib_path='.', name='app')
|
102 |
```
|
103 |
|
104 |
-
<div>
|
105 |
-
<link rel="stylesheet" href="https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.css">
|
106 |
-
<div id="target"></div>
|
107 |
-
<script src="https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.js"></script>
|
108 |
-
<script>
|
109 |
-
launchGradioFromSpaces("abidlabs/question-answering", "#target")
|
110 |
-
</script>
|
111 |
-
</div>
|
112 |
-
|
113 |
### Understanding what is generated
|
114 |
|
115 |
Notice how the contents of app.py only contains the exported cells from this notebook:
|
@@ -129,7 +125,7 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
129 |
[0;34m[0m[0;32mimport[0m [0mgradio[0m [0;32mas[0m [0mgr[0m[0;34m[0m
|
130 |
[0;34m[0m[0;32mfrom[0m [0mfastcore[0m[0;34m.[0m[0mnet[0m [0;32mimport[0m [0murljson[0m[0;34m,[0m [0mHTTPError[0m[0;34m[0m
|
131 |
[0;34m[0m[0;34m[0m
|
132 |
-
[0;34m[0m[0;31m# %% app.ipynb
|
133 |
[0;34m[0m[0;32mdef[0m [0msize[0m[0;34m([0m[0mrepo[0m[0;34m:[0m[0mstr[0m[0;34m)[0m[0;34m:[0m[0;34m[0m
|
134 |
[0;34m[0m [0;34m"Returns the size in GB of a HuggingFace Dataset."[0m[0;34m[0m
|
135 |
[0;34m[0m [0murl[0m [0;34m=[0m [0;34mf'https://huggingface.co/api/datasets/{repo}'[0m[0;34m[0m
|
@@ -138,9 +134,9 @@ Notice how the contents of app.py only contains the exported cells from this not
|
|
138 |
[0;34m[0m [0mgb[0m [0;34m=[0m [0mresp[0m[0;34m[[0m[0;34m'size'[0m[0;34m][0m [0;34m/[0m [0;36m1e9[0m[0;34m[0m
|
139 |
[0;34m[0m [0;32mreturn[0m [0;34mf'{gb:.2f} GB'[0m[0;34m[0m
|
140 |
[0;34m[0m[0;34m[0m
|
141 |
-
[0;34m[0m[0;31m# %% app.ipynb
|
142 |
[0;34m[0m[0miface[0m [0;34m=[0m [0mgr[0m[0;34m.[0m[0mInterface[0m[0;34m([0m[0mfn[0m[0;34m=[0m[0msize[0m[0;34m,[0m [0minputs[0m[0;34m=[0m[0mgr[0m[0;34m.[0m[0mText[0m[0;34m([0m[0mvalue[0m[0;34m=[0m[0;34m"tglcourse/CelebA-faces-cropped-128"[0m[0;34m)[0m[0;34m,[0m [0moutputs[0m[0;34m=[0m[0;34m"text"[0m[0;34m)[0m[0;34m[0m
|
143 |
-
[0;34m[0m[0miface[0m[0;34m.[0m[0mlaunch[0m[0;34m([0m[0mwidth[0m[0;34m=[0m[0;36m500[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
144 |
|
145 |
|
146 |
|
@@ -157,7 +153,7 @@ You must supply a requirements.txt file so the Gradio app knows how to build you
|
|
157 |
|
158 |
_Note: you may want to add operating system dependencies in addition to python dependencies. You can do this via a `packages.txt` file as [documented here](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)._
|
159 |
|
160 |
-
##
|
161 |
|
162 |
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
163 |
|
@@ -165,7 +161,7 @@ To launch your gradio app, you need to commit the changes to the Hugging Face re
|
|
165 |
git add -A; git commit -m "Add application files"; git push
|
166 |
```
|
167 |
|
168 |
-
|
169 |
|
170 |
After a couple of minutes, you will see your app published! This app is published at https://huggingface.co/spaces/hamel/hfspace_demo.
|
171 |
|
|
|
12 |
|
13 |
After you are done creating the space, **clone the repo per the instructions provided in the app.** In this example, I ran the command `git clone https://huggingface.co/spaces/hamel/hfspace_demo`.
|
14 |
|
15 |
+
|
16 |
+
## 2. Create A Notebook
|
17 |
+
|
18 |
+
To follow along, create a notebook called `app.ipynb` in the root of your newly cloned repo. You can write code as described below in your notebook. Alternatively, a minimal version of this notebook can also be [found here](https://gist.github.com/hamelsmu/35be07d242f3f19063c3a3839127dc67).
|
19 |
+
|
20 |
+
## 3. Make an app with Gradio
|
21 |
|
22 |
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).
|
23 |
|
|
|
66 |
```
|
67 |
#|export
|
68 |
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
69 |
+
iface.launch(height=450, width=500)
|
70 |
```
|
71 |
|
72 |
+
Running on local URL: http://127.0.0.1:7861
|
73 |
|
74 |
To create a public link, set `share=True` in `launch()`.
|
75 |
|
76 |
|
77 |
|
78 |
+
<div><iframe src="http://127.0.0.1:7861/" width="500" height="450" allow="autoplay; camera; microphone; clipboard-read; clipboard-write;" frameborder="0" allowfullscreen></iframe></div>
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
+
(<gradio.routes.App>, 'http://127.0.0.1:7861/', None)
|
85 |
|
86 |
|
87 |
|
|
|
93 |
iface.close()
|
94 |
```
|
95 |
|
96 |
+
Closing server running on port: 7861
|
97 |
|
98 |
|
99 |
+
## 4. Convert This Notebook Into A Gradio App
|
100 |
|
101 |
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:
|
102 |
|
|
|
106 |
nb_export('app.ipynb', lib_path='.', name='app')
|
107 |
```
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
### Understanding what is generated
|
110 |
|
111 |
Notice how the contents of app.py only contains the exported cells from this notebook:
|
|
|
125 |
[0;34m[0m[0;32mimport[0m [0mgradio[0m [0;32mas[0m [0mgr[0m[0;34m[0m
|
126 |
[0;34m[0m[0;32mfrom[0m [0mfastcore[0m[0;34m.[0m[0mnet[0m [0;32mimport[0m [0murljson[0m[0;34m,[0m [0mHTTPError[0m[0;34m[0m
|
127 |
[0;34m[0m[0;34m[0m
|
128 |
+
[0;34m[0m[0;31m# %% app.ipynb 8[0m[0;34m[0m
|
129 |
[0;34m[0m[0;32mdef[0m [0msize[0m[0;34m([0m[0mrepo[0m[0;34m:[0m[0mstr[0m[0;34m)[0m[0;34m:[0m[0;34m[0m
|
130 |
[0;34m[0m [0;34m"Returns the size in GB of a HuggingFace Dataset."[0m[0;34m[0m
|
131 |
[0;34m[0m [0murl[0m [0;34m=[0m [0;34mf'https://huggingface.co/api/datasets/{repo}'[0m[0;34m[0m
|
|
|
134 |
[0;34m[0m [0mgb[0m [0;34m=[0m [0mresp[0m[0;34m[[0m[0;34m'size'[0m[0;34m][0m [0;34m/[0m [0;36m1e9[0m[0;34m[0m
|
135 |
[0;34m[0m [0;32mreturn[0m [0;34mf'{gb:.2f} GB'[0m[0;34m[0m
|
136 |
[0;34m[0m[0;34m[0m
|
137 |
+
[0;34m[0m[0;31m# %% app.ipynb 12[0m[0;34m[0m
|
138 |
[0;34m[0m[0miface[0m [0;34m=[0m [0mgr[0m[0;34m.[0m[0mInterface[0m[0;34m([0m[0mfn[0m[0;34m=[0m[0msize[0m[0;34m,[0m [0minputs[0m[0;34m=[0m[0mgr[0m[0;34m.[0m[0mText[0m[0;34m([0m[0mvalue[0m[0;34m=[0m[0;34m"tglcourse/CelebA-faces-cropped-128"[0m[0;34m)[0m[0;34m,[0m [0moutputs[0m[0;34m=[0m[0;34m"text"[0m[0;34m)[0m[0;34m[0m
|
139 |
+
[0;34m[0m[0miface[0m[0;34m.[0m[0mlaunch[0m[0;34m([0m[0mheight[0m[0;34m=[0m[0;36m450[0m[0;34m,[0m [0mwidth[0m[0;34m=[0m[0;36m500[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
140 |
|
141 |
|
142 |
|
|
|
153 |
|
154 |
_Note: you may want to add operating system dependencies in addition to python dependencies. You can do this via a `packages.txt` file as [documented here](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)._
|
155 |
|
156 |
+
## 5. Launch Your Gradio App
|
157 |
|
158 |
To launch your gradio app, you need to commit the changes to the Hugging Face repo:
|
159 |
|
|
|
161 |
git add -A; git commit -m "Add application files"; git push
|
162 |
```
|
163 |
|
164 |
+
# Voilà! Enjoy your Gradio App
|
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 |
|