Spaces:
Running
Running
let's deploy to huggingface spaces
Browse files- app.py +46 -0
- keeshond.jpeg +0 -0
- maine_coon.jpeg +0 -0
- pet_breeds.pkl +3 -0
- pet_breeds_prod.ipynb +192 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[1]:
|
5 |
+
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
from fastai.vision.all import *
|
9 |
+
|
10 |
+
|
11 |
+
# In[3]:
|
12 |
+
|
13 |
+
|
14 |
+
def breed_name(x):
|
15 |
+
return ''.join([char for char in x if not char.isdigit()][:-5])
|
16 |
+
learn = load_learner('pet_breeds.pkl')
|
17 |
+
|
18 |
+
|
19 |
+
# In[4]:
|
20 |
+
|
21 |
+
|
22 |
+
labels = learn.dls.vocab
|
23 |
+
def predict(img):
|
24 |
+
img = PILImage.create(img)
|
25 |
+
pred,pred_idx,probs = learn.predict(img)
|
26 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
27 |
+
|
28 |
+
|
29 |
+
# In[5]:
|
30 |
+
|
31 |
+
|
32 |
+
gr.Interface(fn=predict,
|
33 |
+
inputs=gr.components.Image(height=512, width=512),
|
34 |
+
outputs=gr.components.Label(num_top_classes=3),
|
35 |
+
title='What breed is it ?',
|
36 |
+
description='A pet breeds classifier',
|
37 |
+
article="<p style='text-align: center'><a href='https://www.tanishq.ai/blog/posts/2021-11-16-gradio-huggingface.html' target='_blank'>Reference</a></p>",
|
38 |
+
examples=['keeshond.jpeg', 'maine_coon.jpeg']
|
39 |
+
).launch(share=True)
|
40 |
+
|
41 |
+
|
42 |
+
# In[ ]:
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
keeshond.jpeg
ADDED
![]() |
maine_coon.jpeg
ADDED
![]() |
pet_breeds.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b0331fc05ba0160fb8238e7b34f515b2ad22bb940eec8580eba28735edec353
|
3 |
+
size 179457366
|
pet_breeds_prod.ipynb
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "5e13806a-fd9c-4685-adc2-4cf72cb36720",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import gradio as gr\n",
|
11 |
+
"from fastai.vision.all import *"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 3,
|
17 |
+
"id": "accabd51-74ca-4852-b0ef-8b896d4e90d3",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"def breed_name(x):\n",
|
22 |
+
" return ''.join([char for char in x if not char.isdigit()][:-5])\n",
|
23 |
+
"learn = load_learner('pet_breeds.pkl')"
|
24 |
+
]
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"cell_type": "code",
|
28 |
+
"execution_count": 4,
|
29 |
+
"id": "da5e1ef5-bbeb-4a2b-a85e-6ea89acce255",
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [],
|
32 |
+
"source": [
|
33 |
+
"labels = learn.dls.vocab\n",
|
34 |
+
"def predict(img):\n",
|
35 |
+
" img = PILImage.create(img)\n",
|
36 |
+
" pred,pred_idx,probs = learn.predict(img)\n",
|
37 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "code",
|
42 |
+
"execution_count": 5,
|
43 |
+
"id": "fed109a8-1988-4acf-b59c-4e485bf84eab",
|
44 |
+
"metadata": {},
|
45 |
+
"outputs": [
|
46 |
+
{
|
47 |
+
"name": "stdout",
|
48 |
+
"output_type": "stream",
|
49 |
+
"text": [
|
50 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
51 |
+
"Running on public URL: https://cfc020d066f0b2c918.gradio.live\n",
|
52 |
+
"\n",
|
53 |
+
"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"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"data": {
|
58 |
+
"text/html": [
|
59 |
+
"<div><iframe src=\"https://cfc020d066f0b2c918.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
60 |
+
],
|
61 |
+
"text/plain": [
|
62 |
+
"<IPython.core.display.HTML object>"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
"metadata": {},
|
66 |
+
"output_type": "display_data"
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"data": {
|
70 |
+
"text/plain": []
|
71 |
+
},
|
72 |
+
"execution_count": 5,
|
73 |
+
"metadata": {},
|
74 |
+
"output_type": "execute_result"
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"data": {
|
78 |
+
"text/html": [
|
79 |
+
"\n",
|
80 |
+
"<style>\n",
|
81 |
+
" /* Turns off some styling */\n",
|
82 |
+
" progress {\n",
|
83 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
84 |
+
" border: none;\n",
|
85 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
86 |
+
" background-size: auto;\n",
|
87 |
+
" }\n",
|
88 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
89 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
90 |
+
" }\n",
|
91 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
92 |
+
" background: #F44336;\n",
|
93 |
+
" }\n",
|
94 |
+
"</style>\n"
|
95 |
+
],
|
96 |
+
"text/plain": [
|
97 |
+
"<IPython.core.display.HTML object>"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
"metadata": {},
|
101 |
+
"output_type": "display_data"
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"data": {
|
105 |
+
"text/html": [],
|
106 |
+
"text/plain": [
|
107 |
+
"<IPython.core.display.HTML object>"
|
108 |
+
]
|
109 |
+
},
|
110 |
+
"metadata": {},
|
111 |
+
"output_type": "display_data"
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"data": {
|
115 |
+
"text/html": [
|
116 |
+
"\n",
|
117 |
+
"<style>\n",
|
118 |
+
" /* Turns off some styling */\n",
|
119 |
+
" progress {\n",
|
120 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
121 |
+
" border: none;\n",
|
122 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
123 |
+
" background-size: auto;\n",
|
124 |
+
" }\n",
|
125 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
126 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
127 |
+
" }\n",
|
128 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
129 |
+
" background: #F44336;\n",
|
130 |
+
" }\n",
|
131 |
+
"</style>\n"
|
132 |
+
],
|
133 |
+
"text/plain": [
|
134 |
+
"<IPython.core.display.HTML object>"
|
135 |
+
]
|
136 |
+
},
|
137 |
+
"metadata": {},
|
138 |
+
"output_type": "display_data"
|
139 |
+
},
|
140 |
+
{
|
141 |
+
"data": {
|
142 |
+
"text/html": [],
|
143 |
+
"text/plain": [
|
144 |
+
"<IPython.core.display.HTML object>"
|
145 |
+
]
|
146 |
+
},
|
147 |
+
"metadata": {},
|
148 |
+
"output_type": "display_data"
|
149 |
+
}
|
150 |
+
],
|
151 |
+
"source": [
|
152 |
+
"gr.Interface(fn=predict,\n",
|
153 |
+
" inputs=gr.components.Image(height=512, width=512),\n",
|
154 |
+
" outputs=gr.components.Label(num_top_classes=3),\n",
|
155 |
+
" title='What breed is it ?',\n",
|
156 |
+
" description='A pet breeds classifier',\n",
|
157 |
+
" article=\"<p style='text-align: center'><a href='https://www.tanishq.ai/blog/posts/2021-11-16-gradio-huggingface.html' target='_blank'>Reference</a></p>\",\n",
|
158 |
+
" examples=['keeshond.jpeg', 'maine_coon.jpeg']\n",
|
159 |
+
" ).launch(share=True)"
|
160 |
+
]
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"cell_type": "code",
|
164 |
+
"execution_count": null,
|
165 |
+
"id": "5ac9ad24-503e-46ee-a24f-d0c41af63453",
|
166 |
+
"metadata": {},
|
167 |
+
"outputs": [],
|
168 |
+
"source": []
|
169 |
+
}
|
170 |
+
],
|
171 |
+
"metadata": {
|
172 |
+
"kernelspec": {
|
173 |
+
"display_name": "Python 3 (ipykernel)",
|
174 |
+
"language": "python",
|
175 |
+
"name": "python3"
|
176 |
+
},
|
177 |
+
"language_info": {
|
178 |
+
"codemirror_mode": {
|
179 |
+
"name": "ipython",
|
180 |
+
"version": 3
|
181 |
+
},
|
182 |
+
"file_extension": ".py",
|
183 |
+
"mimetype": "text/x-python",
|
184 |
+
"name": "python",
|
185 |
+
"nbconvert_exporter": "python",
|
186 |
+
"pygments_lexer": "ipython3",
|
187 |
+
"version": "3.11.9"
|
188 |
+
}
|
189 |
+
},
|
190 |
+
"nbformat": 4,
|
191 |
+
"nbformat_minor": 5
|
192 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|