Spaces:
Sleeping
Sleeping
Add application files
Browse files- .idea/.gitignore +8 -0
- .idea/hfspace_demo.iml +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +7 -0
- app.ipynb +267 -0
- app.py +21 -0
- requirements.txt +1 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/hfspace_demo.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="jdk" jdkName="cell" jdkType="Python SDK" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
+
</component>
|
| 8 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.12" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="cell" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/hfspace_demo.iml" filepath="$PROJECT_DIR$/.idea/hfspace_demo.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
| 6 |
+
</component>
|
| 7 |
+
</project>
|
app.ipynb
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "eed6bcd0-6cf8-4aa9-bedf-5eca5a6b7a9c",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# Hugging Face Spaces From A Notebook"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "markdown",
|
| 13 |
+
"id": "15fe30a9-cfeb-4ec0-ae40-334072046464",
|
| 14 |
+
"metadata": {},
|
| 15 |
+
"source": [
|
| 16 |
+
"Please reference [this blog post](https://nbdev.fast.ai/blog/posts/2022-11-07-spaces) on how to use this notebook."
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "markdown",
|
| 21 |
+
"id": "acf7644f-42b3-4d8d-a1d0-f8c3a2358e27",
|
| 22 |
+
"metadata": {},
|
| 23 |
+
"source": [
|
| 24 |
+
"## Install dependencies"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "markdown",
|
| 29 |
+
"id": "5ca22d1e-1bd0-49c0-9b89-c480ad1a29c4",
|
| 30 |
+
"metadata": {},
|
| 31 |
+
"source": [
|
| 32 |
+
"## Make an app with Gradio"
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"cell_type": "code",
|
| 37 |
+
"execution_count": 1,
|
| 38 |
+
"id": "00cf4fad-a920-41dc-be42-3992c7fcefac",
|
| 39 |
+
"metadata": {
|
| 40 |
+
"ExecuteTime": {
|
| 41 |
+
"end_time": "2025-03-14T04:11:04.564714Z",
|
| 42 |
+
"start_time": "2025-03-14T04:11:02.899351Z"
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"outputs": [],
|
| 46 |
+
"source": [
|
| 47 |
+
"#|export\n",
|
| 48 |
+
"import gradio as gr\n",
|
| 49 |
+
"from fastcore.net import urljson, HTTPError"
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"cell_type": "code",
|
| 54 |
+
"execution_count": 9,
|
| 55 |
+
"id": "38a4389f-ef53-4626-a6f5-a859354f854b",
|
| 56 |
+
"metadata": {
|
| 57 |
+
"ExecuteTime": {
|
| 58 |
+
"end_time": "2025-03-14T04:11:13.720552Z",
|
| 59 |
+
"start_time": "2025-03-14T04:11:13.715760Z"
|
| 60 |
+
}
|
| 61 |
+
},
|
| 62 |
+
"outputs": [],
|
| 63 |
+
"source": [
|
| 64 |
+
"#|export\n",
|
| 65 |
+
"def size(repo:str):\n",
|
| 66 |
+
" \"Returns the size in GB of a HuggingFace Dataset.\"\n",
|
| 67 |
+
" url = f'https://hf-mirror.com/api/datasets/{repo}'\n",
|
| 68 |
+
" try: resp = urljson(f'{url}/treesize/main')\n",
|
| 69 |
+
" except HTTPError: return f'Did not find repo: {url}'\n",
|
| 70 |
+
" gb = resp['size'] / 1e9\n",
|
| 71 |
+
" return f'{gb:.2f} GB'"
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"cell_type": "code",
|
| 76 |
+
"execution_count": 3,
|
| 77 |
+
"id": "65daf0ed",
|
| 78 |
+
"metadata": {},
|
| 79 |
+
"outputs": [
|
| 80 |
+
{
|
| 81 |
+
"name": "stdout",
|
| 82 |
+
"output_type": "stream",
|
| 83 |
+
"text": [
|
| 84 |
+
"https://hf-mirror.com\n"
|
| 85 |
+
]
|
| 86 |
+
}
|
| 87 |
+
],
|
| 88 |
+
"source": [
|
| 89 |
+
"!echo $HF_ENDPOINT"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"cell_type": "code",
|
| 94 |
+
"execution_count": 10,
|
| 95 |
+
"id": "95bc32b8-d8ff-4761-a2d7-0880c51d0a42",
|
| 96 |
+
"metadata": {
|
| 97 |
+
"ExecuteTime": {
|
| 98 |
+
"end_time": "2025-03-14T04:12:05.416422Z",
|
| 99 |
+
"start_time": "2025-03-14T04:11:30.180798Z"
|
| 100 |
+
}
|
| 101 |
+
},
|
| 102 |
+
"outputs": [
|
| 103 |
+
{
|
| 104 |
+
"data": {
|
| 105 |
+
"text/plain": [
|
| 106 |
+
"'5.49 GB'"
|
| 107 |
+
]
|
| 108 |
+
},
|
| 109 |
+
"execution_count": 10,
|
| 110 |
+
"metadata": {},
|
| 111 |
+
"output_type": "execute_result"
|
| 112 |
+
}
|
| 113 |
+
],
|
| 114 |
+
"source": [
|
| 115 |
+
"size(\"tglcourse/CelebA-faces-cropped-128\")"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"cell_type": "code",
|
| 120 |
+
"execution_count": 12,
|
| 121 |
+
"id": "7b20e2a1-b622-4970-9069-0202ce10a2ce",
|
| 122 |
+
"metadata": {
|
| 123 |
+
"ExecuteTime": {
|
| 124 |
+
"end_time": "2025-03-14T04:12:35.779502Z",
|
| 125 |
+
"start_time": "2025-03-14T04:12:34.361048Z"
|
| 126 |
+
}
|
| 127 |
+
},
|
| 128 |
+
"outputs": [
|
| 129 |
+
{
|
| 130 |
+
"name": "stdout",
|
| 131 |
+
"output_type": "stream",
|
| 132 |
+
"text": [
|
| 133 |
+
"* Running on local URL: http://127.0.0.1:7861\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"data": {
|
| 140 |
+
"text/html": [
|
| 141 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"500\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 142 |
+
],
|
| 143 |
+
"text/plain": [
|
| 144 |
+
"<IPython.core.display.HTML object>"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
"metadata": {},
|
| 148 |
+
"output_type": "display_data"
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"data": {
|
| 152 |
+
"text/plain": []
|
| 153 |
+
},
|
| 154 |
+
"execution_count": 12,
|
| 155 |
+
"metadata": {},
|
| 156 |
+
"output_type": "execute_result"
|
| 157 |
+
}
|
| 158 |
+
],
|
| 159 |
+
"source": [
|
| 160 |
+
"#|export\n",
|
| 161 |
+
"iface = gr.Interface(fn=size, inputs=gr.Text(value=\"tglcourse/CelebA-faces-cropped-128\"), outputs=\"text\")\n",
|
| 162 |
+
"iface.launch(width=500)"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "code",
|
| 167 |
+
"execution_count": 14,
|
| 168 |
+
"id": "39d7be72-9389-42cf-91b1-78e8f4bbd083",
|
| 169 |
+
"metadata": {},
|
| 170 |
+
"outputs": [
|
| 171 |
+
{
|
| 172 |
+
"name": "stdout",
|
| 173 |
+
"output_type": "stream",
|
| 174 |
+
"text": [
|
| 175 |
+
"Closing server running on port: 7861\n"
|
| 176 |
+
]
|
| 177 |
+
}
|
| 178 |
+
],
|
| 179 |
+
"source": [
|
| 180 |
+
"# this is only necessary in a notebook\n",
|
| 181 |
+
"iface.close()"
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"cell_type": "markdown",
|
| 186 |
+
"id": "88424f53-cd78-41fe-9e06-8a6209001064",
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"source": [
|
| 189 |
+
"## Create a `requirements.txt` file"
|
| 190 |
+
]
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"cell_type": "code",
|
| 194 |
+
"execution_count": 15,
|
| 195 |
+
"id": "db4a30aa-9090-460e-acf9-4eb359161125",
|
| 196 |
+
"metadata": {},
|
| 197 |
+
"outputs": [
|
| 198 |
+
{
|
| 199 |
+
"name": "stdout",
|
| 200 |
+
"output_type": "stream",
|
| 201 |
+
"text": [
|
| 202 |
+
"Writing requirements.txt\n"
|
| 203 |
+
]
|
| 204 |
+
}
|
| 205 |
+
],
|
| 206 |
+
"source": [
|
| 207 |
+
"%%writefile requirements.txt\n",
|
| 208 |
+
"fastcore"
|
| 209 |
+
]
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"cell_type": "markdown",
|
| 213 |
+
"id": "249b2cd7-3123-45bf-945f-882b8a964cf5",
|
| 214 |
+
"metadata": {},
|
| 215 |
+
"source": [
|
| 216 |
+
"## Convert this notebook into a Gradio app"
|
| 217 |
+
]
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"cell_type": "code",
|
| 221 |
+
"execution_count": 16,
|
| 222 |
+
"id": "6706d92c-5785-4f09-9773-b9a944c493a5",
|
| 223 |
+
"metadata": {},
|
| 224 |
+
"outputs": [],
|
| 225 |
+
"source": [
|
| 226 |
+
"from nbdev.export import nb_export\n",
|
| 227 |
+
"nb_export('app.ipynb', lib_path='.', name='app')"
|
| 228 |
+
]
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"cell_type": "markdown",
|
| 232 |
+
"id": "0182403f-d1d6-48c0-8e66-46aefb23a9ab",
|
| 233 |
+
"metadata": {},
|
| 234 |
+
"source": [
|
| 235 |
+
"<div>\n",
|
| 236 |
+
"<link rel=\"stylesheet\" href=\"https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.css\">\n",
|
| 237 |
+
"<div id=\"target\"></div>\n",
|
| 238 |
+
"<script src=\"https://gradio.s3-us-west-2.amazonaws.com/2.6.5/static/bundle.js\"></script>\n",
|
| 239 |
+
"<script>\n",
|
| 240 |
+
"launchGradioFromSpaces(\"abidlabs/question-answering\", \"#target\")\n",
|
| 241 |
+
"</script>\n",
|
| 242 |
+
"</div>"
|
| 243 |
+
]
|
| 244 |
+
}
|
| 245 |
+
],
|
| 246 |
+
"metadata": {
|
| 247 |
+
"kernelspec": {
|
| 248 |
+
"display_name": "cell",
|
| 249 |
+
"language": "python",
|
| 250 |
+
"name": "python3"
|
| 251 |
+
},
|
| 252 |
+
"language_info": {
|
| 253 |
+
"codemirror_mode": {
|
| 254 |
+
"name": "ipython",
|
| 255 |
+
"version": 3
|
| 256 |
+
},
|
| 257 |
+
"file_extension": ".py",
|
| 258 |
+
"mimetype": "text/x-python",
|
| 259 |
+
"name": "python",
|
| 260 |
+
"nbconvert_exporter": "python",
|
| 261 |
+
"pygments_lexer": "ipython3",
|
| 262 |
+
"version": "3.12.9"
|
| 263 |
+
}
|
| 264 |
+
},
|
| 265 |
+
"nbformat": 4,
|
| 266 |
+
"nbformat_minor": 5
|
| 267 |
+
}
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['iface', 'size']
|
| 5 |
+
|
| 6 |
+
# %% app.ipynb 4
|
| 7 |
+
import gradio as gr
|
| 8 |
+
from fastcore.net import urljson, HTTPError
|
| 9 |
+
|
| 10 |
+
# %% app.ipynb 5
|
| 11 |
+
def size(repo:str):
|
| 12 |
+
"Returns the size in GB of a HuggingFace Dataset."
|
| 13 |
+
url = f'https://hf-mirror.com/api/datasets/{repo}'
|
| 14 |
+
try: resp = urljson(f'{url}/treesize/main')
|
| 15 |
+
except HTTPError: return f'Did not find repo: {url}'
|
| 16 |
+
gb = resp['size'] / 1e9
|
| 17 |
+
return f'{gb:.2f} GB'
|
| 18 |
+
|
| 19 |
+
# %% app.ipynb 8
|
| 20 |
+
iface = gr.Interface(fn=size, inputs=gr.Text(value="tglcourse/CelebA-faces-cropped-128"), outputs="text")
|
| 21 |
+
iface.launch(width=500)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastcore
|