Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
2 |
+
|
3 |
+
# Cell
|
4 |
+
from fastai.vision.all import *
|
5 |
+
import gradio as gr
|
6 |
+
import timm
|
7 |
+
|
8 |
+
# Cell
|
9 |
+
learn = load_learner('model.pkl')
|
10 |
+
|
11 |
+
# Cell
|
12 |
+
categories = learn.dls.vocab
|
13 |
+
|
14 |
+
def classify_image(img):
|
15 |
+
pred,idx,probs = learn.predict(img)
|
16 |
+
return dict(zip(categories, map(float,probs)))
|
17 |
+
|
18 |
+
# Cell
|
19 |
+
image = gr.inputs.Image(shape=(192, 192))
|
20 |
+
label = gr.outputs.Label()
|
21 |
+
examples = ['basset.jpg']
|
22 |
+
|
23 |
+
# Cell
|
24 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
25 |
+
intf.launch()
|