hamel commited on
Commit
09e10dc
1 Parent(s): 2f96071

Add application files

Browse files
Files changed (2) hide show
  1. README.md +17 -21
  2. app.md +17 -21
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
- ## 2. Make an app with Gradio
 
 
 
 
 
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:7860
80
 
81
  To create a public link, set `share=True` in `launch()`.
82
 
83
 
84
 
85
- <div><iframe src="http://127.0.0.1:7860/" width="500" height="500" allow="autoplay; camera; microphone; clipboard-read; clipboard-write;" frameborder="0" allowfullscreen></iframe></div>
86
 
87
 
88
 
89
 
90
 
91
- (<gradio.routes.App>, 'http://127.0.0.1:7860/', None)
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: 7860
104
 
105
 
106
- ## 3. Converting This Notebook Into A Gradio App
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
  import gradio as gr
142
  from fastcore.net import urljson, HTTPError
143
  
144
- # %% app.ipynb 7
145
  def size(repo:str):
146
   "Returns the size in GB of a HuggingFace Dataset."
147
   url = f'https://huggingface.co/api/datasets/{repo}'
@@ -150,9 +146,9 @@ Notice how the contents of app.py only contains the exported cells from this not
150
   gb = resp['size'] / 1e9
151
   return f'{gb:.2f} GB'
152
  
153
- # %% app.ipynb 11
154
  iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
155
- iface.launch(width=500)
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
- ## 4. Launch Your Gradio App
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
- ## 5. Voilà! Enjoy your Gradio App
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
  import gradio as gr
138
  from fastcore.net import urljson, HTTPError
139
  
140
+ # %% app.ipynb 8
141
  def size(repo:str):
142
   "Returns the size in GB of a HuggingFace Dataset."
143
   url = f'https://huggingface.co/api/datasets/{repo}'
 
146
   gb = resp['size'] / 1e9
147
   return f'{gb:.2f} GB'
148
  
149
+ # %% app.ipynb 12
150
  iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
151
+ iface.launch(height=450, width=500)
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
- ## 2. Make an app with Gradio
 
 
 
 
 
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:7860
68
 
69
  To create a public link, set `share=True` in `launch()`.
70
 
71
 
72
 
73
- <div><iframe src="http://127.0.0.1:7860/" width="500" height="500" allow="autoplay; camera; microphone; clipboard-read; clipboard-write;" frameborder="0" allowfullscreen></iframe></div>
74
 
75
 
76
 
77
 
78
 
79
- (<gradio.routes.App>, 'http://127.0.0.1:7860/', None)
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: 7860
92
 
93
 
94
- ## 3. Converting This Notebook Into A Gradio App
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
  import gradio as gr
130
  from fastcore.net import urljson, HTTPError
131
  
132
- # %% app.ipynb 7
133
  def size(repo:str):
134
   "Returns the size in GB of a HuggingFace Dataset."
135
   url = f'https://huggingface.co/api/datasets/{repo}'
@@ -138,9 +134,9 @@ Notice how the contents of app.py only contains the exported cells from this not
138
   gb = resp['size'] / 1e9
139
   return f'{gb:.2f} GB'
140
  
141
- # %% app.ipynb 11
142
  iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
143
- iface.launch(width=500)
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
- ## 4. Launch Your Gradio App
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
- ## 5. Voilà! Enjoy your Gradio App
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
  import gradio as gr
126
  from fastcore.net import urljson, HTTPError
127
  
128
+ # %% app.ipynb 8
129
  def size(repo:str):
130
   "Returns the size in GB of a HuggingFace Dataset."
131
   url = f'https://huggingface.co/api/datasets/{repo}'
 
134
   gb = resp['size'] / 1e9
135
   return f'{gb:.2f} GB'
136
  
137
+ # %% app.ipynb 12
138
  iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
139
+ iface.launch(height=450, width=500)
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