Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import pathlib
|
| 4 |
+
temp = pathlib.PosixPath
|
| 5 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 6 |
+
|
| 7 |
+
examples = ["apple.jpg", "avocado.jpg",
|
| 8 |
+
"mixed_fruit.jpg",
|
| 9 |
+
"nectarine.jpg", "passion_fruit.jpg",
|
| 10 |
+
"peach.jpg"]
|
| 11 |
+
title = "A fruit classification app"
|
| 12 |
+
description = "A fruit classficiation app using fastai and a pretrained-Resnet50 model."
|
| 13 |
+
|
| 14 |
+
learn = load_learner("model.pkl")
|
| 15 |
+
labels = learn.dls.vocab
|
| 16 |
+
def predict(img):
|
| 17 |
+
img = PILImage.create(img)
|
| 18 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 19 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 20 |
+
|
| 21 |
+
gr_interface = gr.Interface(fn=predict,
|
| 22 |
+
inputs = gr.inputs.Image(shape = (512, 512)),
|
| 23 |
+
outputs = gr.outputs.Label(num_top_classes = 3),
|
| 24 |
+
title = title,description=description,
|
| 25 |
+
examples = examples
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
gr_interface.launch(share=True)
|