Spaces:
Sleeping
Sleeping
Commit
·
bb37043
1
Parent(s):
d43d2b3
animal identifier
Browse files- app.py +16 -4
- cat.jpg +0 -0
- dog.jpg +0 -0
- lesson2_app.ipynb +139 -0
- model.pkl +3 -0
app.py
CHANGED
@@ -1,7 +1,19 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
+
def is_cat(x): return x[0].isupper()
|
|
|
5 |
|
6 |
+
learn = load_learner('model.pkl')
|
7 |
+
|
8 |
+
categories = ('Dog', 'Cat')
|
9 |
+
|
10 |
+
def classify_image(img):
|
11 |
+
pred, idx, probs = learn.predict(img)
|
12 |
+
return dict(zip(categories, map(float, probs)))
|
13 |
+
|
14 |
+
image = gr.Image(height=192, width=192)
|
15 |
+
label = gr.Label()
|
16 |
+
examples = ['dog.jpg', 'cat.jpg']
|
17 |
+
|
18 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
19 |
+
intf.launch(inline=False)
|
cat.jpg
ADDED
![]() |
dog.jpg
ADDED
![]() |
lesson2_app.ipynb
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "27c92395-9f07-4383-9526-58363a090f46",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from fastai.vision.all import *\n",
|
11 |
+
"import gradio as gr"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 2,
|
17 |
+
"id": "a8969a2b-13c0-496d-918b-179bcd1ad7b8",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"def is_cat(x): return x[0].isupper()"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "code",
|
26 |
+
"execution_count": 3,
|
27 |
+
"id": "407054be-12ef-40f0-860f-856e8a835a5e",
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"learn = load_learner('model.pkl')"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 4,
|
37 |
+
"id": "51f3903e-55c2-476e-96f9-ece20e49915c",
|
38 |
+
"metadata": {},
|
39 |
+
"outputs": [],
|
40 |
+
"source": [
|
41 |
+
"categories = ('Dog', 'Cat')"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "code",
|
46 |
+
"execution_count": 5,
|
47 |
+
"id": "3067fd5b-4872-4a0b-94bb-3a245129f340",
|
48 |
+
"metadata": {},
|
49 |
+
"outputs": [],
|
50 |
+
"source": [
|
51 |
+
"def classify_image(img):\n",
|
52 |
+
" pred, idx, probs = learn.predict(img)\n",
|
53 |
+
" return dict(zip(categories, map(float, probs)))"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"cell_type": "code",
|
58 |
+
"execution_count": 6,
|
59 |
+
"id": "f285720c-a8d3-46ba-80e9-8e5ef79ec4ec",
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"image = gr.Image(height=192, width=192)\n",
|
64 |
+
"label = gr.Label()\n",
|
65 |
+
"examples = ['dog.jpg', 'cat.jpg']"
|
66 |
+
]
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"cell_type": "code",
|
70 |
+
"execution_count": 7,
|
71 |
+
"id": "9ae63726-4b8b-4d9c-9a95-a18e9ffe61ab",
|
72 |
+
"metadata": {},
|
73 |
+
"outputs": [
|
74 |
+
{
|
75 |
+
"name": "stdout",
|
76 |
+
"output_type": "stream",
|
77 |
+
"text": [
|
78 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
79 |
+
"\n",
|
80 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"data": {
|
85 |
+
"text/plain": []
|
86 |
+
},
|
87 |
+
"execution_count": 7,
|
88 |
+
"metadata": {},
|
89 |
+
"output_type": "execute_result"
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"data": {
|
93 |
+
"text/html": [],
|
94 |
+
"text/plain": [
|
95 |
+
"<IPython.core.display.HTML object>"
|
96 |
+
]
|
97 |
+
},
|
98 |
+
"metadata": {},
|
99 |
+
"output_type": "display_data"
|
100 |
+
},
|
101 |
+
{
|
102 |
+
"data": {
|
103 |
+
"text/html": [],
|
104 |
+
"text/plain": [
|
105 |
+
"<IPython.core.display.HTML object>"
|
106 |
+
]
|
107 |
+
},
|
108 |
+
"metadata": {},
|
109 |
+
"output_type": "display_data"
|
110 |
+
}
|
111 |
+
],
|
112 |
+
"source": [
|
113 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
114 |
+
"intf.launch(inline=False)"
|
115 |
+
]
|
116 |
+
}
|
117 |
+
],
|
118 |
+
"metadata": {
|
119 |
+
"kernelspec": {
|
120 |
+
"display_name": "Python (base)",
|
121 |
+
"language": "python",
|
122 |
+
"name": "base"
|
123 |
+
},
|
124 |
+
"language_info": {
|
125 |
+
"codemirror_mode": {
|
126 |
+
"name": "ipython",
|
127 |
+
"version": 3
|
128 |
+
},
|
129 |
+
"file_extension": ".py",
|
130 |
+
"mimetype": "text/x-python",
|
131 |
+
"name": "python",
|
132 |
+
"nbconvert_exporter": "python",
|
133 |
+
"pygments_lexer": "ipython3",
|
134 |
+
"version": "3.12.2"
|
135 |
+
}
|
136 |
+
},
|
137 |
+
"nbformat": 4,
|
138 |
+
"nbformat_minor": 5
|
139 |
+
}
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8251e3c47bcb22beee5c3a8e2a8503a68a11386120965a6842e16117a875fbcd
|
3 |
+
size 47077758
|