Add application file
Browse files- classify_app.py +17 -0
classify_app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.data.all import *
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from fastcore.all import *
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def label_func(fname):
|
| 7 |
+
return "cat" if fname.name[0].isupper() else "dog"
|
| 8 |
+
|
| 9 |
+
learn=load_learner('/content/drive/MyDrive/model.plk')
|
| 10 |
+
|
| 11 |
+
categories=('Dog','Cat')
|
| 12 |
+
def classify_image(img):
|
| 13 |
+
pred,idx,prob=learn.predict(img)
|
| 14 |
+
return dict(zip(categories,map(float,prob)))
|
| 15 |
+
|
| 16 |
+
intf=gr.Interface(fn=classify_image,inputs=gr.inputs.Image(shape=(225,225)),outputs=gr.outputs.Label())
|
| 17 |
+
intf.launch(inline=False)
|