Spaces:
Runtime error
Runtime error
Mark Henry commited on
Commit ·
7b3a7b6
0
Parent(s):
hello huggingface world
Browse files- app.py +40 -0
- examples/bread.jpg +3 -0
- examples/capitol.jpg +3 -0
- examples/fruit.JPG +3 -0
- examples/soysauce.jpg +3 -0
- examples/tamari.jpeg +0 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Load the model from gluten.py
|
| 2 |
+
# Create a gradio interface for the model
|
| 3 |
+
# Run the model on the interface
|
| 4 |
+
|
| 5 |
+
from fastai.vision.all import *
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# This method is required for unpickling
|
| 10 |
+
def label_for_path(path):
|
| 11 |
+
return {
|
| 12 |
+
'bread': 'glutenful',
|
| 13 |
+
'gluten_free': 'glutenfree',
|
| 14 |
+
'man-made': 'glutenfree',
|
| 15 |
+
'fruit': 'glutenfree',
|
| 16 |
+
'malt_beverage': 'glutenful',
|
| 17 |
+
'meat': 'glutenfree',
|
| 18 |
+
'soy_sauce': 'glutenful',
|
| 19 |
+
'tamari': 'glutenfree'
|
| 20 |
+
}[str(list(path.parts)[1])]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
learn_inf = load_learner(Path() / 'gluten.pkl')
|
| 24 |
+
|
| 25 |
+
categories = ('glutenful', 'gluten-free')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def classify_image(img):
|
| 29 |
+
img = PILImage.create(img)
|
| 30 |
+
pred, pred_idx, probs = learn_inf.predict(img)
|
| 31 |
+
return {categories[i]: float(probs[i]) for i in range(len(categories))}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
image = gr.inputs.Image()
|
| 35 |
+
label = gr.outputs.Label()
|
| 36 |
+
# examples = all files in the /examples folder
|
| 37 |
+
examples = [f"examples/{i}" for i in os.listdir("examples")]
|
| 38 |
+
|
| 39 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 40 |
+
intf.launch(inline=False)
|
examples/bread.jpg
ADDED
|
Git LFS Details
|
examples/capitol.jpg
ADDED
|
Git LFS Details
|
examples/fruit.JPG
ADDED
|
|
Git LFS Details
|
examples/soysauce.jpg
ADDED
|
Git LFS Details
|
examples/tamari.jpeg
ADDED
|