stonkszain commited on
Commit
cc600f0
·
verified ·
1 Parent(s): a9873dc

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.ipynb +238 -0
  2. app.py +13 -0
  3. requirements.txt +1 -0
app.ipynb ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from fastai.vision.all import *\n",
10
+ "import gradio as gr\n",
11
+ "import timm"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": null,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "* Running on local URL: http://127.0.0.1:7860\n",
24
+ "\n",
25
+ "To create a public link, set `share=True` in `launch()`.\n"
26
+ ]
27
+ },
28
+ {
29
+ "data": {
30
+ "text/html": [
31
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
32
+ ],
33
+ "text/plain": [
34
+ "<IPython.core.display.HTML object>"
35
+ ]
36
+ },
37
+ "metadata": {},
38
+ "output_type": "display_data"
39
+ },
40
+ {
41
+ "data": {
42
+ "text/plain": []
43
+ },
44
+ "execution_count": 5,
45
+ "metadata": {},
46
+ "output_type": "execute_result"
47
+ },
48
+ {
49
+ "data": {
50
+ "text/html": [
51
+ "\n",
52
+ "<style>\n",
53
+ " /* Turns off some styling */\n",
54
+ " progress {\n",
55
+ " /* gets rid of default border in Firefox and Opera. */\n",
56
+ " border: none;\n",
57
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
58
+ " background-size: auto;\n",
59
+ " }\n",
60
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
61
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
62
+ " }\n",
63
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
64
+ " background: #F44336;\n",
65
+ " }\n",
66
+ "</style>\n"
67
+ ],
68
+ "text/plain": [
69
+ "<IPython.core.display.HTML object>"
70
+ ]
71
+ },
72
+ "metadata": {},
73
+ "output_type": "display_data"
74
+ },
75
+ {
76
+ "data": {
77
+ "text/html": [],
78
+ "text/plain": [
79
+ "<IPython.core.display.HTML object>"
80
+ ]
81
+ },
82
+ "metadata": {},
83
+ "output_type": "display_data"
84
+ },
85
+ {
86
+ "data": {
87
+ "text/html": [
88
+ "\n",
89
+ "<style>\n",
90
+ " /* Turns off some styling */\n",
91
+ " progress {\n",
92
+ " /* gets rid of default border in Firefox and Opera. */\n",
93
+ " border: none;\n",
94
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
95
+ " background-size: auto;\n",
96
+ " }\n",
97
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
98
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
99
+ " }\n",
100
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
101
+ " background: #F44336;\n",
102
+ " }\n",
103
+ "</style>\n"
104
+ ],
105
+ "text/plain": [
106
+ "<IPython.core.display.HTML object>"
107
+ ]
108
+ },
109
+ "metadata": {},
110
+ "output_type": "display_data"
111
+ },
112
+ {
113
+ "data": {
114
+ "text/html": [],
115
+ "text/plain": [
116
+ "<IPython.core.display.HTML object>"
117
+ ]
118
+ },
119
+ "metadata": {},
120
+ "output_type": "display_data"
121
+ },
122
+ {
123
+ "data": {
124
+ "text/html": [
125
+ "\n",
126
+ "<style>\n",
127
+ " /* Turns off some styling */\n",
128
+ " progress {\n",
129
+ " /* gets rid of default border in Firefox and Opera. */\n",
130
+ " border: none;\n",
131
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
132
+ " background-size: auto;\n",
133
+ " }\n",
134
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
135
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
136
+ " }\n",
137
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
138
+ " background: #F44336;\n",
139
+ " }\n",
140
+ "</style>\n"
141
+ ],
142
+ "text/plain": [
143
+ "<IPython.core.display.HTML object>"
144
+ ]
145
+ },
146
+ "metadata": {},
147
+ "output_type": "display_data"
148
+ },
149
+ {
150
+ "data": {
151
+ "text/html": [],
152
+ "text/plain": [
153
+ "<IPython.core.display.HTML object>"
154
+ ]
155
+ },
156
+ "metadata": {},
157
+ "output_type": "display_data"
158
+ },
159
+ {
160
+ "data": {
161
+ "text/html": [
162
+ "\n",
163
+ "<style>\n",
164
+ " /* Turns off some styling */\n",
165
+ " progress {\n",
166
+ " /* gets rid of default border in Firefox and Opera. */\n",
167
+ " border: none;\n",
168
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
169
+ " background-size: auto;\n",
170
+ " }\n",
171
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
172
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
173
+ " }\n",
174
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
175
+ " background: #F44336;\n",
176
+ " }\n",
177
+ "</style>\n"
178
+ ],
179
+ "text/plain": [
180
+ "<IPython.core.display.HTML object>"
181
+ ]
182
+ },
183
+ "metadata": {},
184
+ "output_type": "display_data"
185
+ },
186
+ {
187
+ "data": {
188
+ "text/html": [],
189
+ "text/plain": [
190
+ "<IPython.core.display.HTML object>"
191
+ ]
192
+ },
193
+ "metadata": {},
194
+ "output_type": "display_data"
195
+ }
196
+ ],
197
+ "source": [
198
+ "learn = load_learner('model.pkl')\n",
199
+ "\n",
200
+ "categories = learn.dls.vocab\n",
201
+ "def predict(img):\n",
202
+ " img = PILImage.create(img)\n",
203
+ " pred, pred_idx, probs = learn.predict(img)\n",
204
+ " return dict(zip(categories, map(float, probs)))\n",
205
+ "\n",
206
+ "gr.Interface(fn=predict, inputs=gr.Image(height=512), outputs=gr.Label(num_top_classes=3)).launch()"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": null,
212
+ "metadata": {},
213
+ "outputs": [],
214
+ "source": []
215
+ }
216
+ ],
217
+ "metadata": {
218
+ "kernelspec": {
219
+ "display_name": ".venv",
220
+ "language": "python",
221
+ "name": "python3"
222
+ },
223
+ "language_info": {
224
+ "codemirror_mode": {
225
+ "name": "ipython",
226
+ "version": 3
227
+ },
228
+ "file_extension": ".py",
229
+ "mimetype": "text/x-python",
230
+ "name": "python",
231
+ "nbconvert_exporter": "python",
232
+ "pygments_lexer": "ipython3",
233
+ "version": "3.10.12"
234
+ }
235
+ },
236
+ "nbformat": 4,
237
+ "nbformat_minor": 2
238
+ }
app.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+ import timm
4
+
5
+ learn = load_learner('model.pkl')
6
+
7
+ categories = learn.dls.vocab
8
+ def predict(img):
9
+ img = PILImage.create(img)
10
+ pred, pred_idx, probs = learn.predict(img)
11
+ return dict(zip(categories, map(float, probs)))
12
+
13
+ gr.Interface(fn=predict, inputs=gr.Image(height=512), outputs=gr.Label(num_top_classes=3)).launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai