added bear classfication model
Browse files- .ipynb_checkpoints/app-checkpoint.ipynb +191 -0
- app.ipynb +270 -0
- app.py +27 -15
- export.pkl +3 -0
- images/black.jpg +0 -0
- images/black2.jpg +0 -0
- images/grizzly.jpg +0 -0
- images/grizzly2.jpg +0 -0
- images/teddy.jpg +0 -0
.ipynb_checkpoints/app-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
+
"id": "3b1e0720",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"Collecting gradio\n",
|
| 14 |
+
" Using cached gradio-4.8.0-py3-none-any.whl.metadata (17 kB)\n",
|
| 15 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (23.2.1)\n",
|
| 16 |
+
"Collecting altair<6.0,>=4.2.0 (from gradio)\n",
|
| 17 |
+
" Using cached altair-5.2.0-py3-none-any.whl.metadata (8.7 kB)\n",
|
| 18 |
+
"Collecting fastapi (from gradio)\n",
|
| 19 |
+
" Using cached fastapi-0.104.1-py3-none-any.whl.metadata (24 kB)\n",
|
| 20 |
+
"Requirement already satisfied: ffmpy in c:\\python310\\lib\\site-packages (from gradio) (0.3.1)\n",
|
| 21 |
+
"Collecting gradio-client==0.7.1 (from gradio)\n",
|
| 22 |
+
" Using cached gradio_client-0.7.1-py3-none-any.whl.metadata (7.1 kB)\n",
|
| 23 |
+
"Requirement already satisfied: httpx in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (0.25.1)\n",
|
| 24 |
+
"Requirement already satisfied: huggingface-hub>=0.14.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (0.19.4)\n",
|
| 25 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in c:\\python310\\lib\\site-packages (from gradio) (6.1.1)\n",
|
| 26 |
+
"Requirement already satisfied: jinja2<4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (3.1.2)\n",
|
| 27 |
+
"Requirement already satisfied: markupsafe~=2.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.1.2)\n",
|
| 28 |
+
"Requirement already satisfied: matplotlib~=3.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (3.7.2)\n",
|
| 29 |
+
"Requirement already satisfied: numpy~=1.0 in c:\\python310\\lib\\site-packages (from gradio) (1.23.5)\n",
|
| 30 |
+
"Requirement already satisfied: orjson~=3.0 in c:\\python310\\lib\\site-packages (from gradio) (3.9.10)\n",
|
| 31 |
+
"Requirement already satisfied: packaging in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (23.0)\n",
|
| 32 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.0.3)\n",
|
| 33 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (9.4.0)\n",
|
| 34 |
+
"Requirement already satisfied: pydantic>=2.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.5.2)\n",
|
| 35 |
+
"Requirement already satisfied: pydub in c:\\python310\\lib\\site-packages (from gradio) (0.25.1)\n",
|
| 36 |
+
"Requirement already satisfied: python-multipart in c:\\python310\\lib\\site-packages (from gradio) (0.0.6)\n",
|
| 37 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (6.0)\n",
|
| 38 |
+
"Requirement already satisfied: requests~=2.0 in c:\\python310\\lib\\site-packages (from gradio) (2.31.0)\n",
|
| 39 |
+
"Requirement already satisfied: semantic-version~=2.0 in c:\\python310\\lib\\site-packages (from gradio) (2.10.0)\n",
|
| 40 |
+
"Requirement already satisfied: tomlkit==0.12.0 in c:\\python310\\lib\\site-packages (from gradio) (0.12.0)\n",
|
| 41 |
+
"Requirement already satisfied: typer<1.0,>=0.9 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer[all]<1.0,>=0.9->gradio) (0.9.0)\n",
|
| 42 |
+
"Requirement already satisfied: typing-extensions~=4.0 in c:\\python310\\lib\\site-packages (from gradio) (4.8.0)\n",
|
| 43 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in c:\\python310\\lib\\site-packages (from gradio) (0.24.0.post1)\n",
|
| 44 |
+
"Requirement already satisfied: fsspec in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio-client==0.7.1->gradio) (2023.9.2)\n",
|
| 45 |
+
"Requirement already satisfied: websockets<12.0,>=10.0 in c:\\python310\\lib\\site-packages (from gradio-client==0.7.1->gradio) (11.0.3)\n",
|
| 46 |
+
"Requirement already satisfied: jsonschema>=3.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from altair<6.0,>=4.2.0->gradio) (4.17.3)\n",
|
| 47 |
+
"Requirement already satisfied: toolz in c:\\python310\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n",
|
| 48 |
+
"Requirement already satisfied: filelock in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from huggingface-hub>=0.14.0->gradio) (3.12.4)\n",
|
| 49 |
+
"Requirement already satisfied: tqdm>=4.42.1 in c:\\python310\\lib\\site-packages (from huggingface-hub>=0.14.0->gradio) (4.64.1)\n",
|
| 50 |
+
"Requirement already satisfied: contourpy>=1.0.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.1.1)\n",
|
| 51 |
+
"Requirement already satisfied: cycler>=0.10 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (0.12.0)\n",
|
| 52 |
+
"Requirement already satisfied: fonttools>=4.22.0 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (4.43.0)\n",
|
| 53 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
| 54 |
+
"Requirement already satisfied: pyparsing<3.1,>=2.3.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (3.0.9)\n",
|
| 55 |
+
"Requirement already satisfied: python-dateutil>=2.7 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
| 56 |
+
"Requirement already satisfied: pytz>=2020.1 in c:\\python310\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
|
| 57 |
+
"Requirement already satisfied: tzdata>=2022.1 in c:\\python310\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2023.3)\n",
|
| 58 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
| 59 |
+
"Requirement already satisfied: pydantic-core==2.14.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from pydantic>=2.0->gradio) (2.14.5)\n",
|
| 60 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (2.1.1)\n",
|
| 61 |
+
"Requirement already satisfied: idna<4,>=2.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (3.4)\n",
|
| 62 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (1.26.14)\n",
|
| 63 |
+
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (2022.12.7)\n",
|
| 64 |
+
"Requirement already satisfied: click<9.0.0,>=7.1.1 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer<1.0,>=0.9->typer[all]<1.0,>=0.9->gradio) (8.1.7)\n",
|
| 65 |
+
"Requirement already satisfied: colorama<0.5.0,>=0.4.3 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n",
|
| 66 |
+
"Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in c:\\python310\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n",
|
| 67 |
+
"Collecting rich<14.0.0,>=10.11.0 (from typer[all]<1.0,>=0.9->gradio)\n",
|
| 68 |
+
" Using cached rich-13.7.0-py3-none-any.whl.metadata (18 kB)\n",
|
| 69 |
+
"Requirement already satisfied: h11>=0.8 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n",
|
| 70 |
+
"Requirement already satisfied: anyio<4.0.0,>=3.7.1 in c:\\python310\\lib\\site-packages (from fastapi->gradio) (3.7.1)\n",
|
| 71 |
+
"Collecting starlette<0.28.0,>=0.27.0 (from fastapi->gradio)\n",
|
| 72 |
+
" Using cached starlette-0.27.0-py3-none-any.whl.metadata (5.8 kB)\n",
|
| 73 |
+
"Requirement already satisfied: httpcore in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from httpx->gradio) (1.0.2)\n",
|
| 74 |
+
"Requirement already satisfied: sniffio in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from httpx->gradio) (1.3.0)\n",
|
| 75 |
+
"Requirement already satisfied: exceptiongroup in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from anyio<4.0.0,>=3.7.1->fastapi->gradio) (1.1.0)\n",
|
| 76 |
+
"Requirement already satisfied: attrs>=17.4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (22.2.0)\n",
|
| 77 |
+
"Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.19.3)\n",
|
| 78 |
+
"Requirement already satisfied: six>=1.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
| 79 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\python310\\lib\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n",
|
| 80 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.14.0)\n",
|
| 81 |
+
"Requirement already satisfied: mdurl~=0.1 in c:\\python310\\lib\\site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n",
|
| 82 |
+
"Using cached gradio-4.8.0-py3-none-any.whl (16.5 MB)\n",
|
| 83 |
+
"Using cached gradio_client-0.7.1-py3-none-any.whl (302 kB)\n",
|
| 84 |
+
"Using cached altair-5.2.0-py3-none-any.whl (996 kB)\n",
|
| 85 |
+
"Using cached fastapi-0.104.1-py3-none-any.whl (92 kB)\n",
|
| 86 |
+
"Using cached rich-13.7.0-py3-none-any.whl (240 kB)\n",
|
| 87 |
+
"Using cached starlette-0.27.0-py3-none-any.whl (66 kB)\n",
|
| 88 |
+
"Installing collected packages: starlette, rich, gradio-client, fastapi, altair, gradio\n"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"name": "stderr",
|
| 93 |
+
"output_type": "stream",
|
| 94 |
+
"text": [
|
| 95 |
+
"WARNING: Ignoring invalid distribution - (c:\\python310\\lib\\site-packages)\n",
|
| 96 |
+
"WARNING: Ignoring invalid distribution -ip (c:\\python310\\lib\\site-packages)\n",
|
| 97 |
+
"WARNING: Ignoring invalid distribution - (c:\\python310\\lib\\site-packages)\n",
|
| 98 |
+
"WARNING: Ignoring invalid distribution -ip (c:\\python310\\lib\\site-packages)\n",
|
| 99 |
+
"DEPRECATION: google-images-search 1.4.6 has a non-standard dependency specifier click>=7.0<=8.1.*. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of google-images-search or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063\n",
|
| 100 |
+
" WARNING: Failed to write executable - trying to use .deleteme logic\n",
|
| 101 |
+
"ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\\\\Python310\\\\Scripts\\\\gradio.exe' -> 'C:\\\\Python310\\\\Scripts\\\\gradio.exe.deleteme'\n",
|
| 102 |
+
"\n",
|
| 103 |
+
"WARNING: There was an error checking the latest version of pip.\n"
|
| 104 |
+
]
|
| 105 |
+
}
|
| 106 |
+
],
|
| 107 |
+
"source": [
|
| 108 |
+
"!pip install gradio"
|
| 109 |
+
]
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"cell_type": "code",
|
| 113 |
+
"execution_count": 4,
|
| 114 |
+
"id": "c5b8909a",
|
| 115 |
+
"metadata": {},
|
| 116 |
+
"outputs": [
|
| 117 |
+
{
|
| 118 |
+
"name": "stdout",
|
| 119 |
+
"output_type": "stream",
|
| 120 |
+
"text": [
|
| 121 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"data": {
|
| 128 |
+
"text/html": [
|
| 129 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 130 |
+
],
|
| 131 |
+
"text/plain": [
|
| 132 |
+
"<IPython.core.display.HTML object>"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"metadata": {},
|
| 136 |
+
"output_type": "display_data"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"data": {
|
| 140 |
+
"text/plain": []
|
| 141 |
+
},
|
| 142 |
+
"execution_count": 4,
|
| 143 |
+
"metadata": {},
|
| 144 |
+
"output_type": "execute_result"
|
| 145 |
+
}
|
| 146 |
+
],
|
| 147 |
+
"source": [
|
| 148 |
+
"import gradio as gr\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"def greet(name):\n",
|
| 151 |
+
" return \"Hello \" + name + \"!\"\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"demo = gr.Interface(\n",
|
| 154 |
+
" fn=greet,\n",
|
| 155 |
+
" inputs=gr.Textbox(lines=2, placeholder=\"Your name...\"),\n",
|
| 156 |
+
" outputs=\"text\",\n",
|
| 157 |
+
")\n",
|
| 158 |
+
"demo.launch()"
|
| 159 |
+
]
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"cell_type": "code",
|
| 163 |
+
"execution_count": null,
|
| 164 |
+
"id": "cf1098d5",
|
| 165 |
+
"metadata": {},
|
| 166 |
+
"outputs": [],
|
| 167 |
+
"source": []
|
| 168 |
+
}
|
| 169 |
+
],
|
| 170 |
+
"metadata": {
|
| 171 |
+
"kernelspec": {
|
| 172 |
+
"display_name": "Python 3 (ipykernel)",
|
| 173 |
+
"language": "python",
|
| 174 |
+
"name": "python3"
|
| 175 |
+
},
|
| 176 |
+
"language_info": {
|
| 177 |
+
"codemirror_mode": {
|
| 178 |
+
"name": "ipython",
|
| 179 |
+
"version": 3
|
| 180 |
+
},
|
| 181 |
+
"file_extension": ".py",
|
| 182 |
+
"mimetype": "text/x-python",
|
| 183 |
+
"name": "python",
|
| 184 |
+
"nbconvert_exporter": "python",
|
| 185 |
+
"pygments_lexer": "ipython3",
|
| 186 |
+
"version": "3.10.7"
|
| 187 |
+
}
|
| 188 |
+
},
|
| 189 |
+
"nbformat": 4,
|
| 190 |
+
"nbformat_minor": 5
|
| 191 |
+
}
|
app.ipynb
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
+
"id": "2c4095d3",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"Collecting gradio\n",
|
| 14 |
+
" Using cached gradio-4.8.0-py3-none-any.whl.metadata (17 kB)\n",
|
| 15 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (23.2.1)\n",
|
| 16 |
+
"Collecting altair<6.0,>=4.2.0 (from gradio)\n",
|
| 17 |
+
" Using cached altair-5.2.0-py3-none-any.whl.metadata (8.7 kB)\n",
|
| 18 |
+
"Collecting fastapi (from gradio)\n",
|
| 19 |
+
" Using cached fastapi-0.104.1-py3-none-any.whl.metadata (24 kB)\n",
|
| 20 |
+
"Requirement already satisfied: ffmpy in c:\\python310\\lib\\site-packages (from gradio) (0.3.1)\n",
|
| 21 |
+
"Collecting gradio-client==0.7.1 (from gradio)\n",
|
| 22 |
+
" Using cached gradio_client-0.7.1-py3-none-any.whl.metadata (7.1 kB)\n",
|
| 23 |
+
"Requirement already satisfied: httpx in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (0.25.1)\n",
|
| 24 |
+
"Requirement already satisfied: huggingface-hub>=0.14.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (0.19.4)\n",
|
| 25 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in c:\\python310\\lib\\site-packages (from gradio) (6.1.1)\n",
|
| 26 |
+
"Requirement already satisfied: jinja2<4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (3.1.2)\n",
|
| 27 |
+
"Requirement already satisfied: markupsafe~=2.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.1.2)\n",
|
| 28 |
+
"Requirement already satisfied: matplotlib~=3.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (3.7.2)\n",
|
| 29 |
+
"Requirement already satisfied: numpy~=1.0 in c:\\python310\\lib\\site-packages (from gradio) (1.23.5)\n",
|
| 30 |
+
"Requirement already satisfied: orjson~=3.0 in c:\\python310\\lib\\site-packages (from gradio) (3.9.10)\n",
|
| 31 |
+
"Requirement already satisfied: packaging in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (23.0)\n",
|
| 32 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.0.3)\n",
|
| 33 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (9.4.0)\n",
|
| 34 |
+
"Requirement already satisfied: pydantic>=2.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (2.5.2)\n",
|
| 35 |
+
"Requirement already satisfied: pydub in c:\\python310\\lib\\site-packages (from gradio) (0.25.1)\n",
|
| 36 |
+
"Requirement already satisfied: python-multipart in c:\\python310\\lib\\site-packages (from gradio) (0.0.6)\n",
|
| 37 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio) (6.0)\n",
|
| 38 |
+
"Requirement already satisfied: requests~=2.0 in c:\\python310\\lib\\site-packages (from gradio) (2.31.0)\n",
|
| 39 |
+
"Requirement already satisfied: semantic-version~=2.0 in c:\\python310\\lib\\site-packages (from gradio) (2.10.0)\n",
|
| 40 |
+
"Requirement already satisfied: tomlkit==0.12.0 in c:\\python310\\lib\\site-packages (from gradio) (0.12.0)\n",
|
| 41 |
+
"Requirement already satisfied: typer<1.0,>=0.9 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer[all]<1.0,>=0.9->gradio) (0.9.0)\n",
|
| 42 |
+
"Requirement already satisfied: typing-extensions~=4.0 in c:\\python310\\lib\\site-packages (from gradio) (4.8.0)\n",
|
| 43 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in c:\\python310\\lib\\site-packages (from gradio) (0.24.0.post1)\n",
|
| 44 |
+
"Requirement already satisfied: fsspec in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from gradio-client==0.7.1->gradio) (2023.9.2)\n",
|
| 45 |
+
"Requirement already satisfied: websockets<12.0,>=10.0 in c:\\python310\\lib\\site-packages (from gradio-client==0.7.1->gradio) (11.0.3)\n",
|
| 46 |
+
"Requirement already satisfied: jsonschema>=3.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from altair<6.0,>=4.2.0->gradio) (4.17.3)\n",
|
| 47 |
+
"Requirement already satisfied: toolz in c:\\python310\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n",
|
| 48 |
+
"Requirement already satisfied: filelock in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from huggingface-hub>=0.14.0->gradio) (3.12.4)\n",
|
| 49 |
+
"Requirement already satisfied: tqdm>=4.42.1 in c:\\python310\\lib\\site-packages (from huggingface-hub>=0.14.0->gradio) (4.64.1)\n",
|
| 50 |
+
"Requirement already satisfied: contourpy>=1.0.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.1.1)\n",
|
| 51 |
+
"Requirement already satisfied: cycler>=0.10 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (0.12.0)\n",
|
| 52 |
+
"Requirement already satisfied: fonttools>=4.22.0 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (4.43.0)\n",
|
| 53 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
| 54 |
+
"Requirement already satisfied: pyparsing<3.1,>=2.3.1 in c:\\python310\\lib\\site-packages (from matplotlib~=3.0->gradio) (3.0.9)\n",
|
| 55 |
+
"Requirement already satisfied: python-dateutil>=2.7 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
| 56 |
+
"Requirement already satisfied: pytz>=2020.1 in c:\\python310\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
|
| 57 |
+
"Requirement already satisfied: tzdata>=2022.1 in c:\\python310\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2023.3)\n",
|
| 58 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
| 59 |
+
"Requirement already satisfied: pydantic-core==2.14.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from pydantic>=2.0->gradio) (2.14.5)\n",
|
| 60 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (2.1.1)\n",
|
| 61 |
+
"Requirement already satisfied: idna<4,>=2.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (3.4)\n",
|
| 62 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (1.26.14)\n",
|
| 63 |
+
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from requests~=2.0->gradio) (2022.12.7)\n",
|
| 64 |
+
"Requirement already satisfied: click<9.0.0,>=7.1.1 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer<1.0,>=0.9->typer[all]<1.0,>=0.9->gradio) (8.1.7)\n",
|
| 65 |
+
"Requirement already satisfied: colorama<0.5.0,>=0.4.3 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n",
|
| 66 |
+
"Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in c:\\python310\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n",
|
| 67 |
+
"Collecting rich<14.0.0,>=10.11.0 (from typer[all]<1.0,>=0.9->gradio)\n",
|
| 68 |
+
" Using cached rich-13.7.0-py3-none-any.whl.metadata (18 kB)\n",
|
| 69 |
+
"Requirement already satisfied: h11>=0.8 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n",
|
| 70 |
+
"Requirement already satisfied: anyio<4.0.0,>=3.7.1 in c:\\python310\\lib\\site-packages (from fastapi->gradio) (3.7.1)\n",
|
| 71 |
+
"Collecting starlette<0.28.0,>=0.27.0 (from fastapi->gradio)\n",
|
| 72 |
+
" Using cached starlette-0.27.0-py3-none-any.whl.metadata (5.8 kB)\n",
|
| 73 |
+
"Requirement already satisfied: httpcore in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from httpx->gradio) (1.0.2)\n",
|
| 74 |
+
"Requirement already satisfied: sniffio in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from httpx->gradio) (1.3.0)\n",
|
| 75 |
+
"Requirement already satisfied: exceptiongroup in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from anyio<4.0.0,>=3.7.1->fastapi->gradio) (1.1.0)\n",
|
| 76 |
+
"Requirement already satisfied: attrs>=17.4.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (22.2.0)\n",
|
| 77 |
+
"Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.19.3)\n",
|
| 78 |
+
"Requirement already satisfied: six>=1.5 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
| 79 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\python310\\lib\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n",
|
| 80 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\sachi\\appdata\\roaming\\python\\python310\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.14.0)\n",
|
| 81 |
+
"Requirement already satisfied: mdurl~=0.1 in c:\\python310\\lib\\site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n",
|
| 82 |
+
"Using cached gradio-4.8.0-py3-none-any.whl (16.5 MB)\n",
|
| 83 |
+
"Using cached gradio_client-0.7.1-py3-none-any.whl (302 kB)\n",
|
| 84 |
+
"Using cached altair-5.2.0-py3-none-any.whl (996 kB)\n",
|
| 85 |
+
"Using cached fastapi-0.104.1-py3-none-any.whl (92 kB)\n",
|
| 86 |
+
"Using cached rich-13.7.0-py3-none-any.whl (240 kB)\n",
|
| 87 |
+
"Using cached starlette-0.27.0-py3-none-any.whl (66 kB)\n",
|
| 88 |
+
"Installing collected packages: starlette, rich, gradio-client, fastapi, altair, gradio\n"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"name": "stderr",
|
| 93 |
+
"output_type": "stream",
|
| 94 |
+
"text": [
|
| 95 |
+
"WARNING: Ignoring invalid distribution - (c:\\python310\\lib\\site-packages)\n",
|
| 96 |
+
"WARNING: Ignoring invalid distribution -ip (c:\\python310\\lib\\site-packages)\n",
|
| 97 |
+
"WARNING: Ignoring invalid distribution - (c:\\python310\\lib\\site-packages)\n",
|
| 98 |
+
"WARNING: Ignoring invalid distribution -ip (c:\\python310\\lib\\site-packages)\n",
|
| 99 |
+
"DEPRECATION: google-images-search 1.4.6 has a non-standard dependency specifier click>=7.0<=8.1.*. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of google-images-search or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063\n",
|
| 100 |
+
" WARNING: Failed to write executable - trying to use .deleteme logic\n",
|
| 101 |
+
"ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\\\\Python310\\\\Scripts\\\\gradio.exe' -> 'C:\\\\Python310\\\\Scripts\\\\gradio.exe.deleteme'\n",
|
| 102 |
+
"\n",
|
| 103 |
+
"WARNING: There was an error checking the latest version of pip.\n"
|
| 104 |
+
]
|
| 105 |
+
}
|
| 106 |
+
],
|
| 107 |
+
"source": [
|
| 108 |
+
"!pip install gradio"
|
| 109 |
+
]
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"cell_type": "code",
|
| 113 |
+
"execution_count": 5,
|
| 114 |
+
"id": "72a80415",
|
| 115 |
+
"metadata": {},
|
| 116 |
+
"outputs": [
|
| 117 |
+
{
|
| 118 |
+
"name": "stdout",
|
| 119 |
+
"output_type": "stream",
|
| 120 |
+
"text": [
|
| 121 |
+
"Running on local URL: http://127.0.0.1:7862\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"data": {
|
| 128 |
+
"text/html": [
|
| 129 |
+
"<div><iframe src=\"http://127.0.0.1:7862/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 130 |
+
],
|
| 131 |
+
"text/plain": [
|
| 132 |
+
"<IPython.core.display.HTML object>"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"metadata": {},
|
| 136 |
+
"output_type": "display_data"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"data": {
|
| 140 |
+
"text/plain": []
|
| 141 |
+
},
|
| 142 |
+
"execution_count": 5,
|
| 143 |
+
"metadata": {},
|
| 144 |
+
"output_type": "execute_result"
|
| 145 |
+
}
|
| 146 |
+
],
|
| 147 |
+
"source": [
|
| 148 |
+
"import gradio as gr\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"def greet(name):\n",
|
| 151 |
+
" return \"Hello \" + name + \"!\"\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"demo = gr.Interface(\n",
|
| 154 |
+
" fn=greet,\n",
|
| 155 |
+
" inputs=gr.Textbox(lines=1, placeholder=\"Your name...\"), # inputs='text'\n",
|
| 156 |
+
" outputs=\"text\",\n",
|
| 157 |
+
")\n",
|
| 158 |
+
"demo.launch()"
|
| 159 |
+
]
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"cell_type": "code",
|
| 163 |
+
"execution_count": 12,
|
| 164 |
+
"id": "97060b90",
|
| 165 |
+
"metadata": {},
|
| 166 |
+
"outputs": [],
|
| 167 |
+
"source": [
|
| 168 |
+
"import gradio as gr\n",
|
| 169 |
+
"from fastai.vision.all import *\n",
|
| 170 |
+
"from PIL import Image\n",
|
| 171 |
+
"\n",
|
| 172 |
+
"# Load your trained/saved model\n",
|
| 173 |
+
"learn = load_learner('export.pkl')"
|
| 174 |
+
]
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"cell_type": "code",
|
| 178 |
+
"execution_count": 20,
|
| 179 |
+
"id": "a384fc20",
|
| 180 |
+
"metadata": {},
|
| 181 |
+
"outputs": [
|
| 182 |
+
{
|
| 183 |
+
"name": "stdout",
|
| 184 |
+
"output_type": "stream",
|
| 185 |
+
"text": [
|
| 186 |
+
"Running on local URL: http://127.0.0.1:7870\n",
|
| 187 |
+
"\n",
|
| 188 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 189 |
+
]
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"data": {
|
| 193 |
+
"text/html": [
|
| 194 |
+
"<div><iframe src=\"http://127.0.0.1:7870/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 195 |
+
],
|
| 196 |
+
"text/plain": [
|
| 197 |
+
"<IPython.core.display.HTML object>"
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"output_type": "display_data"
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"data": {
|
| 205 |
+
"text/plain": []
|
| 206 |
+
},
|
| 207 |
+
"execution_count": 20,
|
| 208 |
+
"metadata": {},
|
| 209 |
+
"output_type": "execute_result"
|
| 210 |
+
}
|
| 211 |
+
],
|
| 212 |
+
"source": [
|
| 213 |
+
"def classify_bear(image):\n",
|
| 214 |
+
" # convert PIL image to fastai image object\n",
|
| 215 |
+
" img = PILImage.create(image)\n",
|
| 216 |
+
" \n",
|
| 217 |
+
" # get predictions\n",
|
| 218 |
+
" pred, idx, probs = learn.predict(img)\n",
|
| 219 |
+
" \n",
|
| 220 |
+
" return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}\n",
|
| 221 |
+
"\n",
|
| 222 |
+
"example_images = [\n",
|
| 223 |
+
" 'images/black.jpg',\n",
|
| 224 |
+
" 'images/teddy.jpg',\n",
|
| 225 |
+
" 'images/grizzly.jpg',\n",
|
| 226 |
+
" 'images/black2.jpg',\n",
|
| 227 |
+
" 'images/grizzly2.jpg'\n",
|
| 228 |
+
"]\n",
|
| 229 |
+
"\n",
|
| 230 |
+
"iface = gr.Interface(\n",
|
| 231 |
+
" fn=classify_bear, \n",
|
| 232 |
+
" inputs=gr.Image(type='pil'), \n",
|
| 233 |
+
" outputs=gr.Label(num_top_classes=3),\n",
|
| 234 |
+
" examples=example_images,\n",
|
| 235 |
+
" description=\"Classify bear images as grizzly, black or teddy:\"\n",
|
| 236 |
+
")\n",
|
| 237 |
+
"iface.launch()"
|
| 238 |
+
]
|
| 239 |
+
},
|
| 240 |
+
{
|
| 241 |
+
"cell_type": "code",
|
| 242 |
+
"execution_count": null,
|
| 243 |
+
"id": "f35b70e4",
|
| 244 |
+
"metadata": {},
|
| 245 |
+
"outputs": [],
|
| 246 |
+
"source": []
|
| 247 |
+
}
|
| 248 |
+
],
|
| 249 |
+
"metadata": {
|
| 250 |
+
"kernelspec": {
|
| 251 |
+
"display_name": "Python 3 (ipykernel)",
|
| 252 |
+
"language": "python",
|
| 253 |
+
"name": "python3"
|
| 254 |
+
},
|
| 255 |
+
"language_info": {
|
| 256 |
+
"codemirror_mode": {
|
| 257 |
+
"name": "ipython",
|
| 258 |
+
"version": 3
|
| 259 |
+
},
|
| 260 |
+
"file_extension": ".py",
|
| 261 |
+
"mimetype": "text/x-python",
|
| 262 |
+
"name": "python",
|
| 263 |
+
"nbconvert_exporter": "python",
|
| 264 |
+
"pygments_lexer": "ipython3",
|
| 265 |
+
"version": "3.10.7"
|
| 266 |
+
}
|
| 267 |
+
},
|
| 268 |
+
"nbformat": 4,
|
| 269 |
+
"nbformat_minor": 5
|
| 270 |
+
}
|
app.py
CHANGED
|
@@ -1,20 +1,32 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
sepia_img /= sepia_img.max()
|
| 17 |
-
return sepia_img
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
# Load your trained/saved model
|
| 6 |
+
learn = load_learner('export.pkl')
|
| 7 |
|
| 8 |
+
def classify_bear(image):
|
| 9 |
+
# convert PIL image to fastai image object
|
| 10 |
+
img = PILImage.create(image)
|
| 11 |
+
|
| 12 |
+
# get predictions
|
| 13 |
+
pred, idx, probs = learn.predict(img)
|
| 14 |
+
|
| 15 |
+
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
|
| 16 |
|
| 17 |
+
example_images = [
|
| 18 |
+
'images/black.jpg',
|
| 19 |
+
'images/teddy.jpg',
|
| 20 |
+
'images/grizzly.jpg',
|
| 21 |
+
'images/black2.jpg',
|
| 22 |
+
'images/grizzly2.jpg'
|
| 23 |
+
]
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=classify_bear,
|
| 27 |
+
inputs=gr.Image(type='pil'),
|
| 28 |
+
outputs=gr.Label(num_top_classes=3),
|
| 29 |
+
examples=example_images,
|
| 30 |
+
description="Classify bear images as grizzly, black or teddy:"
|
| 31 |
+
)
|
| 32 |
+
iface.launch()
|
export.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:17cd7c4a2b6d1c830e313ec9d73c12ca4767d0d7f5796249ae86b69690b42884
|
| 3 |
+
size 46967998
|
images/black.jpg
ADDED
|
images/black2.jpg
ADDED
|
images/grizzly.jpg
ADDED
|
images/grizzly2.jpg
ADDED
|
images/teddy.jpg
ADDED
|