Spaces:
Build error
Build error
michael
commited on
Commit
·
c789a0b
1
Parent(s):
7c3241e
initial commit
Browse files- app.py +38 -0
- gradio_example_images/Bean_0515.jpg +0 -0
- gradio_example_images/Bitter_Gourd_1353.jpg +0 -0
- gradio_example_images/Bottle_Gourd_1179.jpg +0 -0
- gradio_example_images/Brinjal_1179.jpg +0 -0
- gradio_example_images/Broccoli_1179.jpg +0 -0
- gradio_example_images/Cabbage_1179.jpg +0 -0
- gradio_example_images/Capsicum_1179.jpg +0 -0
- gradio_example_images/Carrot_1179.jpg +0 -0
- gradio_example_images/Cauliflower_1179.jpg +0 -0
- gradio_example_images/Cucumber_1179.jpg +0 -0
- gradio_example_images/Papaya_1353.jpg +0 -0
- gradio_example_images/Potato_1390.jpg +0 -0
- gradio_example_images/Pumpkin_1179.jpg +0 -0
- gradio_example_images/Radish_1179.jpg +0 -0
- gradio_example_images/Tomato_1179.jpg +0 -0
- requirements.txt +2 -0
- vegetable-classifier.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from fastai.vision.all import *
|
| 5 |
+
from utils import get_example_images
|
| 6 |
+
|
| 7 |
+
learn = load_learner("vegetable-classifier.pkl")
|
| 8 |
+
|
| 9 |
+
labels = learn.dls.vocab
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict(img):
|
| 13 |
+
img = PILImage.create(img)
|
| 14 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 15 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
title = "Classify vegetables"
|
| 19 |
+
description = "A vegetable classifier trained on the vegetable-image-dataset from Kaggle. Made for the fastai deep learning course."
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
p = "../01_getting-started-image-classifier/Vegetable Images/test"
|
| 23 |
+
dst_path = "./gradio_example_images"
|
| 24 |
+
|
| 25 |
+
get_example_images(p, dst_path)
|
| 26 |
+
|
| 27 |
+
_examples = [f"{dst_path}/{i}" for i in os.listdir(dst_path)]
|
| 28 |
+
|
| 29 |
+
gr.Interface(
|
| 30 |
+
fn=predict,
|
| 31 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
| 32 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
| 33 |
+
title=title,
|
| 34 |
+
description=description,
|
| 35 |
+
examples=_examples,
|
| 36 |
+
interpretation="default",
|
| 37 |
+
enable_queue=True,
|
| 38 |
+
).launch()
|
gradio_example_images/Bean_0515.jpg
ADDED
|
gradio_example_images/Bitter_Gourd_1353.jpg
ADDED
|
gradio_example_images/Bottle_Gourd_1179.jpg
ADDED
|
gradio_example_images/Brinjal_1179.jpg
ADDED
|
gradio_example_images/Broccoli_1179.jpg
ADDED
|
gradio_example_images/Cabbage_1179.jpg
ADDED
|
gradio_example_images/Capsicum_1179.jpg
ADDED
|
gradio_example_images/Carrot_1179.jpg
ADDED
|
gradio_example_images/Cauliflower_1179.jpg
ADDED
|
gradio_example_images/Cucumber_1179.jpg
ADDED
|
gradio_example_images/Papaya_1353.jpg
ADDED
|
gradio_example_images/Potato_1390.jpg
ADDED
|
gradio_example_images/Pumpkin_1179.jpg
ADDED
|
gradio_example_images/Radish_1179.jpg
ADDED
|
gradio_example_images/Tomato_1179.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
scikit-image
|
vegetable-classifier.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:453dd81f03b5d1ac82ef04b1245163f7d3d832cf36dcfbe306c1f2f60676b03a
|
| 3 |
+
size 47246740
|