Spaces:
Sleeping
Sleeping
ignoreandfly
commited on
Commit
•
5bab46e
1
Parent(s):
0171820
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,20 @@
|
|
1 |
-
import
|
2 |
-
import os
|
3 |
-
from PIL import Image
|
4 |
-
import time
|
5 |
from fastai.vision.all import *
|
6 |
-
|
7 |
|
8 |
-
def GetLabel(img):
|
9 |
-
return img.split('-')[0]
|
10 |
-
|
11 |
-
|
12 |
-
#Load the Learner (Exported from ipnyb file with learn.export() )
|
13 |
learn = load_learner('export.pkl')
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
st.set_page_config(page_title="PyTorch Food Classifier - FastAI 2022", page_icon=":robot:")
|
27 |
-
st.header("PyTorch Food Classifier")
|
28 |
-
|
29 |
-
file_up = st.file_uploader("Upload Your Food Image Below", type=["jpg","png"])
|
30 |
|
31 |
-
|
32 |
-
st.write("Button Pressed")
|
33 |
-
cl_done = classify_image(file_up)
|
34 |
-
|
35 |
-
st.write(f"Your food is: {cl_done}")
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
2 |
from fastai.vision.all import *
|
3 |
+
import skimage
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
learn = load_learner('export.pkl')
|
6 |
|
7 |
+
labels = learn.dls.vocab
|
8 |
+
def predict(img):
|
9 |
+
img = PILImage.create(img)
|
10 |
+
pred,pred_idx,probs = learn.predict(img)
|
11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
12 |
|
13 |
+
title = "Pet Breed Classifier"
|
14 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
15 |
+
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
16 |
+
examples = ['siamese.jpg']
|
17 |
+
interpretation='default'
|
18 |
+
enable_queue=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
|
|
|
|
|
|
|
|