Spaces:
Runtime error
Runtime error
Delete app.ipynb
Browse files
app.ipynb
DELETED
@@ -1,272 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": 18,
|
6 |
-
"metadata": {},
|
7 |
-
"outputs": [],
|
8 |
-
"source": [
|
9 |
-
"import gradio as gr\n",
|
10 |
-
"import tensorflow as tf\n",
|
11 |
-
"import numpy as np\n",
|
12 |
-
"from PIL import Image"
|
13 |
-
]
|
14 |
-
},
|
15 |
-
{
|
16 |
-
"cell_type": "code",
|
17 |
-
"execution_count": 19,
|
18 |
-
"metadata": {},
|
19 |
-
"outputs": [
|
20 |
-
{
|
21 |
-
"name": "stdout",
|
22 |
-
"output_type": "stream",
|
23 |
-
"text": [
|
24 |
-
"Defaulting to user installation because normal site-packages is not writeable\n",
|
25 |
-
"Requirement already satisfied: tensorflow in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (2.16.1)\n",
|
26 |
-
"Requirement already satisfied: tensorflow-datasets in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (4.9.3)\n",
|
27 |
-
"Requirement already satisfied: gradio in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (4.27.0)\n",
|
28 |
-
"Requirement already satisfied: pillow in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (10.2.0)\n",
|
29 |
-
"Requirement already satisfied: matplotlib in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (3.8.3)\n",
|
30 |
-
"Requirement already satisfied: absl-py>=1.0.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (1.4.0)\n",
|
31 |
-
"Requirement already satisfied: astunparse>=1.6.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (1.6.3)\n",
|
32 |
-
"Requirement already satisfied: flatbuffers>=23.5.26 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (24.3.25)\n",
|
33 |
-
"Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (0.5.4)\n",
|
34 |
-
"Requirement already satisfied: google-pasta>=0.1.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (0.2.0)\n",
|
35 |
-
"Requirement already satisfied: h5py>=3.10.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (3.11.0)\n",
|
36 |
-
"Requirement already satisfied: libclang>=13.0.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (18.1.1)\n",
|
37 |
-
"Requirement already satisfied: ml-dtypes~=0.3.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (0.3.2)\n",
|
38 |
-
"Requirement already satisfied: opt-einsum>=2.3.2 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (3.3.0)\n",
|
39 |
-
"Requirement already satisfied: packaging in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (23.2)\n",
|
40 |
-
"Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (3.20.3)\n",
|
41 |
-
"Requirement already satisfied: requests<3,>=2.21.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (2.31.0)\n",
|
42 |
-
"Requirement already satisfied: setuptools in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (58.0.4)\n",
|
43 |
-
"Requirement already satisfied: six>=1.12.0 in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (1.15.0)\n",
|
44 |
-
"Requirement already satisfied: termcolor>=1.1.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (2.4.0)\n",
|
45 |
-
"Requirement already satisfied: typing-extensions>=3.6.6 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (4.9.0)\n",
|
46 |
-
"Requirement already satisfied: wrapt>=1.11.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (1.16.0)\n",
|
47 |
-
"Requirement already satisfied: grpcio<2.0,>=1.24.3 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (1.62.2)\n",
|
48 |
-
"Requirement already satisfied: tensorboard<2.17,>=2.16 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (2.16.2)\n",
|
49 |
-
"Requirement already satisfied: keras>=3.0.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (3.2.1)\n",
|
50 |
-
"Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (0.36.0)\n",
|
51 |
-
"Requirement already satisfied: numpy<2.0.0,>=1.23.5 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow) (1.26.4)\n",
|
52 |
-
"Requirement already satisfied: array-record in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (0.4.1)\n",
|
53 |
-
"Requirement already satisfied: click in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (8.1.7)\n",
|
54 |
-
"Requirement already satisfied: dm-tree in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (0.1.8)\n",
|
55 |
-
"Requirement already satisfied: etils>=0.9.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from etils[enp,epath,etree]>=0.9.0->tensorflow-datasets) (1.5.2)\n",
|
56 |
-
"Requirement already satisfied: promise in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (2.3)\n",
|
57 |
-
"Requirement already satisfied: psutil in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (5.9.6)\n",
|
58 |
-
"Requirement already satisfied: tensorflow-metadata in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (1.14.0)\n",
|
59 |
-
"Requirement already satisfied: toml in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (0.10.2)\n",
|
60 |
-
"Requirement already satisfied: tqdm in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-datasets) (4.66.2)\n",
|
61 |
-
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (23.2.1)\n",
|
62 |
-
"Requirement already satisfied: altair<6.0,>=4.2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (5.3.0)\n",
|
63 |
-
"Requirement already satisfied: fastapi in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.110.2)\n",
|
64 |
-
"Requirement already satisfied: ffmpy in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.3.2)\n",
|
65 |
-
"Requirement already satisfied: gradio-client==0.15.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.15.1)\n",
|
66 |
-
"Requirement already satisfied: httpx>=0.24.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.27.0)\n",
|
67 |
-
"Requirement already satisfied: huggingface-hub>=0.19.3 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.22.2)\n",
|
68 |
-
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (6.1.1)\n",
|
69 |
-
"Requirement already satisfied: jinja2<4.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (3.1.3)\n",
|
70 |
-
"Requirement already satisfied: markupsafe~=2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (2.1.5)\n",
|
71 |
-
"Requirement already satisfied: orjson~=3.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (3.10.1)\n",
|
72 |
-
"Requirement already satisfied: pandas<3.0,>=1.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (2.2.0)\n",
|
73 |
-
"Requirement already satisfied: pydantic>=2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (2.7.0)\n",
|
74 |
-
"Requirement already satisfied: pydub in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.25.1)\n",
|
75 |
-
"Requirement already satisfied: python-multipart>=0.0.9 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.0.9)\n",
|
76 |
-
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (6.0.1)\n",
|
77 |
-
"Requirement already satisfied: ruff>=0.2.2 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.4.1)\n",
|
78 |
-
"Requirement already satisfied: semantic-version~=2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (2.10.0)\n",
|
79 |
-
"Requirement already satisfied: tomlkit==0.12.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.12.0)\n",
|
80 |
-
"Requirement already satisfied: typer<1.0,>=0.12 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.12.3)\n",
|
81 |
-
"Requirement already satisfied: urllib3~=2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (2.2.1)\n",
|
82 |
-
"Requirement already satisfied: uvicorn>=0.14.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio) (0.29.0)\n",
|
83 |
-
"Requirement already satisfied: fsspec in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio-client==0.15.1->gradio) (2024.3.1)\n",
|
84 |
-
"Requirement already satisfied: websockets<12.0,>=10.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from gradio-client==0.15.1->gradio) (11.0.3)\n",
|
85 |
-
"Requirement already satisfied: contourpy>=1.0.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (1.2.0)\n",
|
86 |
-
"Requirement already satisfied: cycler>=0.10 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (0.12.1)\n",
|
87 |
-
"Requirement already satisfied: fonttools>=4.22.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (4.49.0)\n",
|
88 |
-
"Requirement already satisfied: kiwisolver>=1.3.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (1.4.5)\n",
|
89 |
-
"Requirement already satisfied: pyparsing>=2.3.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (3.1.1)\n",
|
90 |
-
"Requirement already satisfied: python-dateutil>=2.7 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from matplotlib) (2.8.2)\n",
|
91 |
-
"Requirement already satisfied: jsonschema>=3.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from altair<6.0,>=4.2.0->gradio) (4.21.1)\n",
|
92 |
-
"Requirement already satisfied: toolz in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n",
|
93 |
-
"Requirement already satisfied: wheel<1.0,>=0.23.0 in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (from astunparse>=1.6.0->tensorflow) (0.37.0)\n",
|
94 |
-
"Requirement already satisfied: zipp in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from etils[enp,epath,etree]>=0.9.0->tensorflow-datasets) (3.17.0)\n",
|
95 |
-
"Requirement already satisfied: anyio in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpx>=0.24.1->gradio) (4.3.0)\n",
|
96 |
-
"Requirement already satisfied: certifi in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpx>=0.24.1->gradio) (2024.2.2)\n",
|
97 |
-
"Requirement already satisfied: httpcore==1.* in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n",
|
98 |
-
"Requirement already satisfied: idna in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpx>=0.24.1->gradio) (3.7)\n",
|
99 |
-
"Requirement already satisfied: sniffio in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpx>=0.24.1->gradio) (1.3.1)\n",
|
100 |
-
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
|
101 |
-
"Requirement already satisfied: filelock in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from huggingface-hub>=0.19.3->gradio) (3.13.4)\n",
|
102 |
-
"Requirement already satisfied: rich in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from keras>=3.0.0->tensorflow) (13.7.1)\n",
|
103 |
-
"Requirement already satisfied: namex in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from keras>=3.0.0->tensorflow) (0.0.8)\n",
|
104 |
-
"Requirement already satisfied: optree in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from keras>=3.0.0->tensorflow) (0.11.0)\n",
|
105 |
-
"Requirement already satisfied: pytz>=2020.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
|
106 |
-
"Requirement already satisfied: tzdata>=2022.7 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
|
107 |
-
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
108 |
-
"Requirement already satisfied: pydantic-core==2.18.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from pydantic>=2.0->gradio) (2.18.1)\n",
|
109 |
-
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from requests<3,>=2.21.0->tensorflow) (3.3.2)\n",
|
110 |
-
"Requirement already satisfied: markdown>=2.6.8 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorboard<2.17,>=2.16->tensorflow) (3.6)\n",
|
111 |
-
"Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorboard<2.17,>=2.16->tensorflow) (0.7.2)\n",
|
112 |
-
"Requirement already satisfied: werkzeug>=1.0.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorboard<2.17,>=2.16->tensorflow) (3.0.2)\n",
|
113 |
-
"Requirement already satisfied: shellingham>=1.3.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
114 |
-
"Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from fastapi->gradio) (0.37.2)\n",
|
115 |
-
"Requirement already satisfied: googleapis-common-protos<2,>=1.52.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from tensorflow-metadata->tensorflow-datasets) (1.63.0)\n",
|
116 |
-
"Requirement already satisfied: attrs>=22.2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n",
|
117 |
-
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n",
|
118 |
-
"Requirement already satisfied: referencing>=0.28.4 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.34.0)\n",
|
119 |
-
"Requirement already satisfied: rpds-py>=0.7.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.0)\n",
|
120 |
-
"Requirement already satisfied: importlib-metadata>=4.4 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from markdown>=2.6.8->tensorboard<2.17,>=2.16->tensorflow) (7.0.0)\n",
|
121 |
-
"Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from rich->keras>=3.0.0->tensorflow) (3.0.0)\n",
|
122 |
-
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from rich->keras>=3.0.0->tensorflow) (2.17.2)\n",
|
123 |
-
"Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from anyio->httpx>=0.24.1->gradio) (1.2.0)\n",
|
124 |
-
"Requirement already satisfied: mdurl~=0.1 in /Users/chiarazbinden/Library/Python/3.9/lib/python/site-packages (from markdown-it-py>=2.2.0->rich->keras>=3.0.0->tensorflow) (0.1.2)\n",
|
125 |
-
"Note: you may need to restart the kernel to use updated packages.\n"
|
126 |
-
]
|
127 |
-
}
|
128 |
-
],
|
129 |
-
"source": [
|
130 |
-
"%pip install tensorflow tensorflow-datasets gradio pillow matplotlib"
|
131 |
-
]
|
132 |
-
},
|
133 |
-
{
|
134 |
-
"cell_type": "code",
|
135 |
-
"execution_count": 20,
|
136 |
-
"metadata": {},
|
137 |
-
"outputs": [],
|
138 |
-
"source": [
|
139 |
-
"model_path = \"pokemon-model_transferlearning.keras\"\n",
|
140 |
-
"model = tf.keras.models.load_model(model_path)"
|
141 |
-
]
|
142 |
-
},
|
143 |
-
{
|
144 |
-
"cell_type": "code",
|
145 |
-
"execution_count": 21,
|
146 |
-
"metadata": {},
|
147 |
-
"outputs": [],
|
148 |
-
"source": [
|
149 |
-
"# Define the core prediction function\n",
|
150 |
-
"def predict_pokemon(image):\n",
|
151 |
-
" # Preprocess image\n",
|
152 |
-
" print(type(image))\n",
|
153 |
-
" image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image\n",
|
154 |
-
" image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale\n",
|
155 |
-
" image = np.array(image)\n",
|
156 |
-
" image = np.expand_dims(image, axis=0) # same as image[None, ...]\n",
|
157 |
-
" \n",
|
158 |
-
" # Predict\n",
|
159 |
-
" prediction = model.predict(image)\n",
|
160 |
-
" \n",
|
161 |
-
" # Because the output layer was dense(0) without an activation function, we need to apply sigmoid to get the probability\n",
|
162 |
-
" # we could also change the output layer to dense(1, activation='sigmoid')\n",
|
163 |
-
" prediction = np.round(float(tf.sigmoid(prediction)), 2)\n",
|
164 |
-
" p_cat = (1 - prediction)\n",
|
165 |
-
" p_dog = prediction\n",
|
166 |
-
" return {'cat': p_cat, 'dog': p_dog}"
|
167 |
-
]
|
168 |
-
},
|
169 |
-
{
|
170 |
-
"cell_type": "code",
|
171 |
-
"execution_count": 22,
|
172 |
-
"metadata": {},
|
173 |
-
"outputs": [],
|
174 |
-
"source": [
|
175 |
-
"from PIL import Image\n",
|
176 |
-
"import numpy as np\n",
|
177 |
-
"import tensorflow as tf\n",
|
178 |
-
"\n",
|
179 |
-
"# Define the core prediction function\n",
|
180 |
-
"def predict_pokemon(image):\n",
|
181 |
-
" # Preprocess image\n",
|
182 |
-
" image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image\n",
|
183 |
-
" image = image.resize((150, 150)) # Resize the image to 150x150\n",
|
184 |
-
" image = np.array(image)\n",
|
185 |
-
" image = np.expand_dims(image, axis=0) # Add batch dimension\n",
|
186 |
-
" \n",
|
187 |
-
" # Predict\n",
|
188 |
-
" prediction = model.predict(image)\n",
|
189 |
-
" \n",
|
190 |
-
" # Apply softmax to get probabilities for each class\n",
|
191 |
-
" probabilities = tf.nn.softmax(prediction)\n",
|
192 |
-
" \n",
|
193 |
-
" # Map probabilities to Pokemon classes\n",
|
194 |
-
" pokemon_classes = ['Articuno', 'Bulbasaur', 'Charmander'] \n",
|
195 |
-
" probabilities_dict = {pokemon_class: round(float(probability), 2) for pokemon_class, probability in zip(pokemon_classes, probabilities[0])}\n",
|
196 |
-
" \n",
|
197 |
-
" return probabilities_dict\n"
|
198 |
-
]
|
199 |
-
},
|
200 |
-
{
|
201 |
-
"cell_type": "code",
|
202 |
-
"execution_count": 23,
|
203 |
-
"metadata": {},
|
204 |
-
"outputs": [
|
205 |
-
{
|
206 |
-
"name": "stdout",
|
207 |
-
"output_type": "stream",
|
208 |
-
"text": [
|
209 |
-
"Running on local URL: http://127.0.0.1:7863\n",
|
210 |
-
"IMPORTANT: You are using gradio version 4.27.0, however version 4.29.0 is available, please upgrade.\n",
|
211 |
-
"--------\n",
|
212 |
-
"Running on public URL: https://a1f42e2a7f46b68a92.gradio.live\n",
|
213 |
-
"\n",
|
214 |
-
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
215 |
-
]
|
216 |
-
},
|
217 |
-
{
|
218 |
-
"data": {
|
219 |
-
"text/html": [
|
220 |
-
"<div><iframe src=\"https://a1f42e2a7f46b68a92.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
221 |
-
],
|
222 |
-
"text/plain": [
|
223 |
-
"<IPython.core.display.HTML object>"
|
224 |
-
]
|
225 |
-
},
|
226 |
-
"metadata": {},
|
227 |
-
"output_type": "display_data"
|
228 |
-
},
|
229 |
-
{
|
230 |
-
"data": {
|
231 |
-
"text/plain": []
|
232 |
-
},
|
233 |
-
"execution_count": 23,
|
234 |
-
"metadata": {},
|
235 |
-
"output_type": "execute_result"
|
236 |
-
}
|
237 |
-
],
|
238 |
-
"source": [
|
239 |
-
"# Create the Gradio interface\n",
|
240 |
-
"input_image = gr.Image()\n",
|
241 |
-
"iface = gr.Interface(\n",
|
242 |
-
" fn=predict_pokemon,\n",
|
243 |
-
" inputs=input_image, \n",
|
244 |
-
" outputs=gr.Label(),\n",
|
245 |
-
" examples=[\"images/cat1.jpeg\", \"images/cat2.jpeg\", \"images/cat3.jpeg\", \"images/cat4.jpeg\", \"images/dog1.jpeg\", \"images/dog2.jpeg\", \"images/dog3.jpeg\"], \n",
|
246 |
-
" description=\"A simple mlp classification model for image classification using the mnist dataset.\")\n",
|
247 |
-
"iface.launch(share=True)"
|
248 |
-
]
|
249 |
-
}
|
250 |
-
],
|
251 |
-
"metadata": {
|
252 |
-
"kernelspec": {
|
253 |
-
"display_name": "Python 3",
|
254 |
-
"language": "python",
|
255 |
-
"name": "python3"
|
256 |
-
},
|
257 |
-
"language_info": {
|
258 |
-
"codemirror_mode": {
|
259 |
-
"name": "ipython",
|
260 |
-
"version": 3
|
261 |
-
},
|
262 |
-
"file_extension": ".py",
|
263 |
-
"mimetype": "text/x-python",
|
264 |
-
"name": "python",
|
265 |
-
"nbconvert_exporter": "python",
|
266 |
-
"pygments_lexer": "ipython3",
|
267 |
-
"version": "3.9.6"
|
268 |
-
}
|
269 |
-
},
|
270 |
-
"nbformat": 4,
|
271 |
-
"nbformat_minor": 2
|
272 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|