Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
|
4 |
+
learn_inf = load_learner('DogCat.pkl')
|
5 |
+
labels = learn_inf.dls.vocab
|
6 |
+
|
7 |
+
labels = ['Cat', 'Dog']
|
8 |
+
|
9 |
+
def predict(img):
|
10 |
+
img = PILImage.create(img)
|
11 |
+
pred, pred_idx, probs = learn_inf.predict(img)
|
12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
13 |
+
|
14 |
+
title = "Is this image a cat?"
|
15 |
+
iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512,512)), outputs=gr.outputs.Label(num_top_classes=2), title=title)
|
16 |
+
iface.launch()
|