Spaces:
Sleeping
Sleeping
NasrinRipa
commited on
Commit
·
ca45f71
1
Parent(s):
30166f0
adding app file and model file and test images files
Browse files- Pistachio.jpg +0 -0
- app.py +43 -0
- cashew.jpg +0 -0
- macadamia-nut.jpg +0 -0
- nut-recognizer-v4.pkl +3 -0
- peanuts.jpg +0 -0
Pistachio.jpg
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
#import pathlib
|
| 6 |
+
#temp = pathlib.PosixPath
|
| 7 |
+
#pathlib.PosixPath = pathlib.WindowsPath
|
| 8 |
+
|
| 9 |
+
nut_labels = (
|
| 10 |
+
"raw Almonds",
|
| 11 |
+
"raw Walnuts",
|
| 12 |
+
"raw Cashew nut",
|
| 13 |
+
"raw Pecans",
|
| 14 |
+
"raw Peanut",
|
| 15 |
+
"raw Pili nut",
|
| 16 |
+
"raw Pistachios nut",
|
| 17 |
+
"raw Hazelnuts",
|
| 18 |
+
"raw Brazil nut",
|
| 19 |
+
"raw Maccademia nut",
|
| 20 |
+
"raw Pine nut",
|
| 21 |
+
"raw Chestnut",
|
| 22 |
+
"raw Hickory nut",
|
| 23 |
+
"raw Ginkgo nut"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
model = load_learner('nut-recognizer-v4.pkl')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def recognize_image(image):
|
| 30 |
+
pred, idx, probs = model.predict(image)
|
| 31 |
+
return dict(zip(nut_labels, map(float, probs)))
|
| 32 |
+
|
| 33 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 34 |
+
label = gr.outputs.Label(num_top_classes=5)
|
| 35 |
+
examples = [
|
| 36 |
+
'almond1.jpg',
|
| 37 |
+
'pistachio.jpg',
|
| 38 |
+
'cashew.jpg',
|
| 39 |
+
'peanuts.jpg'
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
|
| 43 |
+
iface.launch(inline=False)
|
cashew.jpg
ADDED
|
macadamia-nut.jpg
ADDED
|
nut-recognizer-v4.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ac0d5c84eae82a61694be22c23a70f7f5ca42c82faeb1453ed0cbcf4afb0e1e6
|
| 3 |
+
size 87525405
|
peanuts.jpg
ADDED
|