Minhal Valiya Peedikakkal commited on
Commit
e0fbd62
·
1 Parent(s): 1fa0a35

Add application file

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import timm.models.convnext
4
+ import pathlib
5
+
6
+ temp = pathlib.PosixPath
7
+ pathlib.PosixPath = pathlib.WindowsPath
8
+
9
+ learn = load_learner('Dog-Classification/pets_model.pkl')
10
+
11
+ def classify_image(img):
12
+ categories = learn.dls.vocab
13
+ pred, idx, prob = learn.predict(tensor(img))
14
+ d = [(v, k) for k, v in dict(zip(categories, map(float, prob))).items()]
15
+ return f'{max(d)[1]}: {max(d)[0]:.04f}'
16
+
17
+ iface = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(type="pil"), outputs="text")
18
+ iface.launch()