Upload appy.ipynb
Browse files- appy.ipynb +143 -0
appy.ipynb
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stderr",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"C:\\Users\\RAVI\\AppData\\Roaming\\Python\\Python39\\site-packages\\tqdm\\auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
13 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"from fastai.vision.all import *\n",
|
19 |
+
"import gradio as gr"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 5,
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"import pathlib"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "code",
|
33 |
+
"execution_count": 6,
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": [
|
37 |
+
"\n",
|
38 |
+
"def new_path(cls, *args, **kwargs):\n",
|
39 |
+
" \n",
|
40 |
+
" cls = pathlib.WindowsPath\n",
|
41 |
+
" self = cls._from_parts(args)\n",
|
42 |
+
" if not self._flavour.is_supported:\n",
|
43 |
+
" raise NotImplementedError(\"cannot instantiate %r on your system\"\n",
|
44 |
+
" % (cls.__name__,))\n",
|
45 |
+
" return self\n",
|
46 |
+
"Path.__new__=new_path"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 7,
|
52 |
+
"metadata": {},
|
53 |
+
"outputs": [],
|
54 |
+
"source": [
|
55 |
+
"def is_cat(x): return x[0].isupper() \n",
|
56 |
+
"\n",
|
57 |
+
"learn = load_learner('model.pkl')\n",
|
58 |
+
"categories = ('Dog', 'Cat')"
|
59 |
+
]
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"execution_count": 8,
|
64 |
+
"metadata": {},
|
65 |
+
"outputs": [],
|
66 |
+
"source": [
|
67 |
+
"def classify_image(img):\n",
|
68 |
+
" pred,idx,probs = learn.predict(img)\n",
|
69 |
+
" return dict(zip(categories, map(float, probs)))\n"
|
70 |
+
]
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"cell_type": "code",
|
74 |
+
"execution_count": 10,
|
75 |
+
"metadata": {},
|
76 |
+
"outputs": [
|
77 |
+
{
|
78 |
+
"name": "stdout",
|
79 |
+
"output_type": "stream",
|
80 |
+
"text": [
|
81 |
+
"Running on local URL: http://127.0.0.1:7860/\n",
|
82 |
+
"\n",
|
83 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
84 |
+
]
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"data": {
|
88 |
+
"text/plain": [
|
89 |
+
"(<gradio.routes.App at 0x1be650336a0>, 'http://127.0.0.1:7860/', None)"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
"execution_count": 10,
|
93 |
+
"metadata": {},
|
94 |
+
"output_type": "execute_result"
|
95 |
+
}
|
96 |
+
],
|
97 |
+
"source": [
|
98 |
+
"\n",
|
99 |
+
"image = gr.Image(shape=(192,192))\n",
|
100 |
+
"label = gr.Label()\n",
|
101 |
+
"examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']\n",
|
102 |
+
"\n",
|
103 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
104 |
+
"intf.launch(inline=False)\n",
|
105 |
+
"\n"
|
106 |
+
]
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"cell_type": "code",
|
110 |
+
"execution_count": null,
|
111 |
+
"metadata": {},
|
112 |
+
"outputs": [],
|
113 |
+
"source": []
|
114 |
+
}
|
115 |
+
],
|
116 |
+
"metadata": {
|
117 |
+
"kernelspec": {
|
118 |
+
"display_name": "Python 3.9.4 64-bit",
|
119 |
+
"language": "python",
|
120 |
+
"name": "python3"
|
121 |
+
},
|
122 |
+
"language_info": {
|
123 |
+
"codemirror_mode": {
|
124 |
+
"name": "ipython",
|
125 |
+
"version": 3
|
126 |
+
},
|
127 |
+
"file_extension": ".py",
|
128 |
+
"mimetype": "text/x-python",
|
129 |
+
"name": "python",
|
130 |
+
"nbconvert_exporter": "python",
|
131 |
+
"pygments_lexer": "ipython3",
|
132 |
+
"version": "3.9.4"
|
133 |
+
},
|
134 |
+
"orig_nbformat": 4,
|
135 |
+
"vscode": {
|
136 |
+
"interpreter": {
|
137 |
+
"hash": "11938c6bc6919ae2720b4d5011047913343b08a43b18698fd82dedb0d4417594"
|
138 |
+
}
|
139 |
+
}
|
140 |
+
},
|
141 |
+
"nbformat": 4,
|
142 |
+
"nbformat_minor": 2
|
143 |
+
}
|